@name NPC possessor
@inputs [CamCon AdvPod]:wirelink
@outputs [NPC Aim LaserE]:entity 
@persist [PNPC NPC]:entity Wep:array Gun
@trigger 

if(duped()|dupefinished()){reset()}
interval(100)
#Outputs
W=AdvPod["W",number]
A=AdvPod["A",number]
S=AdvPod["S",number]
D=AdvPod["D",number]
Mouse1=AdvPod["Mouse1",number]
Mouse2=AdvPod["Mouse2",number]
R=AdvPod["R",number]
Space=AdvPod["Space",number]
Shift=AdvPod["Shift",number]
Zoom=AdvPod["Zoom",number]
Alt=AdvPod["Alt",number]
TurnLeftKey=AdvPod["TurnLeftKey",number]
TurnRightKey=AdvPod["TurnRightKey",number]
#X=AdvPod["X",number]
#Y=AdvPod["Y",number]
#Z=AdvPod["Z",number]
PrevWeapon=AdvPod["PrevWeapon",number]
NextWeapon=AdvPod["NextWeapon",number]
#AimPos=AdvPod["AimPos",vector]
ThirdPerson=AdvPod["ThirdPerson",number]
#Distance=AdvPod["Distance",number]
Light=AdvPod["Light",number]
Active=AdvPod["Active",number]
#Team=AdvPod["Team",number]
#Health=AdvPod["Health",number]
#Armor=AdvPod["Armor",number]
Bearing=AdvPod["Bearing",number]
Elevation=AdvPod["Elevation",number]
Entity=AdvPod["Entity",entity]

O=entity():isConstrainedTo():driver()
rangerFilter(entity():getConstraints())
Aim=rangerOffset(1000,O:pos(),O:eye()):entity()

if(first()){
    Wep=array()
    Wep:pushString("crowbar")
    Wep:pushString("stunstick")
    Wep:pushString("pistol")
    Wep:pushString("357")
    Wep:pushString("smg1")
    Wep:pushString("ar2")
    Wep:pushString("shotgun")
    Wep:pushString("annabelle")
    Wep:pushString("crossbow")
    Wep:pushString("frag")
    Wep:pushString("rpg")
    Wep:pushString("none")
    Gun=4  

}

#Output
#On=CamCon:number("On")
#X=CamCon:number("X")
#Y=CamCon:number("Y")
#Z=CamCon:number("Z")

if(Active){
    
    if(Aim:isNPC()&Mouse1&!NPC){PNPC=NPC NPC=Aim}
    if(NPC:isAlive()){
        if(NPC:shootPos()!=NPC:pos()){
            Position=NPC:shootPos()+vec(0,0,20)
        }else{
            Position=NPC:pos()+vec(0,0,NPC:boxSize():z()+10)
        }
        
        Direction=O:eye()
        #Velocity=NPC:vel()
        #Parent=NPC
        rangerFilter(NPC)
        Laser=rangerOffset(3000,Position,Direction)
        holoCreate(1,Laser:position(),vec(1,1,1)*0.5)
        LaserE=Laser:entity()
        
        
        if(R&!Mouse1){
            PNPC=NPC
            if(LaserE:isNPC()){NPC=LaserE}else{NPC=noentity()}
        }
        if(Alt&PNPC:isAlive()){NPC=PNPC}
        if(LaserE){
            if(Mouse1){
                NPC:npcSetTarget(LaserE)
                NPC:npcRelationship(LaserE,"hate",999)
                #NPC:npcAttack()
                NPC:npcShoot()
            }
            holoColor(1,vec(255,0,0))
            if(Space){NPC:npcRelationship(LaserE,"like",999)}
        }else{holoColor(1,vec(1,1,1)*255)}
        #NPC:npcFace(O:eye())
        Dist=100
#        Pl=players()
#        for(C=1,players():count()){
#            if(Pl[C,entity]==owner()){Pl:remove(C)}
#        }
        holoVisible(1,players(),0)
        holoVisible(1,owner(),1)
        if(PrevWeapon){
            Gun--
            if(Gun<1){Gun=Wep:count()}
            print(Wep[Gun,string])
        }
        if(NextWeapon){
            Gun++
            if(Gun>Wep:count()){Gun=1}
            print(Wep[Gun,string])
        }
        if(Mouse2){NPC:npcGiveWeapon(Wep[Gun,string])}
        
        Move=Position
        if(W){
            Move=Position+(O:eye()*Dist)
        }
        elseif(S){
            Move=Position+(O:eye()*-Dist)
        }
        
        if(A){
            Move=Move+(O:eye():rotate(ang(0,90,0))*Dist)
        }
        elseif(D){
            Move=Move+(O:eye():rotate(ang(0,90,0))*-Dist)
        }
        
            
        
        if(W|A|D|S){
            if(Shift){
                NPC:npcGoRun(Move)
            }else{
                NPC:npcGoWalk(Move)
            }
        }else{
            #NPC:npcStop()
        }
    }else{
        NPC=noentity()
        #Parent=entity()
        Position=entity():pos()+vec(0,0,10)
        holoDelete(1)
    }





    if(Zoom){Zoomed=3}else{Zoomed=100}
    if(NPC){Activate=1}else{Activate=0}
}else{
    holoDelete(1)
}


#Input
CamCon:setNumber("Activated",Activate)
CamCon:setNumber("Zoom",Zoomed)
#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",Position)
CamCon:setVector("Direction",Direction)
#CamCon:setVector("Velocity",Velocity)
#CamCon:setEntity("Parent",Parent)


Eject=0
Crosshairs=1
#Inputs
#AdvPod["Lock",number]=Lock
#AdvPod["Terminate",number]=Terminate
#AdvPod["Strip Weapons",number]=Strip
AdvPod["Eject",number]=Eject
#AdvPod["Disable",number]=Disable
AdvPod["Crosshairs",number]=Crosshairs
#AdvPod["Break",number]=Break
#AdvPod["Allow Buttons",number]=Buttons
#AdvPod["Relative",number]=Relative
#AdvPod["Damage Health",number]=DHealth
#AdvPod["Damage Armor",number]=DArmor
