function init()
	Head = FindBody("Head")
	HeadBloodCapacity = GetBodyMass(Head)
	HeadBloodLevel = HeadBloodCapacity * 20
	StartingBleed = HeadBloodCapacity
	MaxBloodCapacity = GetBodyMass(Head)
	bleed = true

	Torso = FindBody("Torso")
	TorsoBloodCapacity = GetBodyMass(Torso)
	TorsoBloodLevel = TorsoBloodCapacity * 20
	StartingBleed1 = TorsoBloodCapacity
	MaxBloodCapacity1 = GetBodyMass(Torso)
	bleed1 = true

	LARM = FindBody("LARM")
	LARMBloodCapacity = GetBodyMass(LARM)
	LARMBloodLevel = LARMBloodCapacity * 20
	StartingBleed2 = LARMBloodCapacity
	MaxBloodCapacity2 = GetBodyMass(LARM)

	bleed2 = true

	LLARM = FindBody("LLARM")
	LLARMBloodCapacity = GetBodyMass(LLARM)
	LLARMBloodLevel = LLARMBloodCapacity * 20
	StartingBleed3 = LLARMBloodCapacity
	MaxBloodCapacity3 = GetBodyMass(LLARM)
	bleed3 = true

	RARM = FindBody("RARM")
	RARMBloodCapacity = GetBodyMass(RARM)
	RARMBloodLevel = RARMBloodCapacity * 20
	StartingBleed4 = RARMBloodCapacity
	MaxBloodCapacity4 = GetBodyMass(RARM)
	bleed4 = true

	RRARM = FindBody("RRARM")
	RRARMBloodCapacity = GetBodyMass(RRARM)
	RRARMBloodLevel = RRARMBloodCapacity * 20
	StartingBleed5 = RRARMBloodCapacity
	MaxBloodCapacity5 = GetBodyMass(RRARM)
	bleed5 = true

	LLEG = FindBody("LLEG")
	LLEGBloodCapacity = GetBodyMass(LLEG)
	LLEGBloodLevel = LLEGBloodCapacity * 20
	StartingBleed6 = LLEGBloodCapacity
	MaxBloodCapacity6 = GetBodyMass(LLEG)
	bleed6 = true

	LLLEG = FindBody("LLLEG")
	LLLEGBloodCapacity = GetBodyMass(LLLEG)
	LLLEGBloodLevel = LLLEGBloodCapacity * 20
	StartingBleed7 = LLLEGBloodCapacity
	MaxBloodCapacity7 = GetBodyMass(LLLEG)
	bleed7 = true

	RLEG = FindBody("RLEG")
	RLEGBloodCapacity = GetBodyMass(RLEG)
	RLEGBloodLevel = RLEGBloodCapacity * 20
	StartingBleed8 = RLEGBloodCapacity
	MaxBloodCapacity8 = GetBodyMass(RLEG)
	bleed8 = true

	RRLEG = FindBody("RRLEG")
	RRLEGBloodCapacity = GetBodyMass(RRLEG)
	RRLEGBloodLevel = RRLEGBloodCapacity * 20
	StartingBleed9 = RRLEGBloodCapacity
	MaxBloodCapacity9 = GetBodyMass(RRLEG)
	bleed9 = true

	antibleed = 15 -- only affects smoke speed
	extremeantibleed = 500000 -- affects extreme bleed which is caused by total organ failure, reduce for blood to explode more
	regularantibleed = 30000 -- affects cureable bleeds, reduce to have more blood in general
	limbantibleed = 30000 -- affects bleeding of limbs, decrease to have more blood from arms and legs
	MinBloodValue = 10000 -- minimum allowed blood value for human to stay alive

	LimbBleedSpeed = 0.1

	bloodgrav = -20
	blooddrag = 0
	startupspeed = Vec(0,0.7,0)
	upspeed = Vec(0,1,0)
	downspeed = Vec(0,-1.2,0)
	alive = true

	akm = FindBody("AKM")
	weight = 2000
	bias = Vec(0,0,0)
	biasb = Vec(0,0,0)
	weightb = -0.2
	agrotimer = 0
	forget = 10
	KillTimer = 0
	Eliminate = 1
	shootim = 0
	shots = 0
	reload = 0
	magsize = 95
	firerate = 1.5
	recoil = 2

	flare = FindLight("flare")
	flaretim = false
	flaretimer = 0
	SetLightEnabled(flare, false)
	spetsnaz = FindShape("spetsnaz",true)
	GunShot = LoadSound("MOD/gorescript/akm.ogg")
	enemyspotted = false
		switched = true
		enabled = true
		criticalcondition = false
		bloodtocriticalcondition = 25000
		disarmed = false

		deathsnd = {
        LoadSound("MOD/gorescript/snd/Team2/death1"),
        LoadSound("MOD/gorescript/snd/Team2/death2"),
        LoadSound("MOD/gorescript/snd/Team2/death3"),
        LoadSound("MOD/gorescript/snd/Team2/death4"),
        LoadSound("MOD/gorescript/snd/Team2/death5")
    	  }
    hurtsnd = {
        LoadSound("MOD/gorescript/snd/Team2/hurt1"),
        LoadSound("MOD/gorescript/snd/Team2/hurt2"),
        LoadSound("MOD/gorescript/snd/Team2/hurt3"),
        LoadSound("MOD/gorescript/snd/Team2/hurt4"),
        LoadSound("MOD/gorescript/snd/Team2/hurt5")
    	  }
   	enemye = {
        LoadSound("MOD/gorescript/snd/Team2/enemyspotted1"),
        LoadSound("MOD/gorescript/snd/Team2/enemyspotted2"),
        LoadSound("MOD/gorescript/snd/Team2/enemyspotted3"),
        LoadSound("MOD/gorescript/snd/Team2/enemyspotted4"),
        LoadSound("MOD/gorescript/snd/Team2/enemyspotted5")
    	  }

    enemydead = {
        LoadSound("MOD/gorescript/snd/Team2/enemydown1"),
        LoadSound("MOD/gorescript/snd/Team2/enemydown2"),
        LoadSound("MOD/gorescript/snd/Team2/enemydown3"),
        LoadSound("MOD/gorescript/snd/Team2/enemydown4"),
        LoadSound("MOD/gorescript/snd/Team2/enemydown5")
    	  }

    	  playtimer = 0

    	  DeathBreath = FindTrigger("DeathBreath")
    	   voiceenabled = true
    	  switchedvoice = true

