@name HeadCrab
@inputs [Pod Dmg Prop Cam]:wirelink 
@outputs Camdist Pos:vector Ang:angle Parent:entity Ranger:ranger Start GT:array 
@persist Hit Distance Driver:entity Underground Dead Alive GL:array 
@trigger 
runOnTick(1)

findInSphere(holoEntity(1):pos(),100)
findIncludeClass("player")
Target = findResult(1)

if (first()) {
    holoCreate(1)
    holoModel(1,"models/headcrabclassic.mdl")
    
    holoCreate(2)
    holoPos(2,holoEntity(1):toWorld(vec(-40,-1,40)))
    holoColor(2,vec(),0)
    holoParent(2,1)
    
    Prop:entity():propFreeze(1)
    Prop:entity():setMass(50000)
    Prop:entity():setColor(vec(),0)
    
    HP=100
    
    Alive = 1
}

    Cam["Position", vector] = holoEntity(2):pos()
    Cam["Parent", entity] = holoEntity(2)

    rangerFilter(Prop:entity())
    Ranger = rangerOffset(10,holoEntity(1):pos()+vec(0,0,5),-holoEntity(1):up())
    Hit = Ranger:hit()
    Distance = Ranger:distance()
    
    holoPos(1,vec(holoEntity(1):pos():x(),holoEntity(1):pos():y(),Ranger:position():z() + 1))

if (Alive) {
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 Alt = Driver:keyWalk()
local Mouse1 = Driver:keyAttack1()
local Mouse2 = Driver:keyAttack2()
local Shift = Driver:keySprint()
local Active = Driver:isPlayer()
local On = Active
local HoloEnt = holoEntity(1)
Cam["Activated", number] = Active
Prop:entity():setPos(HoloEnt:pos()+vec(0,0,8))
Prop:entity():setAng(HoloEnt:toWorld(ang(0,0,0)))

if(changed(Dmg["Clk",number])){HP-=Dmg["Damage",number]}

if((changed(W)|changed(Shift)|changed(Mouse1)|changed(Mouse2)&!W&!Shift&!Mouse1&!Mouse2)) {
    holoAnim(1,1)
}
if (changed(W) & W) {
    holoAnim(1,2)
}
if (changed(Shift & W) & Shift & W) {
    holoAnim(1,6)
}
if (changed(Mouse1) & Mouse1) {
    holoAnim(1,7)
    holoEntity(1):soundPlay("Attack",0,"npc/headcrab/attack2.wav")
    holoParentAttachment(1,Target,"eyes")
    holoPos(1,Target:attachmentPos("eyes")-vec(0,5,6))
    holoAng(1,Target:attachmentAng("eyes"))
}
if (changed(Mouse2) & Mouse2) {
    holoAnim(1,5)
    holoEntity(1):soundPlay("Scream",0,"npc/headcrab_poison/ph_scream3.wav")
}
if (changed(R) & R) {
    holoEntity(1):soundPlay("Shoot",0,"npc/manhack/mh_blade_snick1.wav")
    Shoot=propSpawn("models/props_c17/FurnitureDrawer001a_Shard01.mdl",holoEntity(1):pos()+vec(0,0,10),holoEntity(2):angles(),0)
    Shoot:applyForce((Shoot:forward())*99999)
    Shoot:setColor(vec(0,255,0))
    GL:pushEntity(Shoot)
    GT:pushNumber(Start)
}

for(I=1,GL:count()){
GT[I,number]=GT[I,number]+1
if (GT[I,number]>70){GT:remove(I)
    GL[I,entity]:propDelete()
    GL:remove(I)
}
}

if(changed(Alt) & Alt) { 
if(Underground == 1) {
    holoAnim(1,11) Underground = 0
}else {holoAnim(1,10) Underground = 1}
}

Ang = Driver:eyeAngles()

holoAng(1,ang(0,Ang:yaw(),0))

if (W) {holoPos(1,holoEntity(1):pos() +holoEntity(1):forward()*3)}
if (Shift & W) {holoPos(1,holoEntity(1):pos() +holoEntity(1):forward()*2)}
if (S) {holoPos(1,holoEntity(1):pos() -holoEntity(1):forward()*3)}
}

if((HP) & HP <= 0){
    holoEntity(1):soundPlay("Died",0,"npc/headcrab/die1.wav")
    holoAnim(1,15) Dead = 1 Alive = 0
}


