@name Weapon Dispenser
@inputs EGP:wirelink [R1]:entity Pot
@outputs U1
@persist [FunDir Ball]:vector2 Index CurScreen Ply Select Reset


#### Made by imLiaMxo ####

### PLEASE NOTE ###
### THESE BELOW WILL NOT WORK AFTER I REMOVE ANTI DUPE. IT SHOULD BE ABOUT 7 LINES BEHIND.
##################################
#This E2 Chip does not automatically detect the gun you're selling. You have to set the weapon name below (LINE 17).
#To change the price of the moneyRequest Please go to line 93. Or if you disabled moneyRequest then go to (LINE 91).
#If you disabled moneyRequest please make sure you change the if(Pot == (PRICE) to the amount you want at (LINE 178).

interval(100)
dsJoinGroup("locked")

WeaponName = " MP 40 " # Here is where you put the name of the gun you're selling Saves editing everything else.

}

E = entity()
local Ply = findClosest(EGP:entity():pos())

if(first())
{
    #include "egplib"
    CurScreen = 1
    EGP:egpClear()
    EGP:egpRoundedBox(1,vec2(250,250),vec2(250,250))
    EGP:egpColor(1, vec(0,145,255))
    EGP:egpText(2, "Press Use (E) To Login", vec2(125,250))
    EGP:egpSize(2,27)
    EGP:egpRoundedBox(3,vec2(75,480),vec2(75,90))
    EGP:egpMaterial(3, "vgui/gfx/vgui/market_sticker_category")
    EGP:egpBox(99,vec2(256,256),vec2(80,80))
    EGP:egpMaterial(99,"gui/gmod_logo") #gui/gmod_logo
    Index = 1
    FunDir=vec2(random(-8,8),random(-8,8))
    Ball = vec2(256,256)
    interval(100)
}elseif(Index==1){
    interval(100)
    Ball=Ball+FunDir*4
    EGP:egpPos(99,Ball)
    if(!inrange(Ball,vec2(70,140),vec2(440,440))){
        if(Ball:x()<=70&FunDir:x()<0){
            FunDir=FunDir:setX(clamp(-FunDir:x()+random(-1,1),-5,5))
        }elseif(Ball:x()>=440&FunDir:x()>0){
            FunDir=FunDir:setX(clamp(-FunDir:x()+random(-1,1),-5,5))
        }elseif(Ball:y()<=140&FunDir:y()<0){
            FunDir=FunDir:setY(clamp(-FunDir:y()+random(-1,1),-5,5))
        }elseif(Ball:y()>=440&FunDir:y()>0){
            FunDir=FunDir:setY(clamp(-FunDir:y()+random(-1,1),-5,5))
        }elseif(Reset == 1) { 
    reset()
}
}
}


function void page2(Ply:entity)
{
    CurScreen = 2
    EGP:egpClear()
    EGP:egpBox(88,vec2(256,85),vec2(512,75))
    EGP:egpText(87,+WeaponName,vec2(256,73))
    EGP:egpFont(87,"Lucida Console")
    EGP:egpSize(87,25)
    EGP:egpColor(87,vec(0,0,0))
    EGP:egpAlign(87,1)
    EGP:egpRoundedBox(1,vec2(250,250),vec2(210,150))
    EGP:egpMaterial(1,"vgui/gfx/vgui/mp5")
    EGP:egpRoundedBox(4,vec2(265,415),vec2(325,40))
    EGP:egpColor(4,vec(0,0,255))
    EGP:egpBox(5,vec2(450,480),vec2(60,60))
    EGP:egpMaterial(5,"gui/HTML/home")
    EGP:egpColor(5,vec(255,100,50))
    EGP:egpText(6, "Purchase Weapon",vec2(200,405)),EGP:egpSize(4,27)
    EGP:egpColor(6,vec(100,100,100))
}

function void gunPayment(Ply:entity)
{
#EGP:egpClear()
#EGP:egpText(2,"Please insert $950",vec2(180,250))
#EGP:egpSize(2, 30)
moneyRequest(Ply,1250,"Purchase"+WeaponName,10)
}

function void resetPage(Ply:entity)
{
    timer("reset",1)
    Reset = 1
}


function void thankPage(Ply:entity)
{
    CurScreen = 3
    EGP:egpClear()
    EGP:egpBox(88,vec2(256,85),vec2(512,75))
    EGP:egpText(87,"- Thanks For Shopping -",vec2(256,73))
    EGP:egpFont(87,"Lucida Console")
    EGP:egpSize(87,25)
    EGP:egpColor(87,vec(0,0,0))
    EGP:egpAlign(87,1)
    EGP:egpRoundedBox(1,vec2(250,250),vec2(210,150))
    EGP:egpMaterial(1,"VGUI/loading-rotate")
    EGP:egpRoundedBox(4,vec2(265,415),vec2(325,40))
    EGP:egpColor(4,vec(0,0,255))
    EGP:egpBox(5,vec2(450,480),vec2(60,60))
    EGP:egpMaterial(5,"gui/HTML/home")
    EGP:egpColor(5,vec(255,100,50))
    EGP:egpText(6, "    "+WeaponName,vec2(170,405)),EGP:egpSize(4,27)
    EGP:egpColor(6,vec(100,100,100))
    resetPage(Ply)
}



if(moneyClk()){
    soundPlay(1,0.8,"ambient/office/coinslot1.wav")
    U1 = 1
    thankPage(Ply)
printColor(vec(),"[",vec(32,178,170),"Liam's Auto Dispenser",vec(),"] ",vec(255,0,0),+Ply:name(),vec(0,0,255)," Has Purchase A ",vec(255,0,0),+WeaponName,vec(0,0,255)," From Your Store")
}
if(moneyNoClk()){
    thankPage(Ply)
printColor(vec(),"[",vec(32,178,170),"Liam's Auto Dispenser",vec(),"] ",vec(255,0,0),+Ply:name(),vec(0,0,255)," Has Not Purchased A Weapon Because He's A Cunt.")
}
if(moneyTimeout()){
    thankPage(Ply)
}


    
    

if(findCanQuery()){
    findByClass("player")
    local Ply = findClosest(EGP:entity():pos())
    local Cursor = EGP:egpCursor(Ply)
    local Use = Ply:keyUse()
    if(Ply:isValid() & Ply:isAlive()){
        if(Ply:pos():distance(EGP:entity():pos()) <= 100){
            if((changed(Use) & Use)){
                if(CurScreen == 1){
                    if(EGP:button(1,Cursor)){
                        soundPlay("topage2",6,"ambient/energy/whiteflash.wav")
                        page2(Ply)
                        printColor(vec(),"[",vec(32,178,170),"Liam's Auto Dispenser",vec(),"] ",vec(255,0,0),+Ply:name(),vec(0,0,255)," Has Logged In")
                    }
                }
                    elseif(CurScreen == 2){
                    if(EGP:button(4,Cursor)){
                    gunPayment(Ply)
                }
                    if(EGP:button(5,Cursor)){
                    resetPage(Ply)
                }
            }
        }
    }
}
}

  if(clk("reset")) {
    resetPage(Ply)
  }   


if(Pot == 5000)
{
    U1 = 1
}





EGP:drawCursor(9998)
