@name Half Life
@inputs [CamCon Num]:wirelink N0 N1 N2 N3 N4 N5 N6 N7 N8 N9 Slash Astrix Minus Plus Enter Del
@outputs Take P R Y  [AimEnt Self]:entity
@persist Take Move Self:entity Pos:vector P R Y
@persist Flip Initial TKP Stealth
@trigger 
@model models/props_junk/PopCan01a.mdl
#By Captain Maim STEAM_0:1:8017844
#[
N0 = Num["0",number]
N1 = Num["1",number]
N2 = Num["2",number]
N3 = Num["3",number]
N4 = Num["4",number]
#N5 = Num["5",number]
N6 = Num["6",number]
N7 = Num["7",number]
N8 = Num["8",number]
N9 = Num["9",number]
Slash = Num["/",number]
Astrix = Num["*",number]
Minus = Num["-",number]
Plus = Num["+",number]
Enter = Num["enter",number]
Del = Num[".",number]
]#

if(duped()){reset()}
if(first()|dupefinished()){
    TKP=1
    #entity():setAlpha(0)
    print("type !help for TKP and HalfLife options.")
    Parts=entity():getConstraints()
    for(C=1,Parts:count()){
       #Parts[C,entity]:setAlpha(0)
    }
    Stealth=0
}
O=entity():isConstrainedTo():owner()
Chat=O:lastSaid()
runOnTick(1)
runOnChat(1)
if(chatClk()){
    if(Chat=="!tkp"){TKP=!TKP} #this toggles Telekinetic Physgun support
    if(Chat=="!s"){
        Stealth=!Stealth 
        if(Stealth){print("Stealth Mode: Activated!")}else{print("Stealth Mode: Deactivated")}
    }
    if(Chat=="!help"){
        print("!tkp to toggle TeleKinetic Physgun support")
        print("!t to pick up or drop an item you are looking at.")
        print("!s to toggle stealth mode (hide your death avatar)")
        print("!flip to make you walk in reverse when dead.")
        #print("!use to use something.")
        print("t to move it towards you. And say anything to stop.")
        print("y to move it away from you. And say anything to stop.")
        print("numpad 5 to pickup or drop.")
        print("numpad 7 and 9 to pitch.")
        print("numpad 4 and 6 to yaw.")
        print("numpad 1 and 3 to roll.")
        print("numpad 0 to stop all rotation.")
        print("numpad 8 and 2 to move towards and away.")
        print("plus to draw it near quickly.")
        print("del to send away quickly.")
        
    }
}
Use=0
if(chatClk()){
    if(Chat=="!flip"){
        Flip=!Flip
        if(Flip){print("Reverse facing enabled")}else{print("Forward facing enabled")}
    }
    if(Chat=="!use"){
        Use=1
    }
}
Aim=O:aimPos()
AimEnt=O:aimEntity()
Ang=O:angles()
Eye=O:eye()



Pos=O:pos()

Rotate=ang(0,Flip*180,0)
Alive=O:isAlive()
if(Alive){Shootpos=entity():pos()}else{Shootpos=O:shootPos()}
Angle=O:eye():toAngle()+Rotate
Dead=!Alive