end


function tick(dt)

	PlayVoice()

	if playing then
		playtimer = playtimer + dt
		if playtimer > 3 then
			playing = false
			playtimer = 0
			hurt = false
			enemylocated = false
			enemydown = false
		end
	end

	if InputPressed("H") then
		if switched then
			enabled = false
			switched = false
		else if not switched then
			enabled = true
		switched = true
		end
	end
end

if InputPressed("J") then
	if switchedvoice then
		voiceenabled = false
		switchedvoice = false
	else if not switchedvoice then
		voiceenabled = true
		switchedvoice = true
	end
end
end

	if IsShapeBroken(spetsnaz) then
		RemoveTag(spetsnaz,"spetsnaz")
		agro = false
		agrotimer = 0
		spetsnaz = FindShape("spetsnaz",true)
		enemyspotted = false
		shoot = false
		if canSeeSpetsnaz() then
			if not playing then
		enemydown = true
	end
end
	end

	if PlayerHP == 0 then
		shoot = false
		agro = false
		agrotimer = 0
		enemyspotted = false
	end
	gunTrans = GetBodyTransform(Head)
	gunPos = gunTrans.pos
	direction = TransformToParentVec(gunTrans, Vec(0, -1, 0))
	 shootPos = VecAdd(gunPos, VecScale(direction,0.2))

	drawtext = false

	HeadBloodCapacity = GetBodyMass(Head)
	Bleed = StartingBleed - HeadBloodCapacity
	HeadPos = GetBodyTransform(Head)

	TorsoBloodCapacity = GetBodyMass(Torso)
	Bleed1 = StartingBleed1 - TorsoBloodCapacity
	TorsoPos = GetBodyTransform(Torso)

	LARMBloodCapacity = GetBodyMass(LARM)
	Bleed2 = StartingBleed2 - LARMBloodCapacity
	LARMPos = GetBodyTransform(LARM)

	LLARMBloodCapacity = GetBodyMass(LLARM)
	Bleed3 = StartingBleed3 - LLARMBloodCapacity
	LLARMPos = GetBodyTransform(LLARM)

	RARMBloodCapacity = GetBodyMass(RARM)
	Bleed4 = StartingBleed4 - RARMBloodCapacity
	RARMPos = GetBodyTransform(RARM)

	RRARMBloodCapacity = GetBodyMass(RRARM)
	Bleed5 = StartingBleed5 - RRARMBloodCapacity
	RRARMPos = GetBodyTransform(RRARM)

	LLEGBloodCapacity = GetBodyMass(LLEG)
	Bleed6 = StartingBleed6 - LLEGBloodCapacity
	LLEGPos = GetBodyTransform(LLEG)

	LLLEGBloodCapacity = GetBodyMass(LLLEG)
	Bleed7 = StartingBleed7 - LLLEGBloodCapacity
	LLLEGPos = GetBodyTransform(LLLEG)

	RLEGBloodCapacity = GetBodyMass(RLEG)
	Bleed8 = StartingBleed8 - RLEGBloodCapacity
	RLEGPos = GetBodyTransform(RLEG)

	RRLEGBloodCapacity = GetBodyMass(RRLEG)
	Bleed9 = StartingBleed9 - RRLEGBloodCapacity
	RRLEGPos = GetBodyTransform(RRLEG)

	--AGRESSIVE BEHAVIOR

	if IsBodyBroken(LLARM) then
		disarmed = true
	end

	if canSeeSpetsnaz() then
			agro = true
		agrotimer = 0
		KillTimer = KillTimer + dt
		enemyspotted = true
		shoot = true

	end

	if canSeePlayer() then
		agro = true
		agrotimer = 0
		KillTimer = KillTimer + dt
		enemyspotted = true
		shoot = true
		end
		if agro then
			agrotimer = agrotimer + dt
		if agrotimer > forget then
		agro = false
		agrotimer = 0
		KillTimer = 0
	end
