@name Thomas the Dank Engine
@persist N Ntpl Cwrk NP IKLL Rolling GRD WR Time Trip
@persist [A1 A2 AA RA]:angle
@persist [MV]:vector
@persist [E P CE M]:entity
@persist C:wirelink
@persist F:table FI FP NW1 NW2 Urg [FA Ar1 Ar2 Ar3 Ar4 Ar5 Ar6]:array FRa FOf:vector Dst Rd
@persist [P2H_Mod P2H_Color P2H_Mat P2H_Pos P2H_Ang]:array P2H_Int P2H_Offset P2H_Ready
@model models/sprops/cuboids/height48/size_1/cube_48x120x48.mdl

interval(50)

if(first() | duped() | dupefinished())
{
    
    luaRunAll("

    sound.PlayURL('https://www.dropbox.com/s/fbsywpnbzrygzcd/Thomas%20the%20Tank%20Engine%E2%84%A2-%20The%20Fresh%20Prince%20of%20Bel-Air%20%28Remix%29%20%28V2%29.mp3?dl=1', '3d', function(st)
        if(IsValid(st)) then
            st:SetPos(Entity(" + owner():id() + "):GetPos())
        end
    end)

    ")
    
    function number cosine(A, B, C)
    {
        return acos((A^2 + B^2 - C^2) / (2*A*B))
    }
    
    function ik(L1,L2,Hip:entity,Foot:vector,Chassis:entity,I1,I2)
    {    
        local Axis = Chassis:toLocalAxis(Foot - Hip:pos())
        local Angle = Axis:toAngle():setRoll(-bearing(Hip:pos(), Chassis:angles(), Foot))
        local Dist = min(Axis:length(), L1 + L2)
        local Quat = quat(Angle) * qRotation(vec(0,90 + cosine(Dist, L1, L2),0))
        
        holoAng(I1, Chassis:toWorld(Quat:toAngle()))
        holoAng(I2, Hip:toWorld(ang(cosine(L2, L1, Dist) + 180, 0, 0)))
    }
    
    function vector bezierNEW(Src:vector,End:vector,CurvePoint:vector,Progress:number)
    {
        local NP = clamp(Progress, 0, 1)
        return mix(mix(Src,CurvePoint,NP),mix(CurvePoint,End,NP),NP)
    }
    
    Ntpl = 50 / (500 / 33)
    
    E = entity()
    E:setMass(10000)
    E:setColor(0,0,0,0)
    E:propFreeze(0)
    E:soundPlay("idl", 0, "mvm/giant_heavy/giant_heavy_loop.wav")
    soundVolume("idl", 0.25)
    
    Rd = 99
    
    IKLL = 35
    
    holoCreate(61, E:toWorld(vec(-24, 0, 0)), vec(), E:toWorld(ang(0, -90, 0)))
    holoParent(61, E)
    
    local R = 24
    for(I = 1, 6)
    {
        local J = ceil(I / 2)
        
        #Hip
        holoCreate(I, holoEntity(61):toWorld(vec((R * !(I % 2) * 2)-R, (R * 4) - (R * J * 2), -24)), vec())
        holoParent(I, E)
        
        #Feet Rangers
        local NR = R * 1.25
        holoCreate(6 + I, holoEntity(61):toWorld(vec((NR * !(I % 2) * 2)-NR, (NR * 4) - (NR * J * 2), -24)), vec())
        holoParent(6 + I, E)
        
        #Feet
        local HP = rangerOffset(Rd, holoEntity(6 + I):pos(), -E:up()):pos()
        holoCreate(12 + I, HP, vec(1))
        holoAlpha(12 + I, 0)
        
        #Knee
        holoCreate(18 + I, holoEntity(I):toWorld(vec(0, 0, IKLL)), vec(0.5), holoEntity(I):toWorld(ang()))
        holoAlpha(18 + I, 0)
        holoParent(18 + I, I)
        
        #Aesthetic Feet
        holoCreate(24 + I, holoEntity(18 + I):toWorld(vec(0, 3 * (!(I % 2) * 2 - 1), IKLL)), vec(0.5), holoEntity(I):toWorld(ang(0, (180 * !(I % 2)), 0)))
        holoColor(24 + I, vec(0, 161, 255))
        holoModel(24 + I, "models/sprops/trans/train/single_48.mdl")
        holoDisableShading(24 + I, 1)
        holoParent(24 + I, 18 + I)
        
        #Aesthetic Thigh
        holoCreate(30 + I, holoEntity(I):toWorld(vec(0, 0, IKLL / 2)), vec(0.4, 0.4, IKLL / 12), holoEntity(I):toWorld(ang()))
        holoModel(30 + I, "hq_cylinder")
        holoColor(30 + I, vec(100))
        holoDisableShading(30 + I, 1)
        holoParent(30 + I, I)
        
        #Aesthetic Shin
        holoCreate(36 + I, holoEntity(18 + I):toWorld(vec(0, 0, IKLL / 2)), vec(0.4, 0.4, IKLL / 12), holoEntity(I):toWorld(ang()))
        holoModel(36 + I, "hq_cylinder")
        holoColor(36 + I, vec(100))
        holoDisableShading(36 + I, 1)
        holoParent(36 + I, 18 + I)
        
        #Aesthetic Knee
        holoCreate(42 + I, holoEntity(18 + I):pos(), vec(0.5), holoEntity(18 + I):toWorld(ang(0, 0, 90)))
        holoModel(42 + I, "hq_cylinder")
        holoColor(42 + I, vec(80))
        holoDisableShading(42 + I, 1)
        holoParent(42 + I, 18 + I)
        
        #Aesthetic Feet 2
        holoCreate(48 + I, holoEntity(18 + I):toWorld(vec(0, 0, IKLL)), vec(0.5), holoEntity(24 + I):toWorld(ang(0, 0, 90)))
        holoModel(48 + I, "hq_cylinder")
        holoColor(48 + I, vec(80))
        holoDisableShading(48 + I, 1)
        holoParent(48 + I, 24 + I)
        
        #Aesthetic Hip
        holoCreate(54 + I, holoEntity(I):pos(), vec(0.5), holoEntity(I):toWorld(ang(0, 0, 90)))
        holoModel(54 + I, "hq_cylinder")
        holoColor(54 + I, vec(80))
        holoDisableShading(54 + I, 1)
        holoParent(54 + I, I)
    }
    
    holoColor(1, vec(255, 100, 0))
    holoColor(6, vec(0, 127.5, 255))
    holoColor(13, vec(255, 100, 0))
    holoColor(18, vec(0, 127.5, 255))
    
    #Rangers
    Ar1[1,vector] = holoEntity(13):pos()
    Ar1[2,vector] = holoEntity(13):pos()
    Ar1[3,vector] = holoEntity(13):pos()
    
    Ar2[1,vector] = holoEntity(14):pos()
    Ar2[2,vector] = holoEntity(14):pos()
    Ar2[3,vector] = holoEntity(14):pos()
    
    Ar3[1,vector] = holoEntity(15):pos()
    Ar3[2,vector] = holoEntity(15):pos()
    Ar3[3,vector] = holoEntity(15):pos()
    
    Ar4[1,vector] = holoEntity(16):pos()
    Ar4[2,vector] = holoEntity(16):pos()
    Ar4[3,vector] = holoEntity(16):pos()
    
    Ar5[1,vector] = holoEntity(17):pos()
    Ar5[2,vector] = holoEntity(17):pos()
    Ar5[3,vector] = holoEntity(17):pos()
    
    Ar6[1,vector] = holoEntity(18):pos()
    Ar6[2,vector] = holoEntity(18):pos()
    Ar6[3,vector] = holoEntity(18):pos()
    
    rangerHitWater(1)
    rangerPersist(1)
    
    P2H_Int = 0
    P2H_Offset = 61
    P2H_Mod = array("models/sprops/cuboids/height06/size_8/cube_48x144x6.mdl","models/sprops/cuboids/height06/size_3/cube_18x48x6.mdl","models/sprops/cuboids/height06/size_1/cube_6x48x6.mdl","models/sprops/rectangles/size_5/rect_48x48x3.mdl","models/sprops/rectangles/size_3/rect_24x84x3.mdl","models/sprops/cuboids/height06/size_2/cube_12x48x6.mdl","models/sprops/misc/pyramids/rsize_4/rpyr_48x6.mdl","models/sprops/rectangles/size_5/rect_48x48x3.mdl","models/sprops/rectangles/size_5/rect_48x48x3.mdl","models/sprops/cuboids/height06/size_8/cube_48x144x6.mdl","models/sprops/rectangles/size_5/rect_48x48x3.mdl","models/sprops/geometry/qdisc_48.mdl","models/sprops/geometry/qdisc_48.mdl","models/sprops/cylinders/size_2/cylinder_3x18.mdl","models/sprops/geometry/sphere_3.mdl","models/sprops/rectangles/size_3/rect_24x48x3.mdl","models/sprops/geometry/fdisc_48.mdl","models/sprops/geometry/hring_18.mdl","models/sprops/geometry/fdisc_12.mdl","models/sprops/cylinders/size_3/cylinder_6x3.mdl","models/sprops/cylinders/size_3/cylinder_6x3.mdl","models/sprops/geometry/fdisc_12.mdl","models/sprops/rectangles/size_3/rect_24x84x3.mdl","models/sprops/misc/tubes/size_4/tube_48x84.mdl","models/sprops/trans/air/pcone_5b_m.mdl","models/sprops/misc/tubes_thin/size_1/t_tube_12x30.mdl")
    P2H_Color = array(vec4(255,0,0,255),vec4(255,255,255,255),vec4(255,0,0,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,0,0,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(165,225,163,255),vec4(147,176,90,255),vec4(0,161,255,255),vec4(182,182,182,255),vec4(0,0,0,255),vec4(255,255,255,255),vec4(0,0,0,255),vec4(0,0,0,255),vec4(255,255,255,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,161,255,255),vec4(0,0,0,255))
    P2H_Color[19,vector4] = vec4(255, 180, 180, 255)
    P2H_Color[22,vector4] = vec4(255, 180, 180, 255)
    P2H_Mat = array("models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite")
    P2H_Pos = array(vec(0,0,3),vec(0.0309,72.0068,3.0185),vec(0.0306,-71.9932,3.0196),vec(22.5307,-50.9935,36.0186),vec(22.5308,15.0066,24.0185),vec(0.0306,-68.9931,9.0196),vec(0.0307,-50.9934,60.0186),vec(-22.4693,-50.9934,36.0186),vec(0.0307,-28.4936,36.0186),vec(0.0308,9.0068,9.0195),vec(0.0307,-50.9934,58.5186),vec(22.5309,69.0068,24.0185),vec(-22.4691,69.0069,24.0185),vec(-6.6466,64.3555,23.0966),vec(-10.2731,72.222,20.6532),vec(0.0309,55.5071,24.0185),vec(0.0309,58.5068,36.0185),vec(0.0309,59.2568,25.5185),vec(-8.9691,59.2568,42.0185),vec(-8.9691,60.0068,42.0185),vec(9.0309,60.0068,42.0185),vec(9.0309,59.2568,42.0185),vec(-22.4692,15.0067,24.0185),vec(0.0308,15.0066,36.0185),vec(0.0307,-17.9936,56.0196),vec(0.0308,9.0067,72.0185))
    P2H_Ang = array(ang(-0.0001,-90.0001,0.0001),ang(0,179.9999,0.0001),ang(0,-0.0002,-0.0001),ang(89.9999,179.9998,0),ang(-0.0001,-90.0001,90),ang(0,179.9999,0.0001),ang(0,179.9999,0.0001),ang(89.9999,-0.0001,0),ang(0,179.9999,90.0001),ang(-0.0001,-90.0001,0),ang(0,179.9999,0.0001),ang(0.0001,89.9999,0),ang(0.0001,89.9999,0),ang(74.2499,-65.2502,179.9999),ang(0.0001,89.9999,0),ang(0,179.9999,-89.9986),ang(0,179.9999,0.0001),ang(0,-0.0001,179.9999),ang(0,179.9999,0.0001),ang(0,179.9999,90.0001),ang(0,179.9999,90.0001),ang(0,179.9999,0.0001),ang(-0.0001,-90.0001,90),ang(0,179.9999,0.0001),ang(0,179.9999,0.0001),ang(0,179.9999,90.0001))
    
    holoCreate(89, E:toWorld(vec(-15, 0, 60)), vec(1.1), E:toWorld(ang(0, 0, 90)))
    holoMaterial(89, "models/debug/debugwhite")
    holoColor(89, vec4(255, 60, 0, 0))
    holoDisableShading(89, 1)
    holoModel(89, "models/sprops/misc/tubes_thin/size_1/t_tube_12x6.mdl")
    holoParent(89, E)
}

if(!P2H_Ready)
{
    while(holoCanCreate() & perf() & P2H_Int < P2H_Mod:count())
    {
        P2H_Int++
        local P2H_TempInt = P2H_Int+P2H_Offset
        holoCreate(P2H_TempInt,holoEntity(61):toWorld(P2H_Pos[P2H_Int,vector] - vec(0, 0, 24)),vec(1),holoEntity(61):toWorld(P2H_Ang[P2H_Int,angle]))
        holoColor(P2H_TempInt,P2H_Color[P2H_Int,vector4])
        holoModel(P2H_TempInt,P2H_Mod[P2H_Int,string])
        holoMaterial(P2H_TempInt,P2H_Mat[P2H_Int,string])
        holoDisableShading(P2H_TempInt,1)
        holoParent(P2H_TempInt,holoEntity(61))
    }
    P2H_Ready = P2H_Int >= P2H_Mod:count()
}

if(P:isValid())
{
    Dri = P:driver()
    Act = P:driver():isValid()
    
    W = Dri:keyForward()
    A = Dri:keyLeft()
    S = Dri:keyBack()
    D = Dri:keyRight()
    Shi = Dri:keySprint()
    Spc = Dri:keyJump()
    R = Dri:keyReload()
    Alt = Dri:keyWalk()
    M1 = Dri:keyAttack1()
    M2 = Dri:keyAttack2()
    
    if(changed(Act))
    {
        C["Activated", number] = Act
        C["Position", vector] = E:toWorld(vec(0, 0, 100))
        C["Angle", angle] = Dri:eyeAngles()
        C["Parent", entity] = P
        C["Distance", number] = 200
    }
    
    if(Act)
    {
        Aim = P:toLocalAxis(Dri:eye()) 
        
        if(!Alt)
        {
            A1 = P:toLocal(Dri:eyeAngles())
            A2 = P:angles()
            if(abs($A2:forward():length() - $A1:forward():length()) < 5)
            {
                AA = (P:toLocal(Dri:eyeAngles())) * ang(0, 1, 0)
            }
        }
        
        if(M:isValid())
        {
            local MR = rangerOffset(100, M:pos(), M:forward())
            if(MR:hit() | clk("explode"))
            {
                stoptimer("explode")
                
                holoAlpha(89, 0)
                
                M:propBreak()
                
                C["Position", vector] = E:pos() + vec(0, 0, 100)
                C["Parent", entity] = P
            }else
            {
                holoAlpha(89, holoEntity(89):getAlpha() * 0.25)
                
                M:setPos(M:toWorld(vec(75, 0, 0)))
                M:setAng(M:toWorld(M:toLocal(Aim:toAngle()) / 3))
            }
        }else
        {
            if(changed(M1))
            {
                if(M1)
                {
                    Trip = 1
                    soundPlay("wind", 0, "ambient/gas/cannister_loop.wav")
                }elseif(Trip)
                {
                    M = propSpawn("models/props_phx/ww2bomb.mdl", E:toWorld(vec(-8, 0 ,55)), Aim:toAngle():setPitch(-80), 1)
                    M:setTrails(6, 150, 1, "trails/smoke", vec(255), 255)
                    M:setColor(0, 0, 0, 0)
                    
                    soundStop("wind")
                    soundPlay("shoot", 0.752, "ambient/machines/steam_release_1.wav")
                    
                    holoCreate(88, M:pos(), vec(1), M:toWorld(ang(90, 0, 0)))
                    holoModel(88, "models/props_phx/misc/potato.mdl")
                    holoParent(88, M)
                    
                    C["Position", vector] = M:pos()
                    C["Parent", entity] = M
                    
                    timer("explode", Time * 100)
                    
                    Time = 0
                    Trip = 0
                }
            }
            if(M1)
            {
                Time++
                soundPitch("wind", Time / 2)
                holoAlpha(89, min(255, Time / 2))
            }
        }
        
        if(changed(M2))
        {
            if(M2)
            {
                soundPlay("trainbells", 0, "ambient/alarms/train_crossing_bell_loop1.wav")
            }else
            {
               soundStop("trainbells")
            }
        }
    }
    
    local LM = vec(3 * (1 + (Shi * 15)), 1.5 * !Rolling,0)
    MV = clamp(MV + vec(W|S ? (W - S) : (-MV:x() * (0.5 + (Rolling * 0.45))), A|D ? (A - D) : (-MV:y() * (0.5 + (Rolling * 0.45))), 0), -LM, LM)
}elseif(changed(Act))
{
    stoptimer("explode")
    
    holoAlpha(89, 0)
    
    M:propBreak()
}

Rolling = (abs(E:velL():x()) > 80)  * !M:isValid()

Cs = cos(N * 10) * 1.5

if(changed(Rolling))
{
    GRD = Rolling ? 60 : 94 + Cs
    
    if(Rolling)
    {
        soundPlay("train", 0, "vehicles/junker/jnk_turbo_on_loop1.wav")
    }else
    {
        soundStop("train")
    }
}

if(Rolling)
{
    local EVLX = round(abs(E:velL():x()))
    if(changed(EVLX))
    {
        soundPitch("train", EVLX / 8)
    }
}

GR = rangerOffset(GRD + 16, E:pos(), vec(0, 0, -1))
local EV = E:vel() * Rolling * 0.05
RD1 = rangerOffset(Rd, holoEntity(7):pos() + EV, -E:up())
RD2 = rangerOffset(Rd, holoEntity(8):pos() + EV, -E:up())
RD3 = rangerOffset(Rd, holoEntity(9):pos() + EV, -E:up())
RD4 = rangerOffset(Rd, holoEntity(10):pos() + EV, -E:up())
RD5 = rangerOffset(Rd, holoEntity(11):pos() + EV, -E:up())
RD6 = rangerOffset(Rd, holoEntity(12):pos() + EV, -E:up())

if(changed(Rolling) | changed(GR:hit()))
{
    Ar1[1, vector] = RD1:pos()
    Ar1[2, vector] = RD1:pos()
    Ar1[3, vector] = RD1:pos()
    
    Ar2[1, vector] = RD2:pos()
    Ar2[2, vector] = RD2:pos()
    Ar2[3, vector] = RD2:pos()
    
    Ar3[1, vector] = RD3:pos()
    Ar3[2, vector] = RD3:pos()
    Ar3[3, vector] = RD3:pos()
    
    Ar4[1, vector] = RD4:pos()
    Ar4[2, vector] = RD4:pos()
    Ar4[3, vector] = RD4:pos()
    
    Ar5[1, vector] = RD5:pos()
    Ar5[2, vector] = RD5:pos()
    Ar5[3, vector] = RD5:pos()
    
    Ar6[1, vector] = RD6:pos()
    Ar6[2, vector] = RD6:pos()
    Ar6[3, vector] = RD6:pos()
    
    FI = 0
    FP = 0
    NW1 = 0
    NW2 = 0
}

if(GR:hit())
{
    applyForce(((E:toWorldAxis(MV):setZ(0) + vec(0, 0, (GR:pos():z() + GRD) - E:pos():z())) * 5 - E:toWorldAxis(E:velL() * vec(0.3, 0.4, 0.5))) * E:mass())
    
    if(Rolling)
    {
        if(Rolling)
        {
            local YN = (E:velL() * vec(1, 0, 0)):length() * clamp(E:velL():x(), -1, 1)
            RPT = (YN/66/2/pi()/15*360) * Ntpl
            WR += RPT
            holoAng(25, holoEntity(1):toWorld(ang(WR, 0 ,0)))
            holoAng(26, holoEntity(2):toWorld(ang(WR, 180 ,0)))
            holoAng(27, holoEntity(3):toWorld(ang(WR, 0 ,0)))
            holoAng(28, holoEntity(4):toWorld(ang(WR, 180 ,0)))
            holoAng(29, holoEntity(5):toWorld(ang(WR, 0 ,0)))
            holoAng(30, holoEntity(6):toWorld(ang(WR, 180 ,0)))
        }
    }else
    {
        EVL = E:vel():length() + (E:angVelVector():length() * 1.25)
        EVV = E:toWorldAxis(clamp(E:velL() * vec(0.5, 0.5, 0), -vec(50), vec(50)))
        if(FI)
        {
            if(NW1)
            {
                if(FP < 1)
                {
                    FP += FRa
                    
                    local FO = Ar1[1,vector]
                    local FN = Ar1[3,vector]
                    Ar1[2,vector] = bezierNEW(FN, FO, mix(FO, FN, 0.5) + FOf, FP)
                    
                    local FO = Ar4[1,vector]
                    local FN = Ar4[3,vector]
                    Ar4[2,vector] = bezierNEW(FN, FO, mix(FO, FN, 0.5) + FOf, FP)
                    
                    local FO = Ar5[1,vector]
                    local FN = Ar5[3,vector]
                    Ar5[2,vector] = bezierNEW(FN, FO, mix(FO, FN, 0.5) + FOf, FP)
                }else
                {
                    soundPlay("footstep1", 0.45, "physics/metal/metal_canister_impact_soft" + randint(1,3) + ".wav")
                    soundPlay("footstep2", 0.45, "physics/metal/metal_canister_impact_soft" + randint(1,3) + ".wav")
                    soundPlay("footstep3", 0.45, "physics/metal/metal_canister_impact_soft" + randint(1,3) + ".wav")
                    
                    Ar1[1,vector] = Ar1[3,vector]
                    
                    Ar4[1,vector] = Ar4[3,vector]
                    
                    Ar5[1,vector] = Ar5[3,vector]
                    
                    NW1 = 0
                    
                    FI = !FI
                }
            }else
            {
                local NtM = RD1:pos():distance(Ar1[1,vector]) > Dst | RD4:pos():distance(Ar4[1,vector]) > Dst | RD5:pos():distance(Ar5[1,vector]) > Dst
                
                if(NtM)
                {
                    if(changed(EVL))
                    {
                        Dst = (5 + (EVL/32))
                    }
                    
                    Ar1[1, vector] = holoEntity(13):pos()
                    Ar1[3, vector] = rangerOffset(Rd, holoEntity(7):pos() + EVV, -E:up()):pos()
                    
                    Ar4[1, vector] = holoEntity(16):pos()
                    Ar4[3, vector] = rangerOffset(Rd, holoEntity(10):pos() + EVV, -E:up()):pos()
                    
                    Ar5[1, vector] = holoEntity(17):pos()
                    Ar5[3, vector] = rangerOffset(Rd, holoEntity(11):pos() + EVV, -E:up()):pos()
                    
                    FP = 0
                    
                    Urg = EVL / 25
                    FRa = (0.125 + (Urg/40))
                    FOf = vec(0, 0, (Urg * 12))
                    
                    NW1 = 1
                }else
                {
                    FI = !FI
                }
            }
        }else
        {
            if(NW2)
            {
                if(FP < 1)
                {
                    FP += FRa
                    
                    local FO = Ar2[1,vector]
                    local FN = Ar2[3,vector]
                    Ar2[2,vector] = bezierNEW(FN, FO, mix(FO, FN, 0.5) + FOf, FP)
                    
                    local FO = Ar3[1,vector]
                    local FN = Ar3[3,vector]
                    Ar3[2,vector] = bezierNEW(FN, FO, mix(FO, FN, 0.5) + FOf, FP)
                    
                    local FO = Ar6[1,vector]
                    local FN = Ar6[3,vector]
                    Ar6[2,vector] = bezierNEW(FN, FO, mix(FO, FN, 0.5) + FOf, FP)
                }else
                {
                    soundPlay("footstep4", 0.45, "physics/metal/metal_canister_impact_soft" + randint(1,3) + ".wav")
                    soundPlay("footstep5", 0.45, "physics/metal/metal_canister_impact_soft" + randint(1,3) + ".wav")
                    soundPlay("footstep6", 0.45, "physics/metal/metal_canister_impact_soft" + randint(1,3) + ".wav")
                    
                    Ar2[1,vector] = Ar2[3,vector]
                    
                    Ar3[1,vector] = Ar3[3,vector]
                    
                    Ar6[1,vector] = Ar6[3,vector]
                    
                    NW2 = 0
                    
                    FI = !FI
                }
            }else
            {
                local NtM = RD2:pos():distance(Ar2[1,vector]) > Dst | RD3:pos():distance(Ar3[1,vector]) > Dst | RD6:pos():distance(Ar6[1,vector]) > Dst
                
                if(NtM)
                {
                    if(changed(EVL))
                    {
                        Dst = (5 + (EVL/32))
                    }
                    
                    Ar2[1, vector] = holoEntity(14):pos()
                    Ar2[3, vector] = rangerOffset(Rd, holoEntity(8):pos() + EVV, -E:up()):pos()
                    
                    Ar3[1, vector] = holoEntity(15):pos()
                    Ar3[3, vector] = rangerOffset(Rd, holoEntity(9):pos() + EVV, -E:up()):pos()
                    
                    Ar6[1, vector] = holoEntity(18):pos()
                    Ar6[3, vector] = rangerOffset(Rd, holoEntity(12):pos() + EVV, -E:up()):pos()
                    
                    FP = 0
                    
                    Urg = EVL / 25
                    FRa = (0.125 + (Urg/40))
                    FOf = vec(0, 0, (Urg * 12))
                    
                    NW2 = 1
                }else
                {
                    FI = !FI
                }
            }
        }
    }
}
Wobble = ang(-sin(FP * 180) * 2 * (NW1 | NW2), 0, sin(FP * 90) * 2 * (NW1 - NW2))
applyAngForce(((angnorm(Wobble + RA + (M:isValid() ? (M:pos() - E:pos()):toAngle():setPitch(0) : AA) - E:angles()) * ang(15, 1.75 * Act, 7)) - (E:angVel() * ang(3, 3, 1))) * E:mass() * Ntpl)

holoPos(13, mix(GR:hit() ? Rolling ? RD1:pos() : Ar1[2,vector] : holoEntity(7):toWorld(vec(0, 0, -40)), holoEntity(13):pos(), 0.75))
holoPos(14, mix(GR:hit() ? Rolling ? RD2:pos() : Ar2[2,vector] : holoEntity(8):toWorld(vec(0, 0, -40)), holoEntity(14):pos(), 0.75))
holoPos(15, mix(GR:hit() ? Rolling ? RD3:pos() : Ar3[2,vector] : holoEntity(9):toWorld(vec(0, 0, -40)), holoEntity(15):pos(), 0.75))
holoPos(16, mix(GR:hit() ? Rolling ? RD4:pos() : Ar4[2,vector] : holoEntity(10):toWorld(vec(0, 0, -40)), holoEntity(16):pos(), 0.75))
holoPos(17, mix(GR:hit() ? Rolling ? RD5:pos() : Ar5[2,vector] : holoEntity(11):toWorld(vec(0, 0, -40)), holoEntity(17):pos(), 0.75))
holoPos(18, mix(GR:hit() ? Rolling ? RD6:pos() : Ar6[2,vector] : holoEntity(12):toWorld(vec(0, 0, -40)), holoEntity(18):pos(), 0.75))

N++
if(!(N % 2))
{
    NP = numPlayers()
    if(changed(NP))
    {
        rangerFilter(array(E, P, CE):merge(players()))
    }
    
    if(P:isValid())
    {
        if(!CE:isValid())
        {
            findByClass("gmod_wire_cameracontroller")
            findSortByDistance(E:pos())
            if(find():pos():distance(E:pos()) < 500)
            {
                CE = find()
                CE:setPos(E:toWorld(vec(-42, 0, 40)))
                CE:setColor(0, 0, 0, 0)
                CE:setAng(E:angles())
                
                C = CE:wirelink()
                
                timer("cpnt",50)
            }
        }
    }else
    {
        findByClass("prop_vehicle_prisoner_pod")
        findSortByDistance(E:pos())
        if(find():pos():distance(E:pos()) < 500 & find():owner() == owner())
        {
            P = find()
            P:propNotSolid(1)
            P:setPos(E:toWorld(vec(-72, 0, 0)))
            P:setAng(E:toWorld(ang(0, -90, 0)))
            
            timer("ppnt",50)
        }
    }
    
    #IK
    ik(IKLL, IKLL, holoEntity(1), holoEntity(13):pos() + E:up() * 15, E, 1, 19)
    ik(IKLL, IKLL, holoEntity(2), holoEntity(14):pos() + E:up() * 15, E, 2, 20)
    ik(IKLL, IKLL, holoEntity(3), holoEntity(15):pos() + E:up() * 15, E, 3, 21)
    ik(IKLL, IKLL, holoEntity(4), holoEntity(16):pos() + E:up() * 15, E, 4, 22)
    ik(IKLL, IKLL, holoEntity(5), holoEntity(17):pos() + E:up() * 15, E, 5, 23)
    ik(IKLL, IKLL, holoEntity(6), holoEntity(18):pos() + E:up() * 15, E, 6, 24)
    
    RA = ang((((RD2:pos()+RD1:pos())/2)-((RD6:pos()+RD5:pos())/2)):toAngle():pitch(),0,(((RD2:pos()+RD6:pos()+RD4:pos())/3)-((RD1:pos()+RD5:position()+RD3:position())/3)):toAngle():pitch()) * (RD1:hit() & RD2:hit() & RD3:hit() & RD4:hit() & RD5:hit() & RD6:hit())
}

if(clk("ppnt"))
{
    stoptimer("ppnt")
    P:setPos(E:toWorld(vec(-90, 0, 0)))
    P:setAng(E:toWorld(ang(0, -90, 0)))
    P:parentTo(E)
    P:propNotSolid(0)
}

if(clk("cpnt"))
{
    stoptimer("cpnt")
    CE:parentTo(E)
}

