@name Spider
@inputs 
@outputs 
@persist CPit State 
@trigger 
runOnTick(1)

Size = 1

if (first()) {
    
    entity():setColor(vec(),0)
#Body
    #Back butt
    holoCreate(1)
    holoModel(1,"hq_sphere")
    holoAng(1,ang(0,0,90))
    holoScale(1,vec(6.2,3.4,5.2)/Size)
    holoPos(1,entity():toWorld(vec(-53,0,4)/Size))
    holoParent(1,entity())
    
    #Middle Top
    holoCreate(2)
    holoModel(2,"hq_hdome_thin")
    holoScale(2,vec(3,3,3)/Size)
    holoPos(2,entity():toWorld(vec(0,0,-1)/Size))
    holoParent(2,entity())
    
    #Middle Bottem
    holoCreate(3)
    holoModel(3,"hq_hdome_thin")
    holoScale(3,vec(3.6,3.6,3)/Size)
    holoAng(3,ang(0,0,-180))
    holoPos(3,entity():toWorld(vec(0,0,10)/Size))
    holoParent(3,entity())
    holoClipEnabled(3,1,1)
    holoClip(3,vec(0,0,10),vec(0,0,1),0)
    
    #Middle Joining
    holoCreate(4)
    holoModel(4,"hq_torus")
    holoScale(4,vec(3.05,3.05,3.05)/Size)
    holoAng(4,ang(0,0,-180))
    holoPos(4,entity():toWorld(vec(0,0,0)/Size))
    holoParent(4,entity())
    
#Legs
    #Left Back
    holoCreate(5)
    holoModel(5,"hq_cylinder")
    holoScale(5,vec(0.3,0.3,3)/Size)
    holoAng(5,ang(40,120,0))
    holoPos(5,entity():toWorld(vec(-13,21,10)/Size))
    holoParent(5,4)
    holoClipEnabled(5,1,1)
    holoClip(5,vec(0,0,-12),vec(0,0,1),0)
    
    #Right Back
    holoCreate(6)
    holoModel(6,"hq_cylinder")
    holoScale(6,vec(0.3,0.3,3)/Size)
    holoAng(6,ang(40,-120,0))
    holoPos(6,entity():toWorld(vec(-13,-21,10)/Size))
    holoParent(6,4)
    holoClipEnabled(6,1,1)
    holoClip(6,vec(0,0,-12),vec(0,0,1),0)
    
    #Left Middle Back
    holoCreate(7)
    holoModel(7,"hq_cylinder")
    holoScale(7,vec(0.3,0.3,2.8)/Size)
    holoAng(7,ang(40,100,0))
    holoPos(7,entity():toWorld(vec(-5,21,7)/Size))
    holoParent(7,4)
    holoClipEnabled(7,1,1)
    holoClip(7,vec(0,0,-10),vec(0,0,1),0)
    
    #Right Middle Back
    holoCreate(8)
    holoModel(8,"hq_cylinder")
    holoScale(8,vec(0.3,0.3,2.8)/Size)
    holoAng(8,ang(40,-100,0))
    holoPos(8,entity():toWorld(vec(-5,-21,7)/Size))
    holoParent(8,4)
    holoClipEnabled(8,1,1)
    holoClip(8,vec(0,0,-10),vec(0,0,1),0)
    
    #Left Middle Front
    holoCreate(9)
    holoModel(9,"hq_cylinder")
    holoScale(9,vec(0.3,0.3,2.8)/Size)
    holoAng(9,ang(40,80,0))
    holoPos(9,entity():toWorld(vec(5,21,7)/Size))
    holoParent(9,4)
    holoClipEnabled(9,1,1)
    holoClip(9,vec(0,0,-10),vec(0,0,1),0)
    
    #Right Middle Front
    holoCreate(10)
    holoModel(10,"hq_cylinder")
    holoScale(10,vec(0.3,0.3,2.8)/Size)
    holoAng(10,ang(40,-80,0))
    holoPos(10,entity():toWorld(vec(5,-21,7)/Size))
    holoParent(10,4)
    holoClipEnabled(10,1,1)
    holoClip(10,vec(0,0,-10),vec(0,0,1),0)
    
    #Left Front
    holoCreate(11)
    holoModel(11,"hq_cylinder")
    holoScale(11,vec(0.3,0.3,3)/Size)
    holoAng(11,ang(40,50,0))
    holoPos(11,entity():toWorld(vec(14,21,10)/Size))
    holoParent(11,4)
    holoClipEnabled(11,1,1)
    holoClip(11,vec(0,0,-12),vec(0,0,1),0)
    
    #Right Front
    holoCreate(12)
    holoModel(12,"hq_cylinder")
    holoScale(12,vec(0.3,0.3,3)/Size)
    holoAng(12,ang(40,-50,0))
    holoPos(12,entity():toWorld(vec(14,-21,10)/Size))
    holoParent(12,4)
    holoClipEnabled(12,1,1)
    holoClip(12,vec(0,0,-12),vec(0,0,1),0)
    
    #Left Front Leg Part 2
    holoCreate(13)
    holoModel(13,"hq_cylinder")
    holoScale(13,vec(0.23,0.23,3.2)/Size)
    holoAng(13,ang(120,5,0))
    holoPos(13,entity():toWorld(vec(39,31.5,14)/Size))
    holoParent(13,11)
    
    #Right Front Leg Part 2
    holoCreate(14)
    holoModel(14,"hq_cylinder")
    holoScale(14,vec(0.23,0.23,3.2)/Size)
    holoAng(14,ang(120,-5,0))
    holoPos(14,entity():toWorld(vec(39,-31.5,14)/Size))
    holoParent(14,12)
    
    #Left Front Leg Part 3
    holoCreate(15)
    holoModel(15,"hq_cylinder")
    holoScale(15,vec(0.18,0.18,4)/Size)
    holoAng(15,ang(140,0,0))
    holoPos(15,entity():toWorld(vec(70,33,-13.2)/Size))
    holoParent(15,13)
    
    #Right Front Leg Part 3
    holoCreate(16)
    holoModel(16,"hq_cylinder")
    holoScale(16,vec(0.18,0.18,4)/Size)
    holoAng(16,ang(140,0,0))
    holoPos(16,entity():toWorld(vec(70,-33,-13.2)/Size))
    holoParent(16,14)
    
    #Left Back Leg Part 2
    holoCreate(17)
    holoModel(17,"hq_cylinder")
    holoScale(17,vec(0.23,0.23,3.2)/Size)
    holoAng(17,ang(-120,-24,0))
    holoPos(17,entity():toWorld(vec(-35.5,39,14)/Size))
    holoParent(17,5)
    
    #Right Back Leg Part 2
    holoCreate(18)
    holoModel(18,"hq_cylinder")
    holoScale(18,vec(0.23,0.23,3.2)/Size)
    holoAng(18,ang(-120,24,0))
    holoPos(18,entity():toWorld(vec(-35.5,-39,14)/Size))
    holoParent(18,6)
    
    #Left Back Leg Part 3
    holoCreate(19)
    holoModel(19,"hq_cylinder")
    holoScale(19,vec(0.18,0.18,4)/Size)
    holoAng(19,ang(-140,-12,0))
    holoPos(19,entity():toWorld(vec(-65,48.8,-13.2)/Size))
    holoParent(19,17)
    
    #Right Back Leg Part 3
    holoCreate(20)
    holoModel(20,"hq_cylinder")
    holoScale(20,vec(0.18,0.18,4)/Size)
    holoAng(20,ang(-140,12,0))
    holoPos(20,entity():toWorld(vec(-65,-48.8,-13.2)/Size))
    holoParent(20,18)
    
    #Left Back Middle Part 2
    holoCreate(21)
    holoModel(21,"hq_cylinder")
    holoScale(21,vec(0.23,0.23,2.6)/Size)
    holoAng(21,ang(-40,100,0))
    holoPos(21,entity():toWorld(vec(-9,43,7)/Size))
    holoParent(21,7)
    
    #Right Back Middle Part 2
    holoCreate(22)
    holoModel(22,"hq_cylinder")
    holoScale(22,vec(0.23,0.23,2.6)/Size)
    holoAng(22,ang(-40,-100,0))
    holoPos(22,entity():toWorld(vec(-9,-43,7)/Size))
    holoParent(22,8)
    
    #Left Front Middle Part 2
    holoCreate(23)
    holoModel(23,"hq_cylinder")
    holoScale(23,vec(0.23,0.23,2.6)/Size)
    holoAng(23,ang(-30,80,0))
    holoPos(23,entity():toWorld(vec(8.3,40,7)/Size))
    holoParent(23,9)
    
    #Right Front Middle Part 2
    holoCreate(24)
    holoModel(24,"hq_cylinder")
    holoScale(24,vec(0.23,0.23,2.6)/Size)
    holoAng(24,ang(-30,-80,0))
    holoPos(24,entity():toWorld(vec(8.3,-40,7)/Size))
    holoParent(24,10)
    
    #Left Front Middle Part 3
    holoCreate(25)
    holoModel(25,"hq_cylinder")
    holoScale(25,vec(0.18,0.18,1.8)/Size)
    holoAng(25,ang(-20,80,0))
    holoPos(25,entity():toWorld(vec(10.3,51,-16)/Size))
    holoParent(25,23)
    
    #Right Front Middle Part 3
    holoCreate(26)
    holoModel(26,"hq_cylinder")
    holoScale(26,vec(0.18,0.18,1.8)/Size)
    holoAng(26,ang(-20,-80,0))
    holoPos(26,entity():toWorld(vec(10.3,-51,-16)/Size))
    holoParent(26,24)
    
    #Left Back Middle Part 3
    holoCreate(27)
    holoModel(27,"hq_cylinder")
    holoScale(27,vec(0.18,0.18,1.8)/Size)
    holoAng(27,ang(-20,95.5,0))
    holoPos(27,entity():toWorld(vec(-11,56.4,-15)/Size))
    holoParent(27,21)
    
    #Right Back Middle Part 3
    holoCreate(28)
    holoModel(28,"hq_cylinder")
    holoScale(28,vec(0.18,0.18,1.8)/Size)
    holoAng(28,ang(-20,-95.5,0))
    holoPos(28,entity():toWorld(vec(-11,-56.4,-15)/Size))
    holoParent(28,22)
#Eyes
    #Middle Left
    holoCreate(29)
    holoModel(29,"hq_sphere")
    holoScale(29,vec(0.6,0.6,0.6)/Size)
    holoAng(29,ang(0,0,0))
    holoPos(29,entity():toWorld(vec(15,-4,5)/Size))
    holoParent(29,2)
    
    #Middle Right
    holoCreate(30)
    holoModel(30,"hq_sphere")
    holoScale(30,vec(0.6,0.6,0.6)/Size)
    holoAng(30,ang(0,0,0))
    holoPos(30,entity():toWorld(vec(15,4,5)/Size))
    holoParent(30,2)
    
    #Far Left
    holoCreate(31)
    holoModel(31,"hq_sphere")
    holoScale(31,vec(0.4,0.4,0.4)/Size)
    holoAng(31,ang(0,0,0))
    holoPos(31,entity():toWorld(vec(12,-11,5)/Size))
    holoParent(31,2)
    
    #Far Right
    holoCreate(32)
    holoModel(32,"hq_sphere")
    holoScale(32,vec(0.4,0.4,0.4)/Size)
    holoAng(32,ang(0,0,0))
    holoPos(32,entity():toWorld(vec(12,11,5)/Size))
    holoParent(32,2)
    
    for (M=1,28) {holoMaterial(M,"sprops/trans/misc/ls_m1")}
    for (S=29,32) {holoMaterial(S,"phoenix_storms/fender_white")}
    for (C=29,32) {holoColor(C,vec(55,55,55))}
}
#[
R = owner():keyWalk()

if(R & (CPit == -24 | CPit == 0)) {if(State == 0) {State = 1} else {State = 0}}

if(State == 1) {
    if(CPit > -24) {
        CPit -= 1
        holoAng(5,ang(40,120+CPit,0))
        holoAng(6,ang(40,-CPit-120,0))
        holoAng(7,ang(40,100+CPit,0))
        holoAng(8,ang(40,-CPit-100,0))
        holoAng(9,ang(40,80+CPit,0))
        holoAng(10,ang(40,-CPit-80,0))
        
        holoAng(7,holoEntity(7):angles()+ang(0,0,CPit))
        holoAng(8,holoEntity(8):angles()+ang(0,0,CPit))
        holoAng(9,holoEntity(9):angles()+ang(0,0,CPit))
        holoAng(10,holoEntity(10):angles()+ang(0,0,CPit))
    }
} else {
    if(CPit < 0) {
        CPit += 1
        holoAng(5,ang(40,120+CPit,0))
        holoAng(6,ang(40,-CPit-120,0))
        holoAng(7,ang(40,100+CPit,0))
        holoAng(8,ang(40,-CPit-100,0))
        holoAng(9,ang(40,80+CPit,0))
        holoAng(10,+ang(40,-CPit-80,0))
        
        holoAng(7,holoEntity(7):angles()+ang(0,0,-CPit))
        holoAng(8,holoEntity(8):angles()+ang(0,0,-CPit))
        holoAng(9,holoEntity(9):angles()+ang(0,0,-CPit))
        holoAng(10,holoEntity(10):angles()+ang(0,0,-CPit))
    }
}