end

	--RELOAD
	if shots > magsize then
		reloading = true
		if alive then
		reload = reload + dt
		if reload > 4 then
			reloading = false
			shots = 0
			reload = 0
		end
	end
	end


	--ELIMINATE TARGET 
	local barrel = FindShape("barrel")
	local guntrans = GetShapeWorldTransform(barrel)
	local terrorist = FindShape("terrorist")
	terrorpos = GetShapeWorldTransform(terrorist)
	--DebugPrint("guny:  "..guntrans.pos[2])
	--DebugPrint("body:  "..terrorpos.pos[2])
    local gunpos = guntrans.pos
	local direction = TransformToParentVec(guntrans, Vec(0, -1, 0))
    local shootpos = VecAdd(gunpos, VecScale(direction, 0.2))

    if flaretim then
    	flaretimer = flaretimer + dt
    	if flaretimer > 0.1 then
    		SetLightEnabled(flare, false)
    		flaretimer = 0
    	end
    end
    if shoot then
	if KillTimer > Eliminate then
		if not disarmed then
		if not reloading then
		shootim = shootim + dt * firerate
		if shootim > 0.2 then
		Shoot(shootpos, direction)
		PlaySound(GunShot, shootpos,10)
		SetLightEnabled(flare, true)
		flaretim = true
		for i=1,33 do
		GunSmoke()
	end
		ApplyBodyImpulse(LLARM, Vec(0,0,0), Vec(math.random(-recoil,recoil),recoil,math.random(-recoil,recoil)))
		shootim = 0
		shots = shots + 1
	end
end
	end
end
end

	--AIM AIM AIM AIM AIM AIM AIM AIM AIM
	if enemyspotted then
	if not disarmed then
	if alive then
		if agro then
	local ppos = GetPlayerCameraTransform()
	ppos.pos[2] = ppos.pos[2] - 0.5
	spetsnazpos = GetShapeWorldTransform(spetsnaz)
	distToPlayeraim = VecLength(VecSub(ppos.pos, TorsoPos.pos))
	distToSpetsaim = VecLength(VecSub(spetsnazpos.pos, TorsoPos.pos))



	if distToPlayeraim > distToSpetsaim and canSeeSpetsnaz() then
	enemy = spetsnazpos.pos
