@name Tank
@inputs Pod:wirelink T:entity 
@outputs Press 
@persist Body:entity Code:string State 
@trigger 
interval(50)

if (first()) {
    Body = entity():isWeldedTo()
    Body:setMass(500)
    
    holoCreate(1)
    holoCreate(2)
    holoCreate(3)
    holoCreate(4)
    holoCreate(5)
    holoCreate(6)
    holoCreate(7)
    holoCreate(8)
    
    for (I = 1,8) {
        holoModel(I,"models/sprops/trans/miscwheels/tank30.mdl")
        holoAng(I,entity():toWorld(ang(0,90,0)))
        holoColor(I,vec(160,160,160))
        holoParent(I,Body)
        holoBodygroup(I,1,4)
    }
    
    holoAng(2,ang(0,-90,0))
    holoAng(4,ang(0,-90,0))
    holoAng(6,ang(0,-90,0))
    holoAng(8,ang(0,-90,0))
    
    holoCreate(10)
    holoPos(10,Body:toWorld(vec(32,0,11)))
    holoScale(10,vec(1,10,0.1))
    holoParent(10,Body)
    
    holoCreate(11)
    holoPos(11,Body:toWorld(vec(32,-64.2,7.29)))
    holoAng(11,Body:toWorld(ang(0,0,40)))
    holoScale(11,vec(1,1,0.1))
    holoParent(11,Body)
    
    holoCreate(12)
    holoPos(12,Body:toWorld(vec(32,64.25,7.29)))
    holoAng(12,Body:toWorld(ang(0,0,-40)))
    holoScale(12,vec(1,1,0.1))
    holoParent(12,Body)
    
    holoCreate(13)
    holoPos(13,Body:toWorld(vec(-32,0,11)))
    holoScale(13,vec(1,10,0.1))
    holoParent(13,Body)
    
    holoCreate(14)
    holoPos(14,Body:toWorld(vec(-32,-64.2,7.29)))
    holoAng(14,Body:toWorld(ang(0,0,40)))
    holoScale(14,vec(1,1,0.1))
    holoParent(14,Body)
    
    holoCreate(15)
    holoPos(15,Body:toWorld(vec(-32,64.25,7.29)))
    holoAng(15,Body:toWorld(ang(0,0,-40)))
    holoScale(15,vec(1,1,0.1))
    holoParent(15,Body)
    
    holoCreate(16)
    holoScale(16,vec(4.34,8,2))
    holoParent(16,Body)
    
    holoCreate(17)
    holoModel(17,"hq_rcube")
    holoPos(17,Body:toWorld(vec(0,0,12)))
    holoScale(17,vec(4,7.6,1))
    holoParent(17,Body)
    
    holoCreate(18)
    holoModel(18,"hq_rcube")
    holoPos(18,Body:toWorld(vec(0,0,14)))
    holoScale(18,vec(3.4,7,1))
    holoParent(18,Body)
    
    holoCreate(19)
    holoModel(19,"models/hunter/misc/sphere1x1.mdl")
    holoPos(19,Body:toWorld(vec(0,0,18)))
    holoScale(19,vec(0.7,0.7,0.7))
    holoParent(19,Body)
    
    holoCreate(20)
    holoModel(20,"hq_cylinder")
    holoMaterial(20,"models/props_c17/metalladder001")
    holoColor(20,vec(150,150,150))
    holoPos(20,Body:toWorld(vec(-20,0,26)))
    holoAng(20,Body:toWorld(ang(0,90,90)))
    holoScale(20,vec(0.2,0.2,2))
    holoParent(20,19)
    
    holoCreate(21)
    holoModel(21,"hq_cylinder")
    holoMaterial(21,"models/props_c17/metalladder001")
    holoColor(21,vec(120,120,120))
    holoPos(21,Body:toWorld(vec(-33,0,26)))
    holoAng(21,Body:toWorld(ang(0,90,90)))
    holoScale(21,vec(0.24,0.24,0.2))
    holoParent(21,20)
    
    holoCreate(22)
    holoModel(22,"prism")
    holoMaterial(22,"models/props_c17/metalladder002")
    holoPos(22,Body:toWorld(vec(0,45,8.4)))
    holoAng(22,Body:toWorld(ang(85,90,0)))
    holoScale(22,vec(2,4.34,3))
    holoDisableShading(22,1)
    holoColor(22,vec(150,150,150))
    holoParent(22,Body)
    
    holoClipEnabled(22,1,1)
    holoClip(22,vec(0,0,3),vec(0,0,1),0)
    
    holoCreate(23)
    holoMaterial(23,"models/props_c17/metalladder002")
    holoPos(23,Body:toWorld(vec(0,60,6.2)))
    holoAng(23,Body:toWorld(ang(0,0,0)))
    holoScale(23,vec(4.34,0.5,0.7))
    holoDisableShading(23,1)
    holoColor(23,vec(150,150,150))
    holoParent(23,Body)
    
    holoCreate(24)
    holoModel(24,"prism")
    holoMaterial(24,"models/props_c17/metalladder002")
    holoPos(24,Body:toWorld(vec(0,46,-4)))
    holoAng(24,Body:toWorld(ang(70,90,0)))
    holoScale(24,vec(2,4.34,3))
    holoDisableShading(24,1)
    holoColor(24,vec(150,150,150))
    holoParent(24,Body)
    
    holoCreate(25)
    holoModel(25,"prism")
    holoMaterial(25,"models/props_c17/metalladder002")
    holoPos(25,Body:toWorld(vec(0,-46,-4)))
    holoAng(25,Body:toWorld(ang(80,-90,0)))
    holoScale(25,vec(2,4.34,3))
    holoDisableShading(25,1)
    holoColor(25,vec(150,150,150))
    holoParent(25,Body)
    
    holoCreate(26)
    holoMaterial(26,"models/props_c17/metalladder002")
    holoPos(26,Body:toWorld(vec(0,-61,4.5)))
    holoAng(26,Body:toWorld(ang(0,0,0)))
    holoScale(26,vec(4.34,0.5,0.9))
    holoDisableShading(26,1)
    holoColor(26,vec(150,150,150))
    holoParent(26,Body)
    
    holoCreate(27)
    holoModel(27,"prism")
    holoMaterial(27,"models/props_c17/metalladder002")
    holoPos(27,Body:toWorld(vec(0,-45,8.4)))
    holoAng(27,Body:toWorld(ang(85,-90,0)))
    holoScale(27,vec(2,4.34,3))
    holoDisableShading(27,1)
    holoColor(27,vec(150,150,150))
    holoParent(27,Body)
    
    holoClipEnabled(27,1,1)
    holoClip(27,vec(0,0,3),vec(0,0,1),0)
    
    for (Mat = 10,19) {
        holoMaterial(Mat,"models/props_c17/metalladder002")
        holoDisableShading(Mat,1)
        holoColor(Mat,vec(150,150,150))
    }
}

