@name The Heavy
@persist Walk Jump AllowMore Diff Spawned Dead Owned FootStepRate Exploding #Numbers
@persist [O]:vector #Vectors
@persist [Target]:entity #Entities
@persist [FootSteps Sound]:array #Arrays
@persist [Weapon]:string #Strings
@model models/props_borealis/bluebarrel001.mdl
if(first()){
 FootSteps[1,string]="/mvm/player/footsteps/robostep_01.wav"
 FootSteps[2,string]="/mvm/player/footsteps/robostep_02.wav"
 FootSteps[3,string]="/mvm/player/footsteps/robostep_03.wav"
 FootSteps[4,string]="/mvm/player/footsteps/robostep_04.wav"
 FootSteps[5,string]="/mvm/player/footsteps/robostep_05.wav"
 FootSteps[6,string]="/mvm/player/footsteps/robostep_06.wav"
 FootSteps[7,string]="/mvm/player/footsteps/robostep_07.wav"
 FootSteps[8,string]="/mvm/player/footsteps/robostep_08.wav"
 FootSteps[9,string]="/mvm/player/footsteps/robostep_09.wav"
 FootSteps[10,string]="/mvm/player/footsteps/robostep_10.wav"
 FootSteps[11,string]="/mvm/player/footsteps/robostep_11.wav"
 FootSteps[12,string]="/mvm/player/footsteps/robostep_12.wav"
 FootSteps[13,string]="/mvm/player/footsteps/robostep_13.wav"
 FootSteps[14,string]="/mvm/player/footsteps/robostep_14.wav"
 FootSteps[15,string]="/mvm/player/footsteps/robostep_15.wav"
 FootSteps[16,string]="/mvm/player/footsteps/robostep_16.wav"
 FootSteps[17,string]="/mvm/player/footsteps/robostep_17.wav"
 FootSteps[18,string]="/mvm/player/footsteps/robostep_18.wav"

runOnTick(1)

soundPlay(2,0,"/mvm/giant_heavy/giant_heavy_loop.wav")

Weapon = "LOSER"
FootStepRate = 250
Diff = 45

timer("spawn",250)

entity():propFreeze(0)
entity():setColor(0,0,0,0)

holoCreate(1)
holoModel(1,"models/bots/heavy/bot_heavy.mdl")
holoPos(1,entity():toWorld(vec(0,0,-Diff)))
holoParent(1,entity())
holoAnim(1,"Stand_"+Weapon)
holoSkin(1,round(random(0,1)))

function entity:turnTo(Tarang:angle){
V = This:toLocal(rotationVector(quat(Tarang)/quat(This))+This:pos())
This:applyTorque((100*V - 30*This:angVelVector())*This:inertia()/3)
}
function entity:goto(Vector:vector){
 This:applyForce(((Vector-This:pos())*25-This:vel())*This:mass())   
}
}

if(clk("spawn")){
 stoptimer("spawn")
 Spawned = 1   
}

if(Spawned){
 if(!Dead){
    #Death Handling
    if(entity():isOnFire()|entity():angles():pitch()>85||entity():angles():pitch()<-85||entity():angles():roll()>85||entity():angles():roll()<-85|entity():isUnderWater()){
     Dead = 1   
    }
    
    #Entity Detection
     if(findCanQuery()){
     findByClass("player")
     findSortByDistance(entity():pos())
     if(find():pos():distance(entity():pos())<750){
        Target = find()
        Owned = 1
    }   
    }   
    
    #Rangers, applyForce, and applyTorque
    Ranger = rangerOffset(Diff,entity():pos(),vec(0,0,-1))
    
    if(Ranger:hit()&!Jump){
     V = Ranger:pos()+vec(0,0,Diff)+O
     if(Owned){
     if(Walk){
     Ang = ang(0,(entity():pos()-Target:pos()):toAngle():yaw(),0)   
    }else{ Ang = ang(0,entity():angles():yaw(),0) }
    }else{ Ang = ang(0,entity():angles():yaw(),0) }
    entity():goto(V)
    entity():turnTo(Ang)
    }
    
    if(changed(Ranger:hit())){
        if(Ranger:hit()){
         soundPlay(6,0,FootSteps[round(random(1,FootSteps:count())),string])   
        }
    }
    
    #Walking & holoSetPose(INDEX,STRING,AMOUNT)
    if(Owned){
     if(entity():pos():distance(Target:pos())<600){
        Walk = 1
    }else{Walk = 0}
    
    if(changed(Walk)){
     if(Walk){
     holoAnim(1,"Run_"+Weapon)
     timer("step1",FootStepRate)   
    }   
     if(!Walk){
     holoAnim(1,"Stand_"+Weapon)
     stoptimer("step1")   
     stoptimer("step2")
     stoptimer("step3")
    }
    }
    
    if(Walk){
    O = entity():forward()*10
    
    holoSetPose(1,"move_x",entity():vel():length()/250)
    
    if(clk("step1")){
    stoptimer("step1")
    timer("step2",FootStepRate)
    if(Ranger:hit()){
    soundPlay(10,0,FootSteps[round(random(1,FootSteps:count())),string]) 
    }  
    }
    if(clk("step2")){
    stoptimer("step2")
    timer("step3",FootStepRate)
    if(Ranger:hit()){
    soundPlay(11,0,FootSteps[round(random(1,FootSteps:count())),string])
    }
    }
    if(clk("step3")){
    stoptimer("step3")
    timer("step1",FootStepRate)
    if(Ranger:hit()){
    soundPlay(12,0,FootSteps[round(random(1,FootSteps:count())),string])
    }
    }   
    }else{ O = entity():forward()*0 }
    
    }
    
    #Jumping
    FRang = rangerOffset(100,entity():pos(),entity():forward())
    
    if(FRang:hit()){
     Jump = 1   
    }else{ Jump = 0 }
    
    if(changed(Jump)){
     if(Jump){
     applyForce(entity():up()*20000)
     soundPlay(3,0,"/mvm/sentrybuster/mvm_sentrybuster_step_0"+round(random(1,4))+".wav")
    }   
    }
    
    #Exploding
    if(entity():pos():distance(Target:pos())<100){
        Dead = 1
        applyForce(entity():up()*15000)
        applyAngForce(ang(random(1,360),random(1,360),random(1,360))*50)
        Exploding = 1
        soundPlay(5,0,"/vo/mvm/norm/heavy_mvm_cloakedspy0"+round(random(1,4))+".mp3")
    }
    
}   

if(changed(Dead)){
    if(Dead){
    setName("@heavy_dead")
    soundStop(1)
    timer("delete",3000)
    if(!Exploding){
    soundStop(2)
    soundStop(3)
    soundPlay(5,0,"/vo/mvm/norm/heavy_mvm_paincrticialdeath0"+round(random(1,3))+".mp3")
    holoSetPose(1,"mode_scale",0)
    holoAnim(1,"dieviolent",0,0.5)
    holoDelete(2)
    holoCreate(3)
    holoEntity(3):removeTrails()
    holoModel(3,"models/buildables/sapper_dispenser.mdl")
    holoAlpha(3,0)
    holoParent(3,entity())
    holoCreate(4)
    holoModel(4,"models/buildables/sapper_sentry3.mdl")
    holoPos(4,holoEntity(3):toWorld(vec(0,0,-10)))
    holoAlpha(4,0)
    holoParent(4,entity())     
}else{
holoAnim(1,"Airwalk_ITEM1")
}
}
}

if(Dead){
   if(clk("delete")){
 B=propSpawn("models/props_phx/amraam.mdl",entity():pos(),1)
 B:propBreak()
 selfDestruct()  
}     
}
}