else if distToPlayeraim > distToSpetsaim and not canSeeSpetsnaz() then
	enemy = ppos.pos
end
end
	if distToPlayeraim < distToSpetsaim and canSeePlayer() then
	enemy = ppos.pos
else if distToPlayeraim < distToSpetsaim and not canSeePlayer() then
	enemy = spetsnazpos.pos
end
	end



	local akmpos = GetBodyTransform(akm)

	local aimangle = QuatLookAt(akmpos.pos, enemy)

	local gunyaw, gunpitch, gunroll = GetQuatEuler(akmpos.rot)
	local aimyaw, aimpitch, aimroll = GetQuatEuler(aimangle)


--yaw
 gunyaw = gunyaw + math.min(math.max(aimyaw - gunyaw, -weight), weight)
  --pitch
 gunpitch = gunpitch + math.min(math.max(aimpitch - gunpitch, -weight), weight)
  --roll
 gunroll = gunroll + math.min(math.max(aimroll - gunroll, -weight), weight)
 if agro then

 local bias = QuatEuler(gunyaw, gunpitch, gunroll)
  SetBodyTransform(akm, Transform(akmpos.pos, bias))
end
end
end

--b = GetBodyTransform(LLARM)
  --for i=1,3 do
        --if(ppos.pos[i]<b.pos[i]) then
             --biasb[i] = -weightb
        --elseif(ppos.pos[i]>b.pos[i]) then
          --  biasb[i] = weightb
        --else
          --  biasb[i] = 0
        --end
    --end
    --local currentVelocity = GetBodyVelocity(LLARM)
    if alive then
    	if agro then
    local ppos = enemy
    local bmi, bma = GetBodyBounds(LLARM)
		local bc = VecLerp(bmi, bma, 0.5)
		local ppos = enemy
		local dir = VecSub(bc, ppos)
		local dist = VecLength(dir)
		dir = VecScale(dir, 1.0/dist)
    local add = VecScale(dir, weightb)
	local vel = GetBodyVelocity(LLARM)
	vel = VecAdd(vel, add)
    SetBodyVelocity(LLARM, vel)
local bmi, bma = GetBodyBounds(RRARM)
		local bc = VecLerp(bmi, bma, 0.5)
		local ppos = enemy
		local dir = VecSub(bc, ppos)
		local dist = VecLength(dir)
		dir = VecScale(dir, 1.0/dist)
    local add = VecScale(dir, weightb)
	local vel = GetBodyVelocity(RRARM)
	vel = VecAdd(vel, add)
    SetBodyVelocity(RRARM, vel)
end
end
end
end
  --akmpos.rot = Rot
  --SetBodyTransform(akm, akmpos)

--HEAD HEAD HEAD HEAD HEAD HEAD HEAD HEAD HEAD HEAD
	if bleed then
	if IsBodyBroken(Head) then

		for i=1, 9 do
		 	 thingz = FindJoints("eye")
		 	 for i=1, #thingz do
		 	 	thinz = thingz[i]
		 	 	Delete(thinz)
		 	 end
		 end

		for i=1,Bleed/2 do
		smoke()
	end
end
end

if bleed then
	
		if HeadBloodCapacity < MaxBloodCapacity then
		Bleed = Bleed * 6 
		for i=1,Bleed/6 do
		smoke()
	end
	end

HeadBloodLevel = HeadBloodLevel - Bleed/2
end

	if HeadBloodLevel <= 0 then
		bleed = false
		HeadBloodLevel = 0
	end

	--TORSO TORSO TORSO TORSO TORSO TORSO TORSO

	if bleed1 then
	if IsBodyBroken(Torso) then
		for i=1,Bleed1/regularantibleed do
		smoke1()
	end
end
end

if bleed1 then

		if TorsoBloodCapacity < MaxBloodCapacity1/2 then
		Bleed1 = Bleed1 * 6 
		 for i=1, 9 do
		 	 things = FindBodies("gut", true)
		 	 for i=1, #things do
		 	 	thing = things[i]
		 	 	SetBodyDynamic(thing, true)
		 	 end
		 end
		for i=1,Bleed1/extremeantibleed do
		smoke1()
	end
	end

