Jump to content

[HELP] Zombie, boss and bot system - DayZ


VVr0ngVVay

Recommended Posts

--By Fanbox 

fast_blood = 200000 -- ????? ? ???????
sold_blood = 20000 -- ????? ? ????????
zomb_blood = 5000 -- ????? ? ??????? ?????

fast_damage = 12000 -- ???? ???????
sold_damage = 4112 -- ???? ??????? ?????
zomb_damage = 1121 -- ???? ??????? ?????

--???????
bear_blood = 20000 
wolf_blood = 7000 
fox_blood = 5000 

bear_damage = 6111 
wolf_damage = 3112 
fox_damage = 1121 


animal_blood = 2000 
animal_damage = 100 

boss_chucky_blood = 500000
boss_chucky_damage = 100000

boss_hulk_blood = 1500000
boss_hulk_damage = 100000

boss_octopus_blood = 2000000
boss_octopus_damage = 100000

boss_blood_blood = 3000000 
boss_blood_damage = 100000

boss_leatherface_blood = 1000000 
boss_leatherface_damage = 100000

boss_all_blood = 50000 
boss_all_damage = 4212


function chasedStartAttack (zomb)
	if isElement ( zomb ) and not getElementData ( zomb, "target" ) then
		if getElementData ( zomb, "zHeared" ) then
			setElementData ( zomb, "zHeared", false ) 
		end
		setElementSyncer ( zomb, source )
		setPedAnimation ( zomb )
		if not exports.npc_hlc:isHLCEnabled ( zomb ) then
			exports.npc_hlc:enableHLCForNPC( zomb, getElementData ( zomb,"speed") or "sprint")
		end
		exports.npc_hlc:clearNPCTasks (zomb)
		exports.npc_hlc:addNPCTask ( zomb, {"killPed", source, 2, 2} )
		setElementData ( zomb, "target", source )
		setElementAlpha ( zomb, 255 )
	end
end
addEvent( "chasedStartAttackC", true )
addEventHandler( "chasedStartAttackC", getRootElement(), chasedStartAttack )

local stats = {
    [ 69 ] = 500,
    [ 70 ] = 999,
    [ 71 ] = 999,
    [ 72 ] = 999,
    [ 73 ] = 500,
    [ 74 ] = 999,
    [ 75 ] = 500,
    [ 76 ] = 999,
    [ 77 ] = 999,
    [ 78 ] = 999,
    [ 79 ] = 999,
	[ 160 ] = 999,
	[ 229 ] = 999,
	[ 230 ] = 999
}

function applyStats(player)
	for stat,value in pairs(stats) do
		setPedStat(player, stat, value)
	end
end


function spawnNewZombie(x, y, z, creator, ztype, skin)
	local zomb = createPed(skin,x,y,z+0.5,math.random(0,360),true)
	setElementData(zomb,"spawn_x",x)
	setElementData(zomb,"spawn_y",y)
	setElementData(zomb,"spawn_z",z)
	setElementData(zomb,"spawn_ztype",ztype)
	setElementData(zomb,"spawn_skin",skin)
	if isElement ( zomb ) then
		if not isElementInWater ( zomb ) then 
			setTimer ( activateZombie, 1000, 1, zomb, x, y, z, ztype )
			setElementData ( zomb, "creator", creator )
			return true
		else
			destroyElement ( zomb )
			return false
		end
	end
	return false
end




