@name Ragdolls to Zombies4
@inputs Button
@persist Base:vector Delay Target:entity
interval(10)
# I ONLY made it so that it tracks the nearest guy
#i did NOT make the whole thing
findByClass("player")
Target = (findClosest(entity():pos()))
E = entity():isWeldedTo()
OPos = Target:shootPos()
E:setMass(100)

#Sets up parts we're gonna use
RH = E:bone(7) #Right hand
LH = E:bone(5) #Left hand
Head = E:bone(10)
LF = E:bone(13) #Left foot
RF = E:bone(14) #Right Foot
if(Button == 1) {
    if(E:pos():distance(OPos) > 2000) {
        LH:applyForce(vec(0,0,0))
        RH:applyForce(vec(0,0,0))
        LF:applyForce(-Base)
        RF:applyForce(-Base)
        Head:applyForce(Base*10)
    }
    else{
        if ((E:pos():distance(OPos) < 100) & !Delay) {
           soundPurge()
           timer("delay",750)
           Force = 10^9
           soundPlay(0,100,"npc/zombie/zo_attack2.wav")
           E:applyForce(Force * (OPos - E:pos()))
           Delay = 1
        } else {
           Force = 3
           E:applyForce(E:vel() * -7)
        }
        
        if (clk("delay")) {Delay = 0}
    
    #Extends teh arms
        RH:applyForce(Force*(OPos - RH:pos()))
        LH:applyForce(Force*(OPos - LH:pos()))
    
    #To make it stand up, I pushed the feet down and the head up.
        Base = vec(0,0,150)
        LF:applyForce(-Base)
        RF:applyForce(-Base)
        Head:applyForce(Base*10)
    }
}
else{
}

