@name FailCake AutoGun Shop V1
@inputs EGP:wirelink Open User:entity AddUp AddDown InsertedMoney DistR
@outputs ShopMoney RX RY
@persist [E O]:entity [News Menu Status]:string Upd Toggle 
@persist I [UserN Name POS Weapons CART PRICE CARTPR INSIDE MoneyIns]:array Ok Ps CleanMenu Remake
@persist AdUp IS Count TMoney Clean J Count2 ToWeapons Refresh OS KH
@trigger all

timer("updateOps",1000)
if(clk("updateOps")){
Ops = ops()
EGP:egpText(21,Ops + " ops",vec2(430,490))
}

if(first()){
AdUp = 0
IS = 0 
AdUp2 = 0   
runOnTick(1)
runOnChat(1)

Weapons[1,string] = "MP5"
Weapons[2,string] = "MAC10"
Weapons[3,string] = "Deagle"
Weapons[4,string] = "Glock"
Weapons[5,string] = "AK47"
Weapons[6,string] = "Knife"
Weapons[7,string] = "Shotgun"

PRICE[1,number] = 100
PRICE[2,number] = 130
PRICE[3,number] = 150
PRICE[4,number] = 160
PRICE[5,number] = 180
PRICE[6,number] = 1000
PRICE[7,number] = 110

INSIDE[1,number] = 0
INSIDE[2,number] = 0
INSIDE[3,number] = 0
INSIDE[4,number] = 0
INSIDE[5,number] = 0
INSIDE[6,number] = 0
INSIDE[7,number] = 0

POS[1,vector2] = vec2(-1,0.1)
POS[2,vector2] = vec2(-0.8,0.1)
POS[3,vector2] = vec2(-0.5,0.1)
POS[4,vector2] = vec2(0,0.1)
POS[5,vector2] = vec2(0.5,0.1)
POS[6,vector2] = vec2(0.8,0.1)
POS[7,vector2] = vec2(1,0.1)

EGP:egpClear()
Upd = 0
Ok = 0
Count = 0
E = entity()
O = owner()
Menu = "login"
Open = 0
ShopMoney = 0
Ops = 0
Status="Closed" 

## BACKGROUND ##

EGP:egpBox(14,vec2(255,255),vec2(510,510))

#console/background01.vtf

EGP:egpMaterial(14,"expression 2/cog")
EGP:egpColor(14,vec4(70,0,0,255))

EGP:egpText(21,Ops + " ops",vec2(430,490))
EGP:egpColor(21,vec4(255,255,255,255))

## News Bar ##
EGP:egpRoundedBoxOutline(1,vec2(255,30),vec2(470,30))  
}

timer("ShopUpdate",500)  

## BUTTONS

if(Remake){
    
EGP:egpClear()

## BACKGROUND ##

EGP:egpBox(14,vec2(255,255),vec2(510,510))

#console/background01.vtf

EGP:egpMaterial(14,"expression 2/cog")
EGP:egpColor(14,vec4(70,0,0,255))

EGP:egpText(21,Ops + " ops",vec2(430,490))
EGP:egpColor(21,vec4(255,255,255,255))

## News Bar ##
EGP:egpRoundedBoxOutline(1,vec2(255,30),vec2(470,30))  

Remake = 0  
}

if(clk("delayLogi")){
Menu = "main"
Upd = 0
stoptimer("delayLogi")
}

if(clk("delayMain")){
Menu = "login"
Upd = 0
EGP:egpRemove(12)
EGP:egpRemove(15)
stoptimer("delayMain")
}

if(clk("delayShop")){
Menu = "buy"
Upd = 0
}

if(clk("delayStorage")){
Menu = "stores"
Upd = 0    
}


if(clk("ShopUpdate")){
    
if(KH >= INSIDE:count()){
KH = 0
}

KH+=1



RX = POS[KH,vector2]:x()
RY = POS[KH,vector2]:y()

if(DistR > 0){
INSIDE[KH,number] = 1    
}else{
INSIDE[KH,number] = 0
}
   
}