function activateZombie (zomb, x, y, z, ztype)
	if isElement ( zomb ) then
		local zSphere = createColSphere ( x, y, z, 50 ) 
		local zSphereFar = createColSphere ( x, y, z, 150 )
		local zSphereNear = createColSphere ( x, y, z, 3 )
		attachElements ( zSphere, zomb )
		attachElements ( zSphereFar, zomb )
		attachElements ( zSphereNear, zomb )	
		setElementData ( zSphere, 'shapeZomb', true )
		setElementData ( zSphereFar, 'shapeZomb', true )
		setElementData ( zSphereNear, 'shapeZomb', true )
		setElementData ( zomb, "zombieShape", zSphere )
		setElementData ( zSphere, "zombieShape", true )
		setElementData ( zSphere, "zombieElement", zomb )
		setElementData ( zomb, "shapeFar", zSphereFar )
		setElementData ( zomb, "shapeNear", zSphereNear )
		setElementData ( zSphereNear, "zShapeNear", true )
		
		--setElementData ( zomb, "zombie", true ) --??????? ?????? ?? ??????? (?????)
		--setElementData ( zomb, "animal", true ) --?????? ?????? ??????? (??????)
		--setElementData ( zomb, "killer", true ) --??????? ?????? ??????? (??????)
		--setElementData ( zomb, "boss", true ) --??????? ?????? ??????? (????)
		
		if ztype == 3 then
		setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "soldier", true )
			setElementData(zomb, "blood", sold_blood)
			setElementData(zomb, "damage", sold_damage)
			setElementData(zomb, "speed", "sprint")
		elseif ztype == 2 then
		setElementData ( zomb, "zombie", true )
			setElementData(zomb, "blood", fast_blood)
			setElementData ( zomb, "fast", true )
			setElementData(zomb, "damage", fast_damage)
			setElementData(zomb, "speed", "run")
		elseif ztype == 4 then
		setElementData ( zomb, "killer", true )
			setElementData(zomb, "blood", bear_blood)
			setElementData ( zomb, "bear", true )
			setElementData(zomb, "damage", bear_damage)
			setElementData(zomb, "speed", "run")
		elseif ztype == 5 then
		setElementData ( zomb, "killer", true )
			setElementData(zomb, "blood", wolf_blood)
			setElementData ( zomb, "wolf", true )
			setElementData(zomb, "damage", wolf_damage)
			setElementData(zomb, "speed", "sprint")
		elseif ztype == 6 then
		setElementData ( zomb, "killer", true )
			setElementData(zomb, "blood", fox_blood)
			setElementData ( zomb, "fox", true )
			setElementData(zomb, "damage", fox_damage)
			setElementData(zomb, "speed", "sprint")
		elseif ztype == 7 then
			setElementData ( zomb, "animal", true )
			setElementData(zomb, "blood", animal_blood)
			setElementData(zomb, "damage", animal_damage)
			setElementData(zomb, "speed", "sprint")
		elseif ztype == 9 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "boss_all", true )
			setElementData(zomb, "blood", boss_all_blood)
			setElementData(zomb, "damage", boss_all_blood)
			setElementData(zomb, "speed", "sprint")
		elseif ztype == 10 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "pila", true )
			setElementData(zomb, "blood", boss_all_blood)
			setElementData(zomb, "damage", boss_all_blood)
			setElementData(zomb, "speed", "run")			
			applyStats(zomb)
			giveWeapon(zomb, 9, 9999, true) 
		elseif ztype == 11 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "boss_chucky", true )
			setElementData(zomb, "blood", boss_chucky_blood)
			setElementData(zomb, "damage", boss_chucky_damage)
			setElementData(zomb, "speed", "sprint")
			setElementAlpha ( zomb, 5 )
		elseif ztype == 14 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "boss_hulk", true )
			setElementData(zomb, "blood", boss_hulk_blood)
			setElementData(zomb, "damage", boss_hulk_damage)
			setElementData(zomb, "speed", "sprint")
			setElementAlpha ( zomb, 5 )
		elseif ztype == 15 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "boss_octopus", true )
			setElementData(zomb, "blood", boss_octopus_blood)
			setElementData(zomb, "damage", boss_octopus_damage)
			setElementData(zomb, "speed", "run")
			setElementAlpha ( zomb, 5 )
		elseif ztype == 12 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "pila", true )
			setElementData(zomb, "blood", boss_all_blood)
			setElementData(zomb, "damage", boss_all_blood)
			setElementData(zomb, "speed", "run")			
			applyStats(zomb)
			giveWeapon(zomb, 29, 9999, true)
		elseif ztype == 16 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "pila", true )
			setElementData(zomb, "blood", boss_all_blood)
			setElementData(zomb, "damage", boss_all_blood)
			setElementData(zomb, "speed", "run")			
			applyStats(zomb)
			giveWeapon(zomb, 27, 9999, true) 
		elseif ztype == 17 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "boss_leatherface", true )
			setElementData(zomb, "blood", boss_leatherface_blood)
			setElementData(zomb, "damage", boss_leatherface_damage)
			setElementData(zomb, "speed", "run")		
		elseif ztype == 13 then
			setElementData ( zomb, "zombie", true )
			setElementData ( zomb, "boss_blood", true )
			setElementData(zomb, "blood", boss_blood_blood)
			setElementData(zomb, "damage", boss_blood_damage)
			setElementData(zomb, "speed", "sprint")			
			applyStats(zomb)
		else
			setElementData ( zomb, "zombie", true )
			setElementData(zomb, "blood", zomb_blood)
			setElementData(zomb, "damage", zomb_damage)
			setElementData(zomb, "speed", "run")

		end
		wentZombieToWalk ( zomb )
	end
