@name The Scout
@persist [E T]:entity Ded V:vector Rdy W
@persist [S DS]:array
@model models/props_borealis/bluebarrel001.mdl

interval(15)

if(first())
{
    function entity:goto(V:vector)
    {
        This:applyForce(((V-This:pos())*25-This:vel())*This:mass())   
    }
    
    function entity:angTo(A:angle)
    {
        This:applyAngForce((angnorm(A-This:angles())*5-This:angVel())*This:mass())
    }
    
    E = entity()
    E:setColor(0,0,0,0)
    E:propFreeze(0)
    E:setMass(120)
    
    T = owner()
    
    soundPlay("idle",0,"mvm/giant_scout/giant_scout_loop.wav")
    
    local H = holoCreate(1,E:toWorld(vec(0,0,-40)))
    holoModel(1,"models/bots/scout/bot_scout.mdl")
    holoSkin(1,randint(0,1))
    holoParent(1,E)
    
    local B = holoCreate(2,H:attachmentPos("weapon_bone"),vec(1),H:attachmentAng("weapon_bone"))
    holoAng(2,B:toWorld(ang(0,0,-90)))
    holoModel(2,"models/weapons/c_models/c_bat.mdl")
    holoParentAttachment(2,H,"weapon_bone")
	
    S = array(
        "vo/mvm/norm/taunts/scout_mvm_taunts01.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts02.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts03.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts04.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts05.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts06.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts07.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts08.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts09.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts10.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts11.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts12.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts13.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts14.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts15.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts16.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts17.mp3",
        "vo/mvm/norm/taunts/scout_mvm_taunts18.mp3",
        "vo/mvm/norm/scout_mvm_apexofjump01.mp3",
        "vo/mvm/norm/scout_mvm_apexofjump02.mp3",
        "vo/mvm/norm/scout_mvm_apexofjump03.mp3",
        "vo/mvm/norm/scout_mvm_apexofjump04.mp3",
        "vo/mvm/norm/scout_mvm_apexofjump05.mp3",
        "vo/mvm/norm/scout_mvm_autocappedcontrolpoint01.mp3",
        "vo/mvm/norm/scout_mvm_autocappedcontrolpoint02.mp3",
        "vo/mvm/norm/scout_mvm_autocappedcontrolpoint03.mp3",
        "vo/mvm/norm/scout_mvm_autocappedcontrolpoint04.mp3",
        "vo/mvm/norm/scout_mvm_autocappedintelligence01.mp3",
        "vo/mvm/norm/scout_mvm_autocappedintelligence02.mp3",
        "vo/mvm/norm/scout_mvm_autocappedintelligence03.mp3",
        "vo/mvm/norm/scout_mvm_award01.mp3",
        "vo/mvm/norm/scout_mvm_award02.mp3",
        "vo/mvm/norm/scout_mvm_award03.mp3",
        "vo/mvm/norm/scout_mvm_award04.mp3",
        "vo/mvm/norm/scout_mvm_award05.mp3",
        "vo/mvm/norm/scout_mvm_award06.mp3",
        "vo/mvm/norm/scout_mvm_award07.mp3",
        "vo/mvm/norm/scout_mvm_award08.mp3",
        "vo/mvm/norm/scout_mvm_award09.mp3",
        "vo/mvm/norm/scout_mvm_award10.mp3",
        "vo/mvm/norm/scout_mvm_award11.mp3",
        "vo/mvm/norm/scout_mvm_award12.mp3",
        "vo/mvm/norm/scout_mvm_battlecry01.mp3",
        "vo/mvm/norm/scout_mvm_battlecry02.mp3",
        "vo/mvm/norm/scout_mvm_battlecry03.mp3",
        "vo/mvm/norm/scout_mvm_battlecry04.mp3",
        "vo/mvm/norm/scout_mvm_battlecry05.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible01.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible02.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible03.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible04.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible05.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible06.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible07.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible08.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible09.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible10.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible11.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible12.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible13.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible14.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible15.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible16.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible17.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible18.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible19.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible20.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible21.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible22.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible23.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible24.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible25.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible26.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible27.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible28.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible29.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible30.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible31.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible32.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible33.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible34.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible35.mp3",
        "vo/mvm/norm/scout_mvm_beingshotinvincible36.mp3",
        "vo/mvm/norm/scout_mvm_cartgoingbackdefense03.mp3",
        "vo/mvm/norm/scout_mvm_cartgoingbackdefense04.mp3",
        "vo/mvm/norm/scout_mvm_cartmovingforwardoffense06.mp3",
        "vo/mvm/norm/scout_mvm_cheers01.mp3",
        "vo/mvm/norm/scout_mvm_cheers02.mp3",
        "vo/mvm/norm/scout_mvm_cheers03.mp3",
        "vo/mvm/norm/scout_mvm_cheers04.mp3",
        "vo/mvm/norm/scout_mvm_cheers05.mp3",
        "vo/mvm/norm/scout_mvm_cheers06.mp3",
        "vo/mvm/norm/scout_mvm_domination01.mp3",
        "vo/mvm/norm/scout_mvm_domination02.mp3",
        "vo/mvm/norm/scout_mvm_domination03.mp3",
        "vo/mvm/norm/scout_mvm_domination04.mp3",
        "vo/mvm/norm/scout_mvm_domination05.mp3",
        "vo/mvm/norm/scout_mvm_domination06.mp3",
        "vo/mvm/norm/scout_mvm_domination07.mp3",
        "vo/mvm/norm/scout_mvm_domination08.mp3",
        "vo/mvm/norm/scout_mvm_domination09.mp3",
        "vo/mvm/norm/scout_mvm_domination10.mp3",
        "vo/mvm/norm/scout_mvm_domination11.mp3",
        "vo/mvm/norm/scout_mvm_domination12.mp3",
        "vo/mvm/norm/scout_mvm_domination13.mp3",
        "vo/mvm/norm/scout_mvm_domination14.mp3",
        "vo/mvm/norm/scout_mvm_domination15.mp3",
        "vo/mvm/norm/scout_mvm_domination16.mp3",
        "vo/mvm/norm/scout_mvm_domination17.mp3",
        "vo/mvm/norm/scout_mvm_domination18.mp3",
        "vo/mvm/norm/scout_mvm_domination19.mp3",
        "vo/mvm/norm/scout_mvm_domination20.mp3",
        "vo/mvm/norm/scout_mvm_domination21.mp3",
        "vo/mvm/norm/scout_mvm_dominationdem01.mp3",
        "vo/mvm/norm/scout_mvm_dominationdem02.mp3",
        "vo/mvm/norm/scout_mvm_dominationdem03.mp3",
        "vo/mvm/norm/scout_mvm_dominationdem04.mp3",
        "vo/mvm/norm/scout_mvm_dominationdem05.mp3",
        "vo/mvm/norm/scout_mvm_dominationeng01.mp3",
        "vo/mvm/norm/scout_mvm_dominationeng02.mp3",
        "vo/mvm/norm/scout_mvm_dominationeng03.mp3",
        "vo/mvm/norm/scout_mvm_dominationeng04.mp3",
        "vo/mvm/norm/scout_mvm_dominationeng05.mp3",
        "vo/mvm/norm/scout_mvm_dominationeng06.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy01.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy02.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy03.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy04.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy05.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy06.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy07.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy08.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy09.mp3",
        "vo/mvm/norm/scout_mvm_dominationhvy10.mp3",
        "vo/mvm/norm/scout_mvm_dominationmed04.mp3",
        "vo/mvm/norm/scout_mvm_dominationmed05.mp3",
        "vo/mvm/norm/scout_mvm_dominationpyr02.mp3",
        "vo/mvm/norm/scout_mvm_dominationpyr03.mp3",
        "vo/mvm/norm/scout_mvm_dominationpyr04.mp3",
        "vo/mvm/norm/scout_mvm_dominationpyr06.mp3",
        "vo/mvm/norm/scout_mvm_dominationsct01.mp3",
        "vo/mvm/norm/scout_mvm_dominationsct02.mp3",
        "vo/mvm/norm/scout_mvm_dominationsnp05.mp3",
        "vo/mvm/norm/scout_mvm_dominationsol01.mp3",
        "vo/mvm/norm/scout_mvm_dominationsol02.mp3",
        "vo/mvm/norm/scout_mvm_dominationsol03.mp3",
        "vo/mvm/norm/scout_mvm_dominationsol04.mp3",
        "vo/mvm/norm/scout_mvm_dominationsol06.mp3",
        "vo/mvm/norm/scout_mvm_dominationspy04.mp3",
        "vo/mvm/norm/scout_mvm_generic01.mp3",
        "vo/mvm/norm/scout_mvm_go01.mp3",
        "vo/mvm/norm/scout_mvm_go02.mp3",
        "vo/mvm/norm/scout_mvm_go03.mp3",
        "vo/mvm/norm/scout_mvm_go04.mp3",
        "vo/mvm/norm/scout_mvm_goodjob01.mp3",
        "vo/mvm/norm/scout_mvm_goodjob02.mp3",
        "vo/mvm/norm/scout_mvm_goodjob03.mp3",
        "vo/mvm/norm/scout_mvm_goodjob04.mp3",
        "vo/mvm/norm/scout_mvm_invincible01.mp3",
        "vo/mvm/norm/scout_mvm_invincible02.mp3",
        "vo/mvm/norm/scout_mvm_invincible03.mp3",
        "vo/mvm/norm/scout_mvm_invincible04.mp3",
        "vo/mvm/norm/scout_mvm_invinciblechgunderfire01.mp3",
        "vo/mvm/norm/scout_mvm_invinciblechgunderfire02.mp3",
        "vo/mvm/norm/scout_mvm_invinciblechgunderfire03.mp3",
        "vo/mvm/norm/scout_mvm_invinciblechgunderfire04.mp3",
        "vo/mvm/norm/scout_mvm_jeers02.mp3",
        "vo/mvm/norm/scout_mvm_jeers07.mp3",
        "vo/mvm/norm/scout_mvm_laughevil01.mp3",
        "vo/mvm/norm/scout_mvm_laughevil02.mp3",
        "vo/mvm/norm/scout_mvm_laughevil03.mp3",
        "vo/mvm/norm/scout_mvm_laughhappy01.mp3",
        "vo/mvm/norm/scout_mvm_laughhappy02.mp3",
        "vo/mvm/norm/scout_mvm_laughhappy03.mp3",
        "vo/mvm/norm/scout_mvm_laughhappy04.mp3",
        "vo/mvm/norm/scout_mvm_laughlong01.mp3",
        "vo/mvm/norm/scout_mvm_laughlong02.mp3",
        "vo/mvm/norm/scout_mvm_laughshort01.mp3",
        "vo/mvm/norm/scout_mvm_laughshort02.mp3",
        "vo/mvm/norm/scout_mvm_laughshort03.mp3",
        "vo/mvm/norm/scout_mvm_laughshort04.mp3",
        "vo/mvm/norm/scout_mvm_laughshort05.mp3",
        "vo/mvm/norm/scout_mvm_meleedare01.mp3",
        "vo/mvm/norm/scout_mvm_meleedare02.mp3",
        "vo/mvm/norm/scout_mvm_meleedare03.mp3",
        "vo/mvm/norm/scout_mvm_meleedare04.mp3",
        "vo/mvm/norm/scout_mvm_meleedare05.mp3",
        "vo/mvm/norm/scout_mvm_meleedare06.mp3",
        "vo/mvm/norm/scout_mvm_misc02.mp3",
        "vo/mvm/norm/scout_mvm_misc03.mp3",
        "vo/mvm/norm/scout_mvm_misc04.mp3",
        "vo/mvm/norm/scout_mvm_misc05.mp3",
        "vo/mvm/norm/scout_mvm_misc06.mp3",
        "vo/mvm/norm/scout_mvm_misc07.mp3",
        "vo/mvm/norm/scout_mvm_misc08.mp3",
        "vo/mvm/norm/scout_mvm_misc09.mp3",
        "vo/mvm/norm/scout_mvm_positivevocalization01.mp3",
        "vo/mvm/norm/scout_mvm_positivevocalization02.mp3",
        "vo/mvm/norm/scout_mvm_positivevocalization03.mp3",
        "vo/mvm/norm/scout_mvm_positivevocalization04.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted01.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted02.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted03.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted04.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted05.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted06.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted07.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted08.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted09.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted10.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted11.mp3",
        "vo/mvm/norm/scout_mvm_specialcompleted12.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit01.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit02.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit03.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit04.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit05.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit06.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit07.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit08.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit09.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit10.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit11.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit12.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit13.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit14.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit15.mp3",
        "vo/mvm/norm/scout_mvm_stunballhit16.mp3",
        "vo/mvm/norm/scout_mvm_stunballhittingit01.mp3",
        "vo/mvm/norm/scout_mvm_stunballhittingit02.mp3",
        "vo/mvm/norm/scout_mvm_stunballhittingit04.mp3",
        "vo/mvm/norm/scout_mvm_stunballhittingit05.mp3",
        "vo/mvm/norm/scout_mvm_stunballpickup05.mp3",
        "vo/mvm/norm/scout_mvm_thanksfortheheal01.mp3",
        "vo/mvm/norm/scout_mvm_triplejump01.mp3",
        "vo/mvm/norm/scout_mvm_triplejump02.mp3",
        "vo/mvm/norm/scout_mvm_triplejump03.mp3",
        "vo/mvm/norm/scout_mvm_triplejump04.mp3",
        "vo/mvm/norm/scout_mvm_yes01.mp3",
        "vo/mvm/norm/scout_mvm_yes02.mp3",
        "vo/mvm/norm/scout_mvm_yes03.mp3"
    )
    
    DS = array(
        "vo/mvm/norm/scout_mvm_paincrticialdeath01.mp3",
        "vo/mvm/norm/scout_mvm_paincrticialdeath02.mp3",
        "vo/mvm/norm/scout_mvm_paincrticialdeath03.mp3",
        "vo/mvm/norm/scout_mvm_painsevere01.mp3",
        "vo/mvm/norm/scout_mvm_painsevere02.mp3",
        "vo/mvm/norm/scout_mvm_painsevere03.mp3",
        "vo/mvm/norm/scout_mvm_painsevere04.mp3",
        "vo/mvm/norm/scout_mvm_painsevere05.mp3",
        "vo/mvm/norm/scout_mvm_painsevere06.mp3",
        "vo/mvm/norm/scout_mvm_painsharp01.mp3",
        "vo/mvm/norm/scout_mvm_painsharp02.mp3",
        "vo/mvm/norm/scout_mvm_painsharp03.mp3",
        "vo/mvm/norm/scout_mvm_painsharp04.mp3",
        "vo/mvm/norm/scout_mvm_painsharp05.mp3",
        "vo/mvm/norm/scout_mvm_painsharp06.mp3",
        "vo/mvm/norm/scout_mvm_painsharp07.mp3",
        "vo/mvm/norm/scout_mvm_painsharp08.mp3"
    )
    
    timer("snd",random(5000,20000))
    
    timer("rdy",200)
    
    rangerFilter(players())
    rangerPersist(1)
}