if (~User & User) {
    
    Pos = EGP:egpCursor(User)
    X = Pos:x()
    Y = Pos:y()
    
    print("X = "+X)
    print("Y = "+Y)
    
    ## LOGIN BUTTON ##
    if (X >= 165 & X <= 340 & Y >= 225 & Y <=281 & Menu == "login") {
    Remake = 1 
    UserN = User:name():explode(" ")
    timer("delayLogi",50)
    }
    
    if (X >= 306 & X <= 461 & Y >= 382 & Y <= 436 & Menu == "main") {
        Remake = 1
        timer("delayMain",50)
        User = noentity()
    }
    
    if (X >= 35 & X <= 211 & Y >= 95 & Y <= 151 & Menu == "main") {
        Remake = 1
        Refresh = 1
        timer("delayShop",50)
    }
    
    ## FINAL BUY
   if (X >= 29 & X <= 229 & Y >= 388 & Y <= 471 & Menu == "buy") {
    
    if(MoneyIns[1,number]){
        Remake = 1
        EGP:egpRemove(51)
        timer("delayBuy",50)
    }
    
}
    
    
    
    if (X >= 279 & X <= 477 & Y >= 388 & Y <= 469 & Menu == "buy") {
    Remake = 1
    timer("delayLogi",100)
    }   
    
    ### ADDDDDDDD IIIIITTTTTTTT
    if (X >= 303 & X <= 476 & Y >= 339 & Y <= 359 & Ok == 0 & Menu == "buy" & Clean == 0) {
        
    if(CART:count() < 10){
    if(INSIDE[AdUp+1,number] == 1){
    IS+=1
    EGP:egpText(51,"  Added! :D ",vec2(350,340))  
    CART[IS,string] = Weapons[AdUp+1,string]
    CARTPR[IS,number] = PRICE[AdUp+1,number]
    timer("yay",1000)
    }else{
    EGP:egpText(51,"  ERROR!    ",vec2(350,340))  
    timer("yay",1000)
    }
    }else{
    
    EGP:egpText(51,"Max Items Reached!",vec2(315,340))  
    EGP:egpColor(50,vec4(255,0,0,255))
    timer("yay",1000)
    
    }
    
    }
    
    if (X >= 289 & X <= 489 & Y >= 408 & Y <= 486 & Menu == "buyiy") {
    Remake = 1
    Refresh = 1
    timer("delayShop",50)
    }
    
    if (X >= 34 & X <= 206 & Y >= 339 & Y <= 359 & Menu == "buy") {
    
    if(CART:count() > 0){
    Clean = 1
    Count2 = CART:count()
    Ok = 1
    }

    }

    #STORAGE MENU
    
    if (X >= 36 & X <= 210 & Y >= 167 & Y <= 220 & Menu == "main") {
    Remake = 1
    OS = 0
    timer("delayStorage",50)
    }

    ## THE BUYING, CHECK MONEY
    if (X >= 20 & X <= 220 & Y >= 409 & Y <= 470 & Menu == "buyiy") {
    
    print("BUYFSADFSDFSDFSDFSDFSDF")

    }   
    
    if (X >= 154 & X <= 355 & Y >= 385 & Y <= 452 & Menu == "stores") {
    Remake = 1
    timer("delayLogi",100)
    }         
    
}

## BUYING

if(clk("delayBuy")){
Menu = "buyiy"
Upd = 0
}