local Seat = Pod["Entity",entity]
local Driver = Seat:driver()
local W = Driver:keyForward()
local A = Driver:keyLeft()
local S = Driver:keyBack()
local D = Driver:keyRight()
local R = Driver:keyReload()
local Mouse1 = Driver:keyAttack1()
local Mouse2 = Driver:keyAttack2()
local Shift = Driver:keySprint()
local Active = Driver:isPlayer()
local Ang = Driver:eyeAngles():yaw()

T:setMass(50000)
T:setAlpha(0)
T:setPos(holoEntity(21):pos())

holoAng(19,ang(0,Ang,0))

if (!Active) {holoAng(19,Body:toWorld(ang(0,90,0)))}

if (changed(R) & R) {if(State == 0) {State = 1} else {State = 0}}
if (changed(State == 1) & State == 1) {Body:soundPlay(2,0,"ambient/machines/truck_idle_lp_01.wav")}
elseif (State == 0) {soundStop(2)}

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger1 = rangerOffset(30,entity():toWorld(vec(-34,-50,0)),-entity():up())

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger2 = rangerOffset(30,entity():toWorld(vec(34,-50,0)),-entity():up())

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger3 = rangerOffset(30,entity():toWorld(vec(-34,50,0)),-entity():up())

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger4 = rangerOffset(30,entity():toWorld(vec(34,50,0)),-entity():up())

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger5 = rangerOffset(35,entity():toWorld(vec(-34,17,0)),-entity():up())

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger6 = rangerOffset(35,entity():toWorld(vec(34,17,0)),-entity():up())

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger7 = rangerOffset(35,entity():toWorld(vec(-34,-17,0)),-entity():up())