end

function wentZombieToWalk (zomb)
	if zomb then
		if isElement ( zomb ) then
			if not isPedDead ( zomb ) then
				if checkPlayersInView ( zomb ) then
					if not getElementData ( zomb, "target" ) and not getElementData ( zomb, 'rotating' ) then
						local rdmangle = math.random( 1, 359 )
						setPedRotation( zomb, rdmangle )
						setPedAnimation ( zomb, "PED", "WALK_fatold", -1, true, true, true)
						setTimer ( wentZombieToWalk, 10000, 1, zomb )
						if getElementData ( zomb, "boss_blood" ) then
						setElementAlpha ( zomb, 5 )
						end
					end
				else
					if isElement ( getElementData ( zomb, "zombieShape" ) ) then destroyElement ( getElementData ( zomb, "zombieShape" ) ) end
					if isElement ( getElementData ( zomb, "shapeFar" ) ) then destroyElement ( getElementData ( zomb, "shapeFar" ) ) end
					if isElement ( getElementData ( zomb, "shapeNear" ) ) then destroyElement ( getElementData ( zomb, "shapeNear" ) ) end
					local attaches = getAttachedElements ( zomb )
					if attaches then
						for ElementKey, ElementValue in ipairs ( attaches ) do
							if isElement ( ElementValue ) then
								if not getElementData ( ElementValue, "zRadZone" ) then
									destroyElement ( ElementValue )
								end
							end
						end
					end
					local creator = getElementData ( zomb, "creator" ) 
					if isElement ( creator ) then
						setElementData ( creator, "spawnedzombies", ( getElementData ( creator, "spawnedzombies" ) or 1 ) - 1 )
					end
					setElementData ( zomb, "target", false )
					setElementData ( zomb, "rotating", nil )
					if not getElementData ( zomb, "target" ) and not getElementData ( zomb, 'rotating' ) then
						local rdmangle = math.random( 1, 359 )
						setPedRotation( zomb, rdmangle )
						setPedAnimation ( zomb, "PED", "WALK_fatold", -1, true, true, true)
						setTimer ( wentZombieToWalk, 10000, 1, zomb )
						if getElementData ( zomb, "boss_blood" ) then
						setElementAlpha ( zomb, 5 )
						end
					end
				end
			end
		end
	end
end

function checkPlayersInView ( zomb ) 
	local shapeFar = getElementData ( zomb, "shapeFar" )
	if isElement(shapeFar) then
		if #getElementsWithinColShape ( shapeFar, 'player' ) == 0 then
			return false 
		else return true end
	end