## STORAGE
if(Menu == "stores"){
if(Upd == 0){

News = "| Welcome to FailCake's AutoGun Store , " + UserN[1,string] + "! |"
EGP:egpText(2,News,vec2(50,20))
EGP:egpColor(2,vec4(255,255,255,255))   

## INFO bg
EGP:egpRoundedBox(3,vec2(255,265),vec2(470,400))   
EGP:egpColor(3,vec4(150,150,150,255)) 

## Storage Text
EGP:egpText(4,"---- STORAGE ----",vec2(80,70))   
EGP:egpFont(4,"verdana",50)
EGP:egpColor(4,vec4(255,0,0,255)) 

## Inside
EGP:egpRoundedBoxOutline(5,vec2(255,290),vec2(460,340))   
EGP:egpColor(5,vec4(1,1,1,255)) 

## Storage Text Info
EGP:egpText(6,"--- Item Name <----> Avaiable ---",vec2(40,130))   
EGP:egpFont(6,"verdana",30)
EGP:egpColor(6,vec4(1,1,1,255)) 

## BEXIT bg
EGP:egpRoundedBox(7,vec2(255,420),vec2(200,70))   
EGP:egpColor(7,vec4(100,100,100,255)) 

EGP:egpText(8,"EXIT",vec2(215,400))   
EGP:egpFont(8,"verdana",40)
EGP:egpColor(8,vec4(255,1,1,255)) 

EGP:egpCircle(73,vec2(-5,-5),vec2(5,5))
EGP:egpParentToCursor(73)
EGP:egpColor(73,vec(255,0,0))
}

if(OS == 0){
    
for(FG = 1,Weapons:count()){
    
if(INSIDE[FG,number] == 1){
EGP:egpText(FG+30,Weapons[FG,string] + " <----> Avaiable!",vec2(40,FG*25 +140))
EGP:egpColor(FG+30,vec4(1,255,1,255))   
}else{
EGP:egpText(FG+30,Weapons[FG,string] + " <----> Not Avaiable!",vec2(40,FG*25 +140))   
EGP:egpColor(FG+30,vec4(255,1,1,255))   
}

EGP:egpFont(FG+30,"verdana",25)
if(FG >= Weapons:count()){
OS = 1  
}  
}
  
}

}






if(Menu == "buyiy"){
timer("Update",500)
if(clk("Update")){
EGP:egpText(7,"Current Money Inserted : " + InsertedMoney + "$",vec2(22,220))   
EGP:egpFont(7,"verdana",30)
EGP:egpColor(7,vec4(0,0,0,255))     
}    

if(Upd == 0){
Upd = 1
News = "| Welcome to FailCake's AutoGun Store , " + UserN[1,string] + "! |"

EGP:egpText(2,News,vec2(50,20))
EGP:egpColor(2,vec4(255,255,255,255))    

## INFO bg
EGP:egpRoundedBox(3,vec2(255,215),vec2(470,300))   
EGP:egpColor(3,vec4(150,150,150,255)) 

##

EGP:egpText(4,"-- ATTENTION --",vec2(85,70))   
EGP:egpFont(4,"verdana",50)
EGP:egpColor(4,vec4(255,0,0,255)) 

EGP:egpText(5,"Insert the Correct Ammount of Money!",vec2(25,130))   
EGP:egpFont(5,"verdana",28)
EGP:egpColor(5,vec4(255,0,0,255)) 

EGP:egpText(6,"Your Money Wont Be Returned if Rong!",vec2(32,160))   
EGP:egpFont(6,"verdana",27)
EGP:egpColor(6,vec4(255,0,0,255))

EGP:egpText(9,"----------------------------------------------------",vec2(24,190))   
EGP:egpFont(9,"verdana",27)
EGP:egpColor(9,vec4(0,0,0,255))

EGP:egpText(8,"Total Money Needed : " + MoneyIns[1,number] + "$",vec2(22,250))   
EGP:egpFont(8,"verdana",30)
EGP:egpColor(8,vec4(0,0,0,255)) 

EGP:egpText(7,"Current Money Inserted : " + InsertedMoney + "$",vec2(22,220))   
EGP:egpFont(7,"verdana",30)
EGP:egpColor(7,vec4(0,0,0,255)) 

EGP:egpText(10,"Total Weapons Requested : " + ToWeapons,vec2(22,280))   
EGP:egpFont(10,"verdana",30)
EGP:egpColor(10,vec4(0,0,0,255)) 
 

## Buy Button

EGP:egpRoundedBox(11,vec2(120,440),vec2(200,60))   
EGP:egpColor(11,vec4(150,150,150,255)) 
 
EGP:egpText(12,"Buy It!",vec2(65,420)) 
EGP:egpColor(12,vec4(0,255,0,255))
EGP:egpFont(12,"verdana",40) 
 
## Cancel

EGP:egpRoundedBox(13,vec2(390,440),vec2(200,60))   
EGP:egpColor(13,vec4(150,150,150,255)) 

EGP:egpText(15,"Cancel!",vec2(330,420)) 
EGP:egpColor(15,vec4(255,0,0,255))
EGP:egpFont(15,"verdana",40) 

EGP:egpCircle(71,vec2(-5,-5),vec2(5,5))
EGP:egpParentToCursor(71)
EGP:egpColor(71,vec(255,0,0))
}    
}









