@name HoloSpear
@inputs 
@outputs 
@persist Step Pos:vector Scale UPos:vector SP First Dir:vector Speed User:entity
@trigger 
interval(10)
runOnLast(1)
if(first()|duped()){
    Scale=1
    User=owner() #findPlayerByName("jetal")
    Pos=entity():pos()+vec(0,0,10)*Scale
    First=1
    holoDeleteAll()

    holoCreate(999,vec(0,0,10)*Scale)
    holoAlpha(999,0)
    holoAng(999,ang())   


    holoCreate(1,vec())
    holoModel(1,"hqcylinder2")
    holoScaleUnits(1,vec(2,2,70)*Scale)
    holoMaterial(1,"models/props_pipes/GutterMetal01a")
    holoColor(1,vec(255,255,255))
    holoShadow(1,1)    
    holoAng(1,ang())
    holoParent(1,999)

    holoCreate(12,vec(0,0,40)*Scale)
    holoModel(12,"hqcone")
    holoScaleUnits(12,vec(3,3,14)*Scale)
    holoMaterial(12,"models/props_c17/metalladder001")
    holoColor(12,vec(200,200,200))
    holoShadow(12,1)
    holoAng(12,ang())
    holoParent(12,999)
    holoAng(999,ang(90,0,0))
    holoPos(999,Pos)
}


if(!Step){
    holoAlpha(1,255)
    holoAlpha(12,255)    

    if(First){
        holoAng(999,holoEntity(999):toWorld(ang(0,0,1)))
    }   
    if(User:pos():distance(holoEntity(999):pos())<50*Scale | User:keyUse()){
    Step++
    holoPos(999,User:attachmentPos("anim_attachment_RH"))
    holoAng(999,User:attachmentAng("anim_attachment_RH")+ang(0,180,90))
    holoParentAttachment(999,User,"anim_attachment_RH") 
   First=0
    }

}
if(Step==1){
holoEntity(999):removeTrails()
Pos=User:attachmentPos("anim_attachment_RH")
Weapon=User:weapon():type():find("crowbar")
if(Weapon){
    User:weapon():setMaterial("models/effects/vol_light001")
    User:weapon():setColor(vec())

    holoAlpha(1,255)
    holoAlpha(12,255)
}else{
    holoAlpha(1,0)
    holoAlpha(12,0)
}    



if(User:keyAttack1()&Weapon){
    Step++
    Dir=(User:aimPos()-Pos):normalized()+vec(random(-0.02,0.02),random(-0.02,0.02),random(-0.02,0.02))
    Dir=Dir:normalized()
    Speed=clamp(30*Scale,15,900000000000000)
    holoUnparent(999)
    holoEntity(999):setTrails(5*Scale,0,2,"trails/smoke",vec(80,80,80),250)
    holoEntity(999):soundPlay(3,0,"vehicles/fast_windloop1.wav")
    soundPitch(3,randint(100,300))
    soundVolume(3,0.4)
}
}   
if(Step==2){
    UPos=Pos+Dir*Speed-vec(0,0,0.2)
    Dir=(UPos-Pos):normalized()
    Speed-=0.01
    Pos=UPos
    holoPos(999,Pos)
    holoAng(999,Dir:toAngle()+ang(90,0,0))
    RD=rangerOffset(Speed*Scale,holoEntity(12):pos(),holoEntity(12):up())
    if(User:keyUse()){
        Step=1
         holoPos(999,User:attachmentPos("anim_attachment_RH"))
         holoAng(999,User:attachmentAng("anim_attachment_RH")+ang(0,180,90))
         holoParentAttachment(999,User,"anim_attachment_RH")
        soundStop(3,0.25)
   }

    if(RD:hit()){
        Step=0
        Pos=RD:position()
        RD:entity():applyOffsetForce(Dir*2000*Scale,Pos)

        holoPos(999,Pos)
        holoParentAttachment(999,RD:entity(),"")
        holoParent(999,RD:entity())
        soundStop(3,0.25)
        holoEntity(999):soundPlay(4,2,"physics/wood/wood_box_impact_bullet"+randint(1,4)+".wav")
        holoEntity(999):soundPlay(5,2,"ambient/voices/f_scream1.wav"+randint(1,4)+".wav")
    }
}
if(last()){holoDeleteAll()}