end

function zombieKilledPlayer (task)
	if getElementData ( source, "zombie" ) then
		if task[1] == "walkToPos" then
			if getElementData ( source, "rotating" ) then
				setElementRotation ( source, 0, 0, task[6] )
				setTimer ( function ( zomb ) if isElement ( zomb ) then setElementData ( zomb, "rotating", false ); wentZombieToWalk ( zomb ) end end, 3000, 1, source )				
			end
		end
		if getElementData ( source, "target" ) then
			local diedPlayer = task[2]
			setElementData ( source, "target", nil )
			wentZombieToWalk ( source )
		end
	end
end

addEventHandler ( "npc_hlc:onNPCTaskDone", root, zombieKilledPlayer )


function killPlayerOfSick()
	for i, v in ipairs ( getElementsByType ("ped")) do
		if getElementData ( v, "zombie" ) then
			local target = getElementData ( v, "target" )
			if target and target == source then
				setElementData ( v, "target", false )
				exports.npc_hlc:clearNPCTasks(v)
				setTimer ( wentZombieToWalk, 3000, 1, v )
			end
		end
	end
end
addEvent("killPlayerOfSick",true)
addEventHandler("killPlayerOfSick",getRootElement(),killPlayerOfSick)

function checkUnactiveZombies ()
	for i, v in ipairs ( getElementsByType ("ped")) do
		if getElementData ( v, "zombie" ) then
			local target = getElementData ( v, "target" )
			if target and not isElement ( target ) then
				setElementData ( v, "target", false )
				wentZombieToWalk ( v )
			end
		end
	end
end
setTimer (checkUnactiveZombies,10000,0)--600000

function zombieWasAttackedS ( zomb )
	if not isPedDead ( zomb ) and not getElementData ( source, "isPlayerZombie" ) then
		setPedAnimation ( zomb )
		if not exports.npc_hlc:isHLCEnabled ( zomb ) then
			exports.npc_hlc:enableHLCForNPC( zomb, getElementData ( zomb,"speed") or "sprint")
		end
		exports.npc_hlc:clearNPCTasks (zomb)
		exports.npc_hlc:addNPCTask ( zomb, {"killPed", source, 2, 2} )
		setElementData ( zomb, "target", source )
		setTimer ( wentZombieToWalk, 1000, 1, zomb )
	end
end
addEvent( "zombieWasAttacked", true )
addEventHandler( "zombieWasAttacked", getRootElement(), zombieWasAttackedS )

function zombieHearedS ( zomb )
	if isElement ( zomb ) then
		if not isPedDead ( zomb ) then
			if not getElementData ( zomb, "target" ) and not getElementData ( source, "zHeared" ) and not getElementData ( source, "isPlayerZombie" ) then
				setPedAnimation ( zomb )
				if not exports.npc_hlc:isHLCEnabled ( zomb ) then
					exports.npc_hlc:enableHLCForNPC( zomb, getElementData ( zomb,"speed") or "sprint")
				end
				exports.npc_hlc:clearNPCTasks (zomb)
				setElementData ( zomb, "zHeared", source )
				local x,y,z = getElementPosition ( source )
				exports.npc_hlc:addNPCTask ( zomb, {"walkToPos", x, y, z, 2})
			end
		end
	end
end
addEvent( "zombieHeared", true )
addEventHandler( "zombieHeared", getRootElement(), zombieHearedS )


function rotateZombieToPlayer ( rotation, x, y, z )
	if not isPedDead ( source ) then
		if not getElementData ( source, "target" ) then
			setPedAnimation ( source )
			if not exports.npc_hlc:isHLCEnabled ( source ) then
				exports.npc_hlc:enableHLCForNPC( source, getElementData ( source,"speed") or "sprint")
			end
			exports.npc_hlc:clearNPCTasks (source)
			exports.npc_hlc:addNPCTask ( source, {"walkToPos", x, y, z, 1, rotation})
		end
	end