TorsoBloodLevel = TorsoBloodLevel - Bleed1
end

	if TorsoBloodLevel <= 0 then
		bleed1 = false
		TorsoBloodLevel = 0
	end

-- ARMARMARMARMAMRAMRMARMAMRAMRMARMAMRAMMARMAMAMRMARMMRMARMRMAMRMAR

if bleed2 then

	if LARMBloodCapacity < MaxBloodCapacity2/3 then
		Bleed2 = Bleed2 * 6 
		for i=1,Bleed2/extremeantibleed do
		smoke2()
	end
	end

	if IsBodyBroken(LARM) then
		for i=1,Bleed2/limbantibleed do
		smoke2()
	end
end
end

if bleed2 then
LARMBloodLevel = LARMBloodLevel - Bleed2*LimbBleedSpeed
end

	if LARMBloodLevel <= 0 then
		bleed2 = false
		LARMBloodLevel = 0
	end

	--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

if bleed3 then

	if LLARMBloodCapacity < MaxBloodCapacity3/3 then
		Bleed3 = Bleed3 * 6 
		for i=1,Bleed3/extremeantibleed do
		smoke3()
	end
	end

	if IsBodyBroken(LLARM) then
		for i=1,Bleed3/limbantibleed do
		smoke3()
	end
end
end

if bleed3 then
LLARMBloodLevel = LLARMBloodLevel - Bleed3*LimbBleedSpeed
end

	if LLARMBloodLevel <= 0 then
		bleed3 = false
		LLARMBloodLevel = 0
	end

	--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

	if bleed4 then

		if RARMBloodCapacity < MaxBloodCapacity4/3 then
		Bleed4 = Bleed4 * 6 
		for i=1,Bleed4/extremeantibleed do
		smoke4()
	end
	end

	if IsBodyBroken(RARM) then
		for i=1,Bleed4/limbantibleed do
		smoke4()
	end
end
end

if bleed4 then
RARMBloodLevel = RARMBloodLevel - Bleed4*LimbBleedSpeed
end

	if RARMBloodLevel <= 0 then
		bleed4 = false
		RARMBloodLevel = 0
	end

	--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

	if bleed5 then

		if RRARMBloodCapacity < MaxBloodCapacity5/3 then
		Bleed5 = Bleed5 * 6 
		for i=1,Bleed5/extremeantibleed do
		smoke5()
	end
	end

	if IsBodyBroken(RRARM) then
		for i=1,Bleed5/limbantibleed do
		smoke5()
	end
end
end

if bleed5 then
RRARMBloodLevel = RRARMBloodLevel - Bleed5*LimbBleedSpeed
end

	if RRARMBloodLevel <= 0 then
		bleed5 = false
		RRARMBloodLevel = 0
	end

	--LEGLEGLEGLELGLELGLGLELGLEGLLGLEGLELGLEGLELGLEGLEGLELGELLEGLEGLLEGLEGLGELGELGLEGLELGELGLEGLEGLLEGLEGLLEGLELGLEGLELGLEGLLEGLELGELGELG

	if bleed6 then

		if LLEGBloodCapacity < MaxBloodCapacity6/3 then
		Bleed6 = Bleed6 * 6 
		for i=1,Bleed6/extremeantibleed do
		smoke6()
	end
	end

	if IsBodyBroken(LLEG) then
		for i=1,Bleed6/limbantibleed do
		smoke6()
	end
end
end

if bleed6 then
LLEGBloodLevel = LLEGBloodLevel - Bleed6*LimbBleedSpeed
end

	if LLEGBloodLevel <= 0 then
		bleed6 = false
	LLEGBloodLevel = 0
	end

	--lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

	if bleed7 then

		if LLLEGBloodCapacity < MaxBloodCapacity7/3 then
		Bleed7 = Bleed7 * 6 
		for i=1,Bleed7/extremeantibleed do
		smoke7()
	end
	end

	if IsBodyBroken(LLLEG) then
		for i=1,Bleed7/limbantibleed do
		smoke7()
	end
end
end