if(clk("rdy"))
{
    stoptimer("rdy")
    Rdy = 1
}

if(clk("snd"))
{
    stoptimer("snd")
    local N = random(5,20)
    timer("snd",N*1000)
    
    soundPlay("snd",15,S[randint(1,S:count()),string])
}

if(Rdy)
{
    if(Ded)
    {
        if(changed(Ded))
        {
            holoSkin(1,holoEntity(1):getSkin()==0 ? 2 : 3)
            
            stoptimer("snd")
            
            soundStop("idle")
            soundStop("snd")
            soundPlay("ded",2,DS[randint(1,DS:count()),string])
            
            timer("expl",5000)
        }
        
        if(clk("expl"))
        {
            stoptimer("expl")
            
            propSpawn("models/props_phx/ww2bomb.mdl",E:pos(),1):propBreak()
            
            selfDestruct()
        }
    }else
    {
        local JR = rangerOffset(150,E:pos()-vec(0,0,20),E:forward():setZ(0):normalized())
        local RD = rangerOffset(40,E:pos(),vec(0,0,-1))
        if(changed(JR:hit())&JR:hit())
        {
            applyForce(vec(0,0,400)*E:mass())
        }
        elseif(RD:hit())
        {
            E:goto(RD:pos()+vec(0,0,40)+V)
            E:angTo((T:pos()-E:pos()):toAngle():setPitch(0))
        }
        
        W = (E:pos():distance(T:pos())>150) * T:isValid()
        
        V = E:forward()*W*20
        
        local LA = ang(45,360,45)
        Ded = !inrange(E:angles(),-LA,LA)
    }
}

if(changed(W) & !Ded)
{
    holoAnim(1,W ? "RUN_MELEE" : "STAND_MELEE")
    holoSetPose(1,"move_scale",W)
    holoSetPose(1,"move_x",W)
}