end

addEvent( "rotateZombieToPlayer", true )
addEventHandler( "rotateZombieToPlayer", getRootElement(), rotateZombieToPlayer )

function zombieNearLeave ( thePlayer )
	if getElementType ( thePlayer ) == "player" and getElementData ( source, "zombieShape" ) then
		local zomb = getElementData ( source, "zombieElement" )
		if isElement ( zomb ) and exports.npc_hlc:isHLCEnabled ( zomb ) then
			if getElementData ( zomb, "fast" ) then
				return true
			end
			local thistask = getElementData(zomb,"npc_hlc:thistask")
			if thistask then
				local task = getElementData(zomb,"npc_hlc:task."..thistask)
				if task then
					if task[1] == "killPed" and isElement ( task[2] ) then
						if task[2] == thePlayer then
							exports.npc_hlc:clearNPCTasks (zomb)
							setElementData(zomb,"target",false)
							wentZombieToWalk(zomb)
						end
					end
				end
			end
		end	
	end
end
addEventHandler ( "onColShapeLeave", root, zombieNearLeave )
--???? ??? ??????? ????
function PanicAnimals(zomb)
    if isElement(zomb) then
				local rdmangle = math.random( 1, 359 )
				setPedRotation( zomb, rdmangle )
				setPedAnimation ( zomb, "PED", "sprint_panic", -1, true, true, true)
				setTimer ( PanicAnimals, 20000, 1, zomb ) --??????? ?????? ? ???? ??????
		end
	end

function animalStopFollow(zomb)
    PanicAnimals(zomb)
end
addEvent("animalStopFollow",true)
addEventHandler("animalStopFollow",getRootElement(),animalStopFollow)
--
checkZombies = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "zombie") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*1.2 + visibly*1.2 and scal <= 0 ) or ( distance > sound*1.4 + visibly*1.4 ) then -- Расстояние за которую он вас увидит и услышит (средне)
				ready = false
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkZombies, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )


checkAnimal = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "animal") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*3 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "animalStopFollow", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkAnimal, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkKiller = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "killer") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*3 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkKiller, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkboss4aki = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "boss_chucky") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*3 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkboss4aki, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkbossleatherface = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "boss_leatherface") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*3 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(bossleatherface, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkbosshulk = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "boss_hulk") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*3 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkbosshulk, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkbossoctopus = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "boss_octopus") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 3
			local visibly = getElementData(getLocalPlayer(), "visibly") / 3
			local ready = true
			if ( distance > sound*1 + visibly*1 and scal <= 0 ) or ( distance > sound*1 + visibly*1 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkbossoctopus, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkblood = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "boss_blood") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 2
			local visibly = getElementData(getLocalPlayer(), "visibly") / 2
			local ready = true
			if ( distance > sound*3 + visibly*3 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkblood, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkBots = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "bots") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*5 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "botsStartAttack", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkBots, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkbossBenz = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "bossBenz") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*5 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkbossBenz, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

checkbossCrais = function()
	for i,ped in ipairs(getElementsByType("ped",root,true)) do
		if getElementData(ped, "bossCrais") then
			local x,y,z = getElementPosition ( localPlayer )
			local zx,zy,zz = getElementPosition (ped)
			local zfrontx, zfronty, zfrontz = getPositionInfrontOfElement(ped, 3)
			
			local vect1X, vect1Y =  zx-x, zy-z
			local vect2X, vect2Y = zfrontx-zx, zfronty - zy
			
			local scal = vect2X*vect1X+vect2Y*vect1Y
			
			local distance = getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz )
			local sound = getElementData(getLocalPlayer(), "volume") / 5
			local visibly = getElementData(getLocalPlayer(), "visibly") / 5
			local ready = true
			if ( distance > sound*3 + visibly*5 and scal <= 0 ) or ( distance > sound*3 + visibly*3 ) then -- Расстояние за которую он вас увидит и услышит (ДАЛЕКО)
				ready = false 
			end
			if ready then
				triggerServerEvent ( "chasedStartAttackC", getLocalPlayer(), ped )
			end
		end
	end