if(Alive){
    if(holoEntity(1)){
        holoDelete(1)
    }
}else{
    if(holoEntity(1)){
        holoPos(1,O:shootPos()) 
        holoAng(1,O:angles()+Rotate)
    }else{
        if(!Stealth){
            holoCreate(1,vec()) 
            Model="models/buildables/sentry3_rockets.mdl"
            #ifdef table:pushArray(array)
                Check2=1
                #else
                Check2=0
                holoModel(1,"pyramid")
                holoMaterial(1,"models/shadertest/shader3")
                #endif            
            if(Check2){
            #ifdef holoCustomModel(number,string,number)
                holoCustomModel(1,Model,1)
            #else 
                

                if(!holoEntity(3)){
                    #Models used
                    Dome="dome"
                    Cyl="hqcylinder"
                    Pl=O:pos() #location of entity to bond to
                    findInSphere(Pl,100)
                    
                    
                    
                    #colors and or size base 
                    B=vec(1,1,1) #Base vector
                    Red=vec(1,0,0)*255
                    Blue=vec(0,0,1)*255
                    White=vec(1,1,1)*255
                    
                    #hologram textures used
                    Eyes="models/error/new light1"
                    Flame="models/props_combine/tpballglow"
                    Raven="models/props_junk/ravenholmsign_sheet"
                    Metal="phoenix_storms/Indenttiles_1-2"
                    Arms=Metal
                    Face="phoenix_storms/Indenttiles2"
                    Off=-5
                    #Defines arrays for mass hologram creation
                    Holo=table() #(position-Offset,size,angle,color,model,parentID,material)
                    Holo:pushArray(array(vec(0,0,15+Off),B,ang(),White,Dome,O,Metal))#main dome
                    Holo:pushArray(array(vec(0,0,9+Off),vec(1,1,2)*0.75,ang(),B*128,Cyl,1,Raven))#base
                    Holo:pushArray(array(vec(6,3,17+Off),B*0.2,ang(90,0,0),Red,Dome,1,Eyes)) #eye Left
                    Holo:pushArray(array(vec(6,-3,17+Off),B*0.2,ang(90,0,0),Red,Dome,1,Eyes)) #eye Right
                    Holo:pushArray(array(vec(5,0,17+Off),vec(0.25,1,0.25),ang(90,0,0),Blue,Cyl,1,Face))#Visor
                    Holo:pushArray(array(vec(0,7,8+Off),vec(0.25,0.25,1),ang(),B*200,Cyl,1,Arms)) #arm left
                    Holo:pushArray(array(vec(0,-7,8+Off),vec(0.25,0.25,1),ang(),B*200,Cyl,1,Arms)) #arm right
                    Holo:pushArray(array(vec(0,0,12.5+Off),vec(0.25,0.25,1),ang(0,0,90),B*64,Cyl,1)) #arm left
                    Holo:pushArray(array(vec(0,0,0+Off),B*0.5,ang(180,0,0),Blue,Cyl,1,Flame)) #thruster
                    
                    #hologram generator
                    for(C=1,Holo:count()){
                        H=Holo[C,array]
                        holoCreate(C,H[1,vector]+Pl,H[2,vector],H[3,angle],H[4,vector],H[5,string])
                        if(H[6,number]){holoParent(C,H[6,number])}
                        if(H[6,entity]){holoParent(C,H[6,entity])} 
                        if(H[7,string]){holoMaterial(C,H[7,string])}
                    }
                }

            #endif
            }
        }
    }
}
#Input
CamCon:setNumber("Activated",Dead)
#CamCon:setNumber("Zoom",Zoom)
#CamCon:setNumber("X",X)
#CamCon:setNumber("Y",Y)
#CamCon:setNumber("Z",Z)
#CamCon:setNumber("Pitch",Pitch)
#CamCon:setNumber("Yaw",Yaw)
#CamCon:setNumber("Roll",Roll)
CamCon:setAngle("Angle",Angle)
CamCon:setVector("Position",Shootpos)
#CamCon:setVector("Direction",Direction)
#CamCon:setVector("Velocity",Velocity)
#CamCon:setEntity("Parent",Parent)





if(TKP){
    if((chatClk()&Chat=="!t")){
        Take=!Take
        if(Take&!Self){Take=0}
        print("TeleKinetic Physgun is: "+Take)
        if(Take){Self=O:aimEntity() print("Grabbing "+Self:type())}
    }   
    if(!O:isAlive()){
        
    }
    
    if(Chat=="t"){Move-=1}
    if(Chat=="y"){Move+=1}
    if(N8){Move+=1}
    if(N2){Move-=1}
    if(N5&~N5){
        Take=!Take Self=O:aimEntity() 
        if(Take&!Self){Take=0}
        print("TeleKinetic Physgun is: "+Take)
        print("Grabbing "+Self:type())
        Move=0
        Initial=O:pos():distance(Self:pos())
    }
    Rate=150
    if(N7){P=Rate}
    if(N9){P=-Rate}
    if(N4){Y=Rate}
    if(N6){Y=-Rate}
    if(N1){R=Rate}
    if(N3){R=-Rate}
    if(N0){R=Y=P=0}
    if(Del){Move+=50}
    if(Plus){Move-=50}
    
    #clamp(R,-180,180)
    #clamp(P,-90,90)
    #clamp(Y,-180,180)
    if(Take){
        
        #Self=entity():isConstrainedTo()
        #if(!Self){Self=entity()}
        #runOnTick(1)
        #PYR=vec(0,0,0)
     
        if(abs(R)==180){R=0}
        Time=1500/1000
        interval(Time*1000)
        InertiaConstant = 27.05307927383
        TargetAng=angnorm(ang(P,Y,R))
        Local=Self:toLocal(Self:angles())
        AngDist=TargetAng-Local
        #AngDist=TargetAng-Self:angles()
        Inertia = InertiaConstant*ang(Self:inertia():y(),Self:inertia():z(),Self:inertia():x())
        AngVel = AngDist/Time
        Self:applyAngForce(Inertia*(AngVel-Self:angVel()))
    
        Speed=100*(Self:mass()/4)
        
        XYZ=O:shootPos()+O:eye()*(Initial+Move)
        
        Self:applyForce(Speed*(XYZ-Self:pos())-(Self:vel()/2)*Self:mass())
    }
}