rangerFilter(entity())
rangerFilter(players())
rangerFilter(entity():isWeldedTo())
Ranger8 = rangerOffset(35,entity():toWorld(vec(34,-17,0)),-entity():up())

holoPos(1,Ranger1:pos()+vec(0,0,20))
holoPos(2,Ranger2:pos()+vec(0,0,20))
holoPos(3,Ranger3:pos()+vec(0,0,20))
holoPos(4,Ranger4:pos()+vec(0,0,20))
holoPos(5,Ranger5:pos()+vec(0,0,20))
holoPos(6,Ranger6:pos()+vec(0,0,20))
holoPos(7,Ranger7:pos()+vec(0,0,20))
holoPos(8,Ranger8:pos()+vec(0,0,20))

Pos5 = Ranger5:position()
Pos6 = Ranger6:position()
Pos7 = Ranger7:position()
Pos8 = Ranger8:position()

if (W) {
    #Right side
    holoAng(1,holoEntity(1):toWorld(+ang(-9,0,0)))
    holoAng(3,holoEntity(3):toWorld(+ang(-9,0,0)))
    holoAng(5,holoEntity(5):toWorld(+ang(-9,0,0)))
    holoAng(7,holoEntity(7):toWorld(+ang(-9,0,0)))
    
    #Left side
    holoAng(2,holoEntity(2):toWorld(+ang(9,0,0)))
    holoAng(4,holoEntity(4):toWorld(+ang(9,0,0)))
    holoAng(6,holoEntity(6):toWorld(+ang(9,0,0)))
    holoAng(8,holoEntity(8):toWorld(+ang(9,0,0)))    
}
if (S) {
    #Right side
    holoAng(1,holoEntity(1):toWorld(+ang(9,0,0)))
    holoAng(3,holoEntity(3):toWorld(+ang(9,0,0)))
    holoAng(5,holoEntity(5):toWorld(+ang(9,0,0)))
    holoAng(7,holoEntity(7):toWorld(+ang(9,0,0)))
    
    #Left side
    holoAng(2,holoEntity(2):toWorld(+ang(-9,0,0)))
    holoAng(4,holoEntity(4):toWorld(+ang(-9,0,0)))
    holoAng(6,holoEntity(6):toWorld(+ang(-9,0,0)))
    holoAng(8,holoEntity(8):toWorld(+ang(-9,0,0)))
}

if (A) {for (I = 1,8) {holoAng(I,holoEntity(I):toWorld(+ang(-9,0,0)))}}

if (D) {for (I = 1,8) {holoAng(I,holoEntity(I):toWorld(+ang(9,0,0)))}}

if (changed(Mouse1) & Mouse1) {
    holoPos(20,holoEntity(20):toWorld(+vec(0,0,2)))
    holoEntity(20):soundPlay(1,0,"ambient/rottenburg/portcullis_slam.wav")
    Press = 1
    timer("shoot",100)
}

if (clk("shoot")) {
    holoPos(20,holoEntity(20):toWorld(+vec(0,0,-2)))
    Press = 0
}