end
setTimer(checkbossCrais, 2000, 0)
setElementData ( localPlayer, "spawnedzombies", 0 )

function zombieJump(ped)
	if (isElement(source)) then
		setPedControlState(source,"jump",true)
		setTimer(function(source) 
			if (isElement(source)) then 
				setPedControlState(source,"jump",false) 
			end 
		end,800,1,source)
	end
end
addEventHandler("bot_Jump",getRootElement(),zombieJump)
addEvent("bot_Jump",true)

function getPositionInfrontOfElement(element, meters)
    if not element or not isElement(element) then
        return false
    end
    if not meters then
        meters = 3
    end
    local posX, posY, posZ = getElementPosition(element)
    local _, _, rotation = getElementRotation(element)
    posX = posX - math.sin(math.rad(rotation)) * meters
    posY = posY + math.cos(math.rad(rotation)) * meters
    return posX, posY, posZ
end

local fires = 0
local shotCheckAvailable = true

function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement )
	if getElementData ( localPlayer, "isPlayerZombie" ) then return true end
	if shotCheckAvailable then
		if weapon > 9 and weapon ~= 23 then
			shotCheckAvailable = false
			setTimer ( function () shotCheckAvailable = true end, 4000, 1 )
			local zombs = getElementsByType ( "ped", getRootElement(), true )
			local x,y,z = getElementPosition ( localPlayer )
			for i,zomb in ipairs(zombs) do 
				if not getElementData ( zomb, "target" ) and not getElementData ( zomb, "zHeared" ) then
					local zx,zy,zz = getElementPosition (zomb)
					if getDistanceBetweenPoints3D ( x,y,z, zx,zy,zz ) < 50 then
						triggerServerEvent ("zombieHeared", localPlayer, zomb )
					end
				end
			end
		end
	end
end
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc )

function findRotation(x1,y1,x2,y2)
	local t = -math.deg(math.atan2(x2-x1,y2-y1))
	if t < 0 then t = t + 360 end;
	return t
end

Hi, i need help :(

Bots don't take as much blood as is set...

Server gives them parameters from editor_client.Lua.

gameplayVariables = {}
gameplayVariables["ping"] = 300
gameplayVariables["zombiedamage"] = math.random(800,2000)
gameplayVariables["enablenight"] = false
gameplayVariables["hourxp"] = 125

There is also such a reference to this script in survivorSystem_client.Lua 

		elseif getElementData ( attacker, "bots" ) or getElementData ( attacker, "snegovik" ) or getElementData ( attacker, "santa" ) or getElementData ( attacker, "boss4aki" ) or getElementData ( attacker, "bossBenz" ) or getElementData ( attacker, "bossCrais" ) then
			local damageded = Damage_ToCloth (bodypart)
			local reduce = getClothDamageReduce (pl_model, bodypart)
				setElementData(getLocalPlayer(),"blood",getElementData(getLocalPlayer(),"blood")-getElementData(attacker,"BOSSdamage")*damageded*reduce)
			local number = math.random(1,7)
			if number == 4 then
				setElementData(getLocalPlayer(),"bleeding",getElementData(getLocalPlayer(),"bleeding") + math.floor(loss*5))
			end
		end
	end

Please help me. 

What can cause all bots to hit with the same force?
Link to comment
  • Scripting Moderators
6 hours ago, VVr0ngVVay said:

Bots don't take as much blood as is set...

Server gives them parameters from editor_client.Lua.

If uses data from table, then there's is your problem:

gameplayVariables["zombiedamage"] = math.random(800,2000)

It is only randomized once, on script initalization.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...