@name Spawn Gate E2
@inputs 
@outputs [User1 User2 Unwanted1]:entity 
@persist I [R R2]:ranger [Out In Right Left Middle TopLeft TopRight Ravenholm Left2]:entity 
@persist [Left3 Left4 Left5 Right2 Right3 Right4 Right5 RoofLeft RoofRight]:entity 
@persist Holo1 Holo2 Unwanted 
@trigger 
runOnTick(1)
runOnChat(1)

findByClass("Player")
findExcludeModel("models/player/barney.mdl")
findExcludeModel("models/player/police_fem.mdl")
findExcludeModel("models/player/police.mdl")
findExcludeModel("models/player/combine_soldier_prisonguard.mdl")
findExcludeModel("models/player/gasmask.mdl")
findExcludeModel("models/player/breen.mdl")
User1 = findClosest(holoEntity(1):pos())
User2 = findClosest(holoEntity(2):pos())

if (Unwanted == 1) {
    findByClass("Player")
    findClearBlackModelList()
    Unwanted1 = findClosest(holoEntity(2):pos())
}


if (Holo1) {
    holoCreate(1)
    holoPos(1,Out:pos()+vec(0,-88,0))
    holoScale(1,vec(3,0.05,6))
    holoAng(1,Out:angles()+ang(0,90,0))
    holoAlpha(1,0)
}
    
if (Holo2) {
    holoCreate(2)
    holoPos(2,In:pos()+vec(0,88,0))
    holoScale(2,vec(3,0.05,6))
    holoAng(2,In:angles()+ang(0,90,0))
    holoAlpha(2,0)
}

if (first()) {
    Out = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Out:setPos(vec(-15738.267578125,15451.947265625,60.6708984375))
    Out:setAng(ang(0,90,0))
    
    In = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    In:setPos(vec(-15817.362304688,15359.321289063,61.077392578125))
    In:setAng(ang(0,90,0))
    
    Left = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Left:setPos(vec(-15693.201171875,15451.215820313,58.892597198486))
    Left:setAng(ang(0,90,0))
    
    Right = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Right:setPos(vec(-15861.083984375,15450.596679688,62.147094726563))
    Right:setAng(ang(0,90,0))
    
    timer("First4",1000)
}

R = rangerOffsetHull(2.5,holoEntity(1):pos(),holoEntity(1):up(),holoEntity(1):boxSize())
R2 = rangerOffsetHull(2.5,holoEntity(2):pos(),holoEntity(2):up(),holoEntity(2):boxSize())

if (clk("First4")) {
    Middle = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Middle:setPos(vec(-15777.625976563,15451.4296875,62.501964569092))
    Middle:setAng(ang(0,90,0))
    
    TopLeft = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    TopLeft:setPos(vec(-15714.52734375,15467.31640625,119.08796691895))
    TopLeft:setAng(ang(45,90,90))
    
    TopRight = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    TopRight:setPos(vec(-15820.37109375,15467.36328125,119.49049377441))
    TopRight:setAng(ang(45,90,90))
    
    Ravenholm = propSpawn("models/props_junk/ravenholmsign.mdl",1)
    Ravenholm:setPos(vec(-15774.008789063,15471.828125,119.07724761963))
    Ravenholm:setAng(ang(39.532150268555,87.946083068848,1.8516169786453))
        
    timer("Second4",1000)
    
    Holo1 = 1
    Holo2 = 1
}

if(changed(R2:entity():isPlayer()) & R2:entity():isPlayer()){
    moneyRequest(User2,1000,"In",20)
} elseif (chatClk(owner()) & owner():lastSaid():find("!io")) {
    hideChat(1)
    In:setPos(vec(-16017.362304688,15359.321289063,61.077392578125))
    Holo2 = 0
    timer("owni1",3000)
}

if (clk("owni1")) {
    In:setPos(vec(-15817.362304688,15359.321289063,61.077392578125))
    Holo2 = 1
}