if bleed7 then
LLLEGBloodLevel = LLLEGBloodLevel - Bleed7*LimbBleedSpeed
end

	if LLLEGBloodLevel <= 0 then
		bleed7 = false
	LLLEGBloodLevel = 0
	end

	--lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

	if bleed8 then

		if RLEGBloodCapacity < MaxBloodCapacity8/3 then
		Bleed8 = Bleed8 * 6 
		for i=1,Bleed8/extremeantibleed do
		smoke8()
	end
	end

	if IsBodyBroken(RLEG) then
		for i=1,Bleed8/limbantibleed do
		smoke8()
	end
end
end

if bleed8 then
RLEGBloodLevel = RLEGBloodLevel - Bleed8*LimbBleedSpeed
end

	if RLEGBloodLevel <= 0 then
		bleed8 = false
	RLEGBloodLevel = 0
	end

	--lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

	if bleed9 then

		if RRLEGBloodCapacity < MaxBloodCapacity9/3 then
		Bleed9 = Bleed9 * 6 
		for i=1,Bleed9/extremeantibleed do
		smoke9()
	end
	end

	if IsBodyBroken(RRLEG) then
		for i=1,Bleed9/limbantibleed do
		smoke9()
	end
end
end

if bleed9 then
RRLEGBloodLevel = RRLEGBloodLevel - Bleed9*LimbBleedSpeed
end

	if RRLEGBloodLevel <= 0 then
		bleed9 = false
	RRLEGBloodLevel = 0
	end

	TotalLegBloodCapacity = MaxBloodCapacity6 + MaxBloodCapacity7 + MaxBloodCapacity8 + MaxBloodCapacity9
	TotalLegBloodValue = RRLEGBloodLevel + RLEGBloodLevel + LLLEGBloodLevel + LLEGBloodLevel

	TotalBloodValue = RRLEGBloodLevel + RLEGBloodLevel + LLLEGBloodLevel + LLEGBloodLevel + RRARMBloodLevel + RARMBloodLevel + LLARMBloodLevel + LARMBloodLevel + TorsoBloodLevel + HeadBloodLevel
		upspeed[2] = TotalLegBloodValue/10000

	currentvel = GetBodyVelocity(Head)
	currentvel1 = GetBodyVelocity(LLLEG)
	currentvel2 = GetBodyVelocity(RRLEG)

	if IsBodyBroken(Head) then
		alive = false
	end

	if TorsoBloodLevel < MaxBloodCapacity1/4 or TorsoBloodCapacity < MaxBloodCapacity1/3 then
		alive = false
	end

	if TotalBloodValue < MinBloodValue then
		alive = false
	end
	if alive then
	SetBodyVelocity(Head,VecAdd(currentvel,upspeed))
	SetBodyVelocity(LLLEG,VecAdd(currentvel1,downspeed))
	SetBodyVelocity(RRLEG,VecAdd(currentvel2,downspeed))
end

a = GetPlayerTransform()

	distToPlayer = VecLength(VecSub(a.pos, TorsoPos.pos))

	if distToPlayer < 3 then
		inrange = true
	else
		inrange = false
	end


	if TotalBloodValue < bloodtocriticalcondition then
	 	criticalcondition = true
	 end

	if criticalcondition then
	 	SetTriggerTransform(DeathBreath, Transform(TorsoPos.pos, QuatEuler(0, 90, 0)))
	 end
	 if not criticalcondition then
	 	SetTriggerTransform(DeathBreath, Transform(Vec(0, 1000, 0), QuatEuler(0, 90, 0)))
	 end

	if not alive then
		criticalcondition = false
		SetTriggerTransform(DeathBreath, Transform(Vec(0, 1000, 0), QuatEuler(0, 90, 0)))
	end

		if IsBodyBroken(Torso) then
		if not hurded1 then
		hurt = true
		hurded1 = true
	end
	end

	if IsBodyBroken(LLARM) then
		if not hurded2 then
		hurt = true
		hurded2 = true
	end
	end

	if IsBodyBroken(LARM) then
		if not hurded3 then
		hurt = true
		hurded3 = true
	end
	end

	if IsBodyBroken(RARM) then
		if not hurded4 then
		hurt = true
		hurded4 = true
	end
	end

	if IsBodyBroken(LLEG) then
		if not hurded5 then
		hurt = true
		hurded5 = true
	end
	end

	if IsBodyBroken(LLLEG) then
		if not hurded6 then
		hurt = true
		hurded6 = true
	end
	end

	if IsBodyBroken(RLEG) then
		if not hurded7 then
		hurt = true
		hurded7 = true
	end
	end

	if IsBodyBroken(RRLEG) then
		if not hurded8 then
		hurt = true
		hurded8 = true
	end
	end

	if enemyspotted then
		if not located then
		enemylocated = true
		located = true
	end
	end


