@name EGP button
@inputs EGP:wirelink User:entity
@outputs B1
@persist Cursor:vector2
#--------------------===============[|ERZA|]===============--------------------
interval(100) # Not needed for this

if(first())
    {
        EGP:egpClear() # Clears the screen everytime you update the chip.
        EGP:egpDrawTopLeft(1) # This forces all boxes and circles to be drawn from the top left instead from the center.
                              # It makes egp buttons easier to code out. I think anyway.

        EGP:egpBox(1,vec2(220,230),vec2(100,50)) #Forms a rounded corner box.#DEFUALT Vec2(220,230)
        EGP:egpColor(1,vec(255,0,0)) # Sets the color of the rounded box.
        
        EGP:egpRoundedBoxOutline(2,vec2(220,230),vec2(74,50))
        EGP:egpColor(2,vec(0,0,255))
        
        EGP:egpText(3,"B1 is off",vec2(226,246)) # Makes text.
        EGP:egpColor(3,vec(255,255,255))
        
        #EGP:egpCircle(400,vec2(),vec2(6,6))
        EGP:egpColor(400,vec4(255,255,255,100))
        EGP:egpParentToCursor(400) # This parents a certain index to the users crosshair.
    }
    
Cursor = EGP:egpCursor(User) # defines the variable "Cursor" as the users crosshairs.

if(User&~User) # If the user interacts with the screen by pressing use, this if statement will run.
    {
        User:give("weapon_lordi_wep_aug")
        LeftTop = EGP:egpPos(1) # Defines "LeftTop" as the position of the fist box coded above. Since "egpDrawTopLeft" was added
        # the actual position is the top left of the "1 indexed RoundedBox code".
        
        RightBottom = EGP:egpPos(1) + EGP:egpSize(1) # this finds the bottom right corner of the rounded box by adding the position of the
        # box to the size of the box.
        
        if(inrange(Cursor, LeftTop, RightBottom)) # This checks if the cursor is inside the rounded box and runs if true
            {
                B1=!B1 # A toggled output to make the screen useful
                print(3,"Player " + User:name() + " has pressed E on position " + toString(round(Cursor)))
				# the above line of code prints who toggled the button and where on the screen
            }
        if(B1)  # this bit of code just changes the color of the rounded box and the text to indicate that it is toggled.
            {
                EGP:egpColor(1, vec4(0,255,0,255))
                EGP:egpSetText(3,"B1 is on")
            }
        if(!B1)
            {
                EGP:egpColor(1, vec4(255,0,0,255))
                EGP:egpSetText(3,"B1 is off")
            }
    
    } 