if (moneyClk("In")) {
    moneyClkPlayer()
    holoDelete(2)
    In:setPos(vec(-16017.362304688,15359.321289063,61.077392578125))
    timer("Holo2",3000)
}

if (clk("Holo2")) {
    In:setPos(vec(-15817.362304688,15359.321289063,61.077392578125))
    Holo2 = 1
}

if (moneyNoClk("In")) {
    moneyNoClkPlayer()
    holoDelete(2)
    timer("holo2",3000)
}

if (clk("holo2")) {
    Holo2 = 1
}

if(changed(R:entity():isPlayer()) & R:entity():isPlayer()){
    moneyRequest(User1,1000,"Out",20)
} elseif (chatClk(owner()) & owner():lastSaid():find("!oo")) {
    hideChat(1)
    Out:setPos(vec(-16017.362304688,15359.321289063,61.077392578125))
    Holo1 = 0
    timer("owni2",3000)
}

if (clk("owni2")) {
    Out:setPos(vec(-15738.267578125,15451.947265625,60.6708984375))
    Holo1 = 1
}

if (moneyClk("Out")) {
    moneyClkPlayer()
    holoDelete(1)
    Out:setPos(vec(-16017.362304688,15359.321289063,61.077392578125))
    timer("Holo1",3000)
}

if (clk("Holo1")) {
    Out:setPos(vec(-15738.267578125,15451.947265625,60.6708984375))
    Holo1 = 1
}

if (moneyNoClk("Out")) {
    moneyNoClkPlayer()
    holoDelete(1)
    timer("no",3000)
}

if (clk("no")) {
    Holo1 = 1
}

if (clk("Second4")) {
    Left2 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Left2:setPos(vec(-15716.465820313,15428.268554688,58.892601013184))
    Left2:setAng(ang(0,180,0))
    
    Left3 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Left3:setPos(vec(-15716.213867188,15381.991210938,58.892601013184))
    Left3:setAng(ang(0,0,0))
    
    Left4 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Left4:setPos(vec(-15759.876953125,15428.482421875,62.501964569092))
    Left4:setAng(ang(0,180,0))
    
    Left5 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Left5:setPos(vec(-15759.625,15382.205078125,62.501964569092))
    Left5:setAng(ang(0,0,0))
    
    timer("Third4",1000)
}

if (clk("Third4")) {
    Right2 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Right2:setPos(vec(-15839.102539063,15428.735351563,58.892601013184))
    Right2:setAng(ang(0,0,0))
    
    Right3 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Right3:setPos(vec(-15839.354492188,15381.524414063,58.892601013184))
    Right3:setAng(ang(0,180,0))
    
    Right4 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Right4:setPos(vec(-15795.69140625,15428.94921875,62.501964569092))
    Right4:setAng(ang(0,0,0))
    
    Right5 = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    Right5:setPos(vec(-15795.943359375,15381.73828125,62.501964569092))
    Right5:setAng(ang(0,180,0))
    
    timer("Forth4",1000)
}

if (clk("Forth4")) {
    RoofLeft = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    RoofLeft:setPos(vec(-15739.478515625,15400.295898438,103.16565704346))
    RoofLeft:setAng(ang(90,90,180))
    
    RoofRight = propSpawn("models/props_wasteland/interior_fence001g.mdl",1)
    RoofRight:setPos(vec(-15818.956054688,15400.295898438,104.28612518311))
    RoofRight:setAng(ang(90,90,180))
}

if (chatClk(owner()) & owner():lastSaid():find("!shutdown")) {
    hideChat(1)
    Out:propDelete()
    In:propDelete()
    Right:propDelete()
    Left:propDelete()
    Middle:propDelete()
    TopLeft:propDelete()
    TopRight:propDelete()
    Ravenholm:propDelete()
    Left2:propDelete()
    Left3:propDelete()
    Left4:propDelete()
    Left5:propDelete()
    Right2:propDelete()
    Right3:propDelete()
    Right4:propDelete()
    Right5:propDelete()
    RoofLeft:propDelete()
    RoofRight:propDelete()
    holoDeleteAll()
}