end


function smoke()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(HeadPos.pos, Vec(math.random(-Bleed/antibleed, Bleed/antibleed), math.random(-Bleed/antibleed, Bleed/antibleed), math.random(-Bleed/antibleed, Bleed/antibleed)),10)
end

function smoke1()
    --spawn sparks
     ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(TorsoPos.pos, Vec(math.random(-Bleed1/antibleed, Bleed1/antibleed), math.random(-Bleed1/antibleed, Bleed1/antibleed), math.random(-Bleed1/antibleed, Bleed1/antibleed)),10)
end

function smoke2()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(LARMPos.pos, Vec(math.random(-Bleed2/antibleed, Bleed2/antibleed), math.random(-Bleed2/antibleed, Bleed2/antibleed), math.random(-Bleed2/antibleed, Bleed2/antibleed)),10)
end

function smoke3()
    --spawn sparks
     ParticleType("smoke")
      ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(LLARMPos.pos, Vec(math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed)),10)
end

function smoke4()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(RARMPos.pos, Vec(math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed)),10)
end

function smoke5()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(RRARMPos.pos, Vec(math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed)),10)
end

function smoke6()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(LLEGPos.pos, Vec(math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed)),10)
end

function smoke7()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(LLLEGPos.pos, Vec(math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed)),10)
end

function smoke8()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(RLEGPos.pos, Vec(math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed)),10)
end

function smoke9()
    --spawn sparks
    ParticleType("smoke")
     ParticleTile(4)
    ParticleColor(0.3, 0, 0)
    ParticleRadius(0.05, 0.005)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleSticky(0.5)
    ParticleDrag(blooddrag)
    ParticleStretch(1)
    SpawnParticle(RRLEGPos.pos, Vec(math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed), math.random(-Bleed3/antibleed, Bleed3/antibleed)),10)
end

function GunSmoke()
    --spawn sparks
    barrel = FindShape("barrel")
    shootpos = GetShapeWorldTransform(barrel)
    ParticleType("smoke")
    ParticleColor(1, 1, 0.2)
    ParticleRadius(0.01, 0.005)
    ParticleEmissive(10,0)
    ParticleAlpha(1000)
    ParticleCollide(1)
    ParticleGravity(bloodgrav)
    ParticleDrag(0)
    ParticleStretch(1)
    SpawnParticle(shootpos.pos, Vec(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5)),0.3)
end


function draw()
if drawtext then
    UiPush()
      UiAlign("center middle")
      UiTranslate(400, 200)
      UiFont("bold.ttf", 30)
      UiText("Head Blood Level:  "..HeadBloodLevel)
    UiPop()

     UiPush()
      UiAlign("center middle")
      UiTranslate(400, 220)
      UiFont("bold.ttf", 30)
      UiText("Torso Blood Level:  "..TorsoBloodLevel)
    UiPop()

    UiPush()
      UiAlign("center middle")
      UiTranslate(400, 240)
      UiFont("bold.ttf", 30)
      UiText("upper left arm Blood Level:  "..LARMBloodLevel)
    UiPop()

     UiPush()
      UiAlign("center middle")
      UiTranslate(400, 260)
      UiFont("bold.ttf", 30)
      UiText("Lower left arm Blood Level:  "..LLARMBloodLevel)
    UiPop()

     UiPush()
      UiAlign("center middle")
      UiTranslate(400, 280)
      UiFont("bold.ttf", 30)
      UiText("Upper right arm Blood Level:  "..RARMBloodLevel)
    UiPop()

    UiPush()
      UiAlign("center middle")
      UiTranslate(400, 300)
      UiFont("bold.ttf", 30)
      UiText("Lower right arm Blood Level:  "..RRARMBloodLevel)
    UiPop()

    UiPush()
      UiAlign("center middle")
      UiTranslate(400, 320)
      UiFont("bold.ttf", 30)
      UiText("Upper left leg Blood Level:  "..LLEGBloodLevel)
    UiPop()

    UiPush()
      UiAlign("center middle")
      UiTranslate(400, 340)
      UiFont("bold.ttf", 30)
      UiText("Lower left leg Blood Level:  "..LLLEGBloodLevel)
    UiPop()

     UiPush()
      UiAlign("center middle")
      UiTranslate(400, 360)
      UiFont("bold.ttf", 30)
      UiText("Upper right leg Blood Level:  "..RLEGBloodLevel)
    UiPop()

     UiPush()
      UiAlign("center middle")
      UiTranslate(400, 380)
      UiFont("bold.ttf", 30)
      UiText("Lower right leg Blood Level:  "..RRLEGBloodLevel)
    UiPop()

    UiPush()
      UiAlign("center middle")
      UiTranslate(400, 400)
      UiFont("bold.ttf", 30)
      UiText("total Blood Level:  "..TotalBloodValue)
    UiPop()