if(Clean){
    
for(J5=0,Count2){
     
CART:remove(J5)
CARTPR:remove(J5) 
   
EGP:egpRemove(J5+60)  
TMoney = 0  

if(CART:count() <= 0){
Count = 0  
EGP:egpText(53,"   Cart Cleaned!",vec2(55,340))  
EGP:egpColor(53,vec4(1,1,1,255))
timer("yay2",1000)
TMoney = 0 
K = 0
IS = 0
Clean = 0
EGP:egpText(59,"-- Total Money : " + TMoney + "$",vec2(40,100)) 
Ok = 1
} 
    
}

}

if(clk("yay2") & Menu == "buy"){
EGP:egpText(53,"       Clean Cart",vec2(55,340)) 
Ok = 0  
}

if(clk("yay") & Menu == "buy"){
EGP:egpText(51,"Add to Cart",vec2(350,340)) 
EGP:egpColor(50,vec4(0,200,0,255))   
}

if(Menu == "main"){

if(Upd == 0){
Upd = 1

News = "| Welcome to FailCake's AutoGun Store , " + UserN[1,string] + "! |"

EGP:egpRemove(29)
EGP:egpRemove(28)

EGP:egpRemove(70) 
## Buttons Bg ##




EGP:egpBox(11,vec2(265,410),vec2(70,10))

EGP:egpRoundedBox(9,vec2(225,410),vec2(30,40))
EGP:egpRoundedBox(10,vec2(295,410),vec2(30,40))
EGP:egpRoundedBox(3,vec2(125,280),vec2(200,400)) 

## Info Bg ## 


EGP:egpBox(5,vec2(385,330),vec2(30,100))


EGP:egpRoundedBox(7,vec2(385,280),vec2(60,30))
EGP:egpRoundedBox(8,vec2(385,370),vec2(60,30))
EGP:egpRoundedBox(6,vec2(385,410),vec2(180,70))

EGP:egpRoundedBox(4,vec2(385,180),vec2(210,200))


EGP:egpRoundedBox(13,vec2(385,170),vec2(200,30)) # Bg ShopStatus

EGP:egpRoundedBox(16,vec2(385,210),vec2(200,30)) # Bg ShopStatus

EGP:egpRoundedBox(18,vec2(385,250),vec2(200,30)) # Bg ShopStatus

EGP:egpRoundedBox(20,vec2(385,110),vec2(200,30)) # Bg ShopStatus

EGP:egpColor(5,vec4(50,50,50,255))
EGP:egpColor(11,vec4(50,50,50,255))
EGP:egpColor(7,vec4(100,100,100,255))
EGP:egpColor(8,vec4(100,100,100,255))
EGP:egpColor(9,vec4(100,100,100,255))
EGP:egpColor(10,vec4(100,100,100,255))

EGP:egpColor(13,vec4(100,100,100,255))
EGP:egpColor(18,vec4(100,100,100,255))

EGP:egpColor(20,vec4(100,100,100,255))

EGP:egpColor(16,vec4(100,100,100,255))

EGP:egpText(15,"Shop Money = " + ShopMoney + "$",vec2(305,200))


Name = O:name():explode(" ")

EGP:egpText(17,"Owner = " + Name[1,string],vec2(305,240))
EGP:egpColor(17,vec4(0,0,255,255))

EGP:egpText(19," ---- Informations ----",vec2(305,100))
EGP:egpColor(19,vec4(255,155,1,255))
EGP:egpText(12,"Shop Status = " + Status,vec2(305,160))

EGP:egpColor(15,vec4(0,255,0,255))

EGP:egpColor(3,vec4(150,150,150,255))
EGP:egpColor(6,vec4(150,150,150,255))
EGP:egpColor(4,vec4(150,150,150,255))


## BUTTON LOGOUT

EGP:egpRoundedBox(22,vec2(385,410),vec2(155,55))
EGP:egpColor(22,vec4(40,40,40,255))


EGP:egpText(23,"Log Out",vec2(325,390))
EGP:egpFont(23,"verdana",35)
EGP:egpColor(23,vec4(90,0,0,255))

## Button BUY GUNS ##

EGP:egpRoundedBox(24,vec2(125,125),vec2(175,55))
EGP:egpColor(24,vec4(40,40,40,255))


EGP:egpText(60,"Buy Guns",vec2(55,105))
EGP:egpFont(60,"verdana",35)
EGP:egpColor(60,vec4(10,10,10,255))


## Button Storage ##

EGP:egpRoundedBox(26,vec2(125,195),vec2(175,55))
EGP:egpColor(26,vec4(40,40,40,255))


EGP:egpText(27,"Storage",vec2(65,175))
EGP:egpFont(27,"verdana",35)
EGP:egpColor(27,vec4(10,10,10,255))

EGP:egpText(2,News,vec2(30,20))
EGP:egpColor(2,vec4(255,255,255,255))   


## Button Info ##

EGP:egpRoundedBox(30,vec2(125,265),vec2(175,55))
EGP:egpColor(30,vec4(40,40,40,255))


EGP:egpText(31,"Info",vec2(95,245))
EGP:egpFont(31,"verdana",35)
EGP:egpColor(31,vec4(10,10,10,255)) 


EGP:egpCircle(71,vec2(-5,-5),vec2(5,5))
EGP:egpParentToCursor(71)
EGP:egpColor(71,vec(255,0,0))

EGP:egpColor(12,vec4(255,1,1,255)) 
}





timer("update",300)
if(clk("update")){
EGP:egpText(12,"Shop Status = " + Status,vec2(305,160))
EGP:egpText(15,"Shop Money = " + ShopMoney + "$",vec2(305,200))
}

if(Open & ~Open){
Toggle =!Toggle    

if(Toggle){
Status="Open" 
EGP:egpColor(12,vec4(1,255,1,255))   
}else{
Status="Closed" 
EGP:egpColor(12,vec4(255,1,1,255)) 
}

}
}


if(Menu == "login"){
  
if(Upd == 0){
Upd = 1
News = "| Welcome to FailCake's AutoGun Store |"

EGP:egpText(2,News,vec2(100,20))
EGP:egpColor(2,vec4(255,255,255,255))       
    
EGP:egpRoundedBox(28,vec2(255,255),vec2(175,55))
EGP:egpColor(28,vec4(40,40,40,255))

EGP:egpText(29,"Login",vec2(215,235))
EGP:egpFont(29,"verdana",35)
EGP:egpColor(29,vec4(250,150,0,255))
    
        
EGP:egpCircle(70,vec2(-5,-5),vec2(5,5))
EGP:egpParentToCursor(70)
EGP:egpColor(70,vec(255,0,0))    
}

}


if(Menu == "buy"){

if(Upd == 0){
Upd = 1   
 
## Cant Use : 14,21,1,2

News = "| Welcome to FailCake's AutoGun Store , " + UserN[1,string] + "! |"


EGP:egpText(2,News,vec2(30,20))
EGP:egpColor(2,vec4(255,255,255,255))       
    

## Background PipeRect
EGP:egpBox(8,vec2(260,200),vec2(50,20)) 

## Background Pipe
EGP:egpRoundedBox(6,vec2(220,200),vec2(30,50)) 

## Background Pipe2
EGP:egpRoundedBox(7,vec2(290,200),vec2(30,50)) 

## Background carT
EGP:egpRoundedBox(3,vec2(120,220),vec2(200,300))

## Background Weapons
EGP:egpRoundedBox(4,vec2(390,220),vec2(200,300)) 

## Background Buttons
EGP:egpRoundedBox(5,vec2(255,430),vec2(470,100)) 

## Buy Out
EGP:egpRoundedBoxOutline(9,vec2(120,230),vec2(190,270)) 

## Buy Text
EGP:egpText(10,"--- Your Current Cart ---",vec2(30,75)) 


## Weapon Out
EGP:egpRoundedBoxOutline(11,vec2(390,230),vec2(190,270)) 

## Weapon Text
EGP:egpText(12,"--- Avaiable Weapons ---",vec2(300,75)) 

## BUY BUTTON
EGP:egpRoundedBox(13,vec2(130,430),vec2(200,80)) 


## Exit BUTTON
EGP:egpRoundedBox(15,vec2(380,430),vec2(200,80)) 


## ADD BUTTON
EGP:egpRoundedBox(50,vec2(390,350),vec2(175,20)) 
EGP:egpColor(50,vec4(0,200,0,255))

## ADD BUTTON Text
EGP:egpText(51,"Add to Cart",vec2(350,340))  
EGP:egpColor(51,vec4(1,1,1,255))


## REMOVE BUTTON
EGP:egpRoundedBox(52,vec2(120,350),vec2(175,20)) 
EGP:egpColor(52,vec4(200,0,0,255))

## REMOVE BUTTON Text
EGP:egpText(53,"       Clean Cart",vec2(55,340))  
EGP:egpColor(53,vec4(1,1,1,255))

## EXIT Text
EGP:egpText(16,"EXIT",vec2(335,405)) 
EGP:egpFont(16,"verdana",50)

## BUY Text
EGP:egpText(17,"BUY",vec2(85,405)) 
EGP:egpFont(17,"verdana",50)

## COLORS ##

EGP:egpColor(4,vec4(150,150,150,255))
EGP:egpColor(3,vec4(150,150,150,255))
EGP:egpColor(5,vec4(150,150,150,255))

EGP:egpColor(6,vec4(90,90,90,255))
EGP:egpColor(7,vec4(90,90,90,255))
EGP:egpColor(8,vec4(50,50,50,255))
EGP:egpColor(9,vec4(1,1,1,255))
EGP:egpColor(10,vec4(1,1,1,255))
EGP:egpColor(11,vec4(1,1,1,255))
EGP:egpColor(12,vec4(1,1,1,255))
EGP:egpColor(16,vec4(1,1,1,255))
EGP:egpColor(17,vec4(1,1,1,255))

EGP:egpColor(13,vec4(0,90,1,255))
EGP:egpColor(15,vec4(90,1,1,255))

EGP:egpText(200,"Weapon - Price - Avaiable",vec2(300,100))
EGP:egpColor(200,vec4(90,1,1,255))

EGP:egpText(59,"-- Total Money : " + TMoney+ "$",vec2(40,100))

## BOX SELECT ADD
EGP:egpBox(54,vec2(395,130),vec2(160,15))
EGP:egpColor(54,vec4(0,0,200,100))


if(Weapons:count() <= 10){
for(Ps = 1 ,Weapons:count())
{
    EGP:egpBox(Ps + 21 + Weapons:count() ,vec2(305,Ps*20 + 110),vec2(20,20))
    EGP:egpMaterial(Ps + 21 + Weapons:count(),"gui/accept")
    EGP:egpText(Ps + 21,Weapons[Ps,string] + " --- " + PRICE[Ps,number] + "$ --- " + INSIDE[Ps,number],vec2(315,Ps*20 + 100))
    EGP:egpColor(Ps + 21,vec4(1,1,1,255))
}
}

EGP:egpCircle(71,vec2(-5,-5),vec2(5,5))
EGP:egpParentToCursor(71)
EGP:egpColor(71,vec(255,0,0))


}




if(CART:count() > 0 & Clean == 0 & Ok == 0 | Refresh == 1){
    
if(CART:count() != Count & Clean == 0 & Ok == 0 | Refresh == 1){
Count = CART:count()  
TMoney = 0

for(K = 1,CART:count()){
    
EGP:egpText(K + 60,CART[K,string] + " --- " + CARTPR[K,number] + "$",vec2(50,K*20 + 100))
EGP:egpColor(K + 60,vec4(1,1,1,255))  
TMoney += CARTPR[K,number]
MoneyIns[1,number] = TMoney
ToWeapons = CART:count()
Refresh = 0
}
  
EGP:egpText(59,"-- Total Money : " + TMoney+ "$",vec2(40,100))
}

}





if(~AddUp & AddUp){

if(AdUp < Weapons:count()){
AdUp+=1
}

## BOX SELECT ADD
EGP:egpBox(54,vec2(395,AdUp*20 + 130),vec2(160,15))
EGP:egpColor(54,vec4(0,0,200,100))

   
}

if(~AddDown & AddDown){

if(AdUp > 0){
AdUp-=1
}

## BOX SELECT ADD
EGP:egpBox(54,vec2(395,AdUp*20 + 130),vec2(160,15))
EGP:egpColor(54,vec4(0,0,200,100))

   
}

}