end
if inrange then
	if enabled then

			UiPush()
      UiAlign("center middle")
      UiTranslate(900, 300)
      UiColor(0,0,1)
      UiFont("bold.ttf", 30)
      UiText("To disable viewable ragdoll stats, press H ")
    UiPop()

	UiPush()
      UiAlign("center middle")
      UiTranslate(900, 350)
      UiColor(0,1,0)
      UiFont("bold.ttf", 30)
      UiText("Total Blood Volume:  "..TotalBloodValue)
    UiPop()

    if alive then
    	  UiPush()
      UiAlign("center middle")
      UiTranslate(900, 400)
      UiColor(0,1,0)
      UiFont("bold.ttf", 60)
      UiText("ALIVE")
    UiPop()
    if criticalcondition then
    	UiPush()
      UiAlign("center middle")
      UiTranslate(900, 450)
      UiColor(1,1,0)
      UiFont("bold.ttf", 50)
      UiText("CRITICAL CONDITION")
    UiPop()
    end
end
if not alive then
	  UiPush()
	  UiColor(1,0,0)
      UiAlign("center middle")
      UiTranslate(900, 400)
      UiFont("bold.ttf", 60)
      UiText("DECEASED")
    UiPop()
end
end
end
end

function canSeePlayer()
    local camTrans = GetPlayerCameraTransform()
	local playerPos = camTrans.pos

	--Direction to player
	local dir = VecSub(playerPos, shootPos)
	local dist = VecLength(dir)
	dir = VecNormalize(dir)

	QueryRejectVehicle(GetPlayerVehicle())
	return not QueryRaycast(shootPos, dir, dist, 0, true)
end

function canSeeSpetsnaz()
    local camTrans = GetShapeWorldTransform(spetsnaz)
    camTrans.pos[2] = camTrans.pos[2]
	local playerPos = camTrans.pos

	--Direction to player
	local dir = VecSub(playerPos, shootPos)
	local dist = VecLength(dir)
	dir = VecNormalize(dir)

	QueryRejectVehicle(GetPlayerVehicle())
	return not QueryRaycast(shootPos, dir, dist, 0, true)
end

function PlayVoice()
	TorsoPos = GetBodyTransform(Torso)
if voiceenabled then
    	  if not alive then
    	  	if not plaid then
    	  	PlaySound(deathsnd[math.random(#deathsnd)],TorsoPos.pos,5)
    	  	plaid = true
    	  	playing = true
    	  end
    	end

    	if enemylocated then
    		if alive then
    		if not playing then
    	  	PlaySound(enemye[math.random(#enemye)],TorsoPos.pos,5)
    	  	playing = true
    	  end
    	end
    end

    if enemydown then
    	if alive then
    		if not playing then
    	  	PlaySound(enemydead[math.random(#enemydead)],TorsoPos.pos,5)
    	  	playing = true
    	  end
    	end
    end

    	if not criticalcondition then
    		if alive then
    	if hurt then
    		if not playing then
    	  	PlaySound(hurtsnd[math.random(#hurtsnd)],TorsoPos.pos,5)
    	  	playing = true
    	  end
    	end
	end
end
end
end