Sign in to follow this  
VVr0ngVVay

Function jump bot

Recommended Posts

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

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

Why this function don't working...?

How i can add jump for zombie?

This is stat zombie 4:

		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")

How i can add jump for it?

I use npc_hlc.

Share this post


Link to post

npc_functions_s.Lua

function enableHLCForNPC(npc,walkspeed,accuracy,drivespeed)
	if not isElement(npc) or getElementType(npc) ~= "ped" then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	if all_npcs[npc] then
		outputDebugString("HLC already enabled",2)
		return false
	end

	if walkspeed and not NPC_SPEED_ONFOOT[walkspeed] then
		outputDebugString("Invalid walkspeed argument",2)
		return false
	end
	if accuracy then
		accuracy = tonumber(accuracy)
		if not accuracy or accuracy < 0 or accuracy > 1 then
			outputDebugString("Invalid accuracy argument",2)
			return false
		end
	end
	if drivespeed then
		drivespeed = tonumber(drivespeed)
		if not drivespeed or drivespeed < 0 then
			outputDebugString("Invalid drivespeed argument",2)
			return false
		end
	end

	addEventHandler("onElementDataChange",npc,cleanUpDoneTasks)
	addEventHandler("onElementDestroy",npc,destroyNPCInformationOnDestroy)
	all_npcs[npc] = true
	setElementData(npc,"npc_hlc",true)
	--addNPCToUnsyncedList(npc)	
	setNPCWalkSpeed(npc,walkspeed or "run")
	setNPCWeaponAccuracy(npc,accuracy or 1)
	setNPCDriveSpeed(npc,drivespeed or 40/180)

	return true
end

function disableHLCForNPC(npc)
	if not isElement(npc) or getElementType(npc) ~= "ped" then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	if not all_npcs[npc] then
		outputDebugString("HLC not enabled",2)
		return false
	end

	clearNPCTasks(npc)

	removeEventHandler("onElementDataChange",npc,cleanUpDoneTasks)
	removeEventHandler("onElementDestroy",npc,destroyNPCInformationOnDestroy)
	destroyNPCInformation(npc)
	removeElementData(npc,"npc_hlc")
	
	removeElementData(npc,"npc_hlc:walk_speed")
	removeElementData(npc,"npc_hlc:accuracy")
	removeElementData(npc,"npc_hlc:drive_speed")

	return true
end

function setNPCWalkSpeed(npc,speed)
	if not npc or not all_npcs[npc] then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	if speed ~= "walk" and speed ~= "run" and speed ~= "sprint" and speed ~= "sprintfast" then
		outputDebugString("Invalid speed argument",2)
		return false
	end
	setElementData(npc,"npc_hlc:walk_speed",speed)
	return true
end

function setNPCWeaponAccuracy(npc,accuracy)
	if not npc or not all_npcs[npc] then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	accuracy = tonumber(accuracy)
	if not accuracy or accuracy < 0 or accuracy > 1 then
		outputDebugString("Invalid accuracy argument",2)
		return false
	end
	setElementData(npc,"npc_hlc:accuracy",accuracy)
	return true
end

function setNPCDriveSpeed(npc,speed)
	if not npc or not all_npcs[npc] then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	speed = tonumber(speed)
	if not speed or speed < 0 then
		outputDebugString("Invalid speed argument",2)
		return false
	end
	setElementData(npc,"npc_hlc:drive_speed",speed)
	return true
end

------------------------------------------------

function addNPCTask(npc,task)
	if not npc or not all_npcs[npc] then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	if not isTaskValid(task) then
		outputDebugString("Invalid task argument",2)
		return false
	end
	local lasttask = getElementData(npc,"npc_hlc:lasttask")
	if not lasttask then
		lasttask = 1
		setElementData(npc,"npc_hlc:thistask",1)
	else
		lasttask = lasttask+1
	end
	setElementData(npc,"npc_hlc:task."..lasttask,task)
	setElementData(npc,"npc_hlc:lasttask",lasttask)
	return true
end

function clearNPCTasks(npc)
	if not npc or not all_npcs[npc] then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	local thistask = getElementData(npc,"npc_hlc:thistask")
	if not thistask then return end
	local lasttask = getElementData(npc,"npc_hlc:lasttask")
	for task = thistask,lasttask do
		removeElementData(npc,"npc_hlc:task."..task)
	end
	removeElementData(npc,"npc_hlc:thistask")
	removeElementData(npc,"npc_hlc:lasttask")
	return true
end

function setNPCTask(npc,task)
	if not npc or not all_npcs[npc] then
		outputDebugString("Invalid ped argument",2)
		return false
	end
	if not isTaskValid(task) then
		outputDebugString("Invalid task argument",2)
		return false
	end
	clearNPCTasks(npc)
	setElementData(npc,"npc_hlc:task.1",task)
	setElementData(npc,"npc_hlc:thistask",1)
	setElementData(npc,"npc_hlc:lasttask",1)
	return true
end

function isTaskValid(task)
	local taskFunc = taskValid[task[1]]
	return taskFunc and taskFunc(task) or false
end

actions_s.Lua

function makeNPCWalkToPos(npc,x,y,z,maxtime)
	local px,py,pz = getElementPosition(npc)
	local walk_dist = NPC_SPEED_ONFOOT[getNPCWalkSpeed(npc)]*maxtime*0.001
	local dx,dy,dz = x-px,y-py,z-pz
	local dist = getDistanceBetweenPoints3D(0,0,0,dx,dy,dz)
	dx,dy,dz = dx/dist,dy/dist,dz/dist
	local maxtime_unm = maxtime
	if dist < walk_dist then
		maxtime = maxtime*dist/walk_dist
		walk_dist = dist
	end
	local model = getElementModel(npc)
	x,y,z = px+dx*walk_dist,py+dy*walk_dist,pz+dz*walk_dist
	local rot = -math.deg(math.atan2(dx,dy))

	local move = true
	if check_cols then
		local box = call(server_coldata,"createModelIntersectionBox",model,x,y,z,rot)
		local boxprev = call(server_coldata,"getElementIntersectionBox",npc)
		move = not call(server_coldata"doesModelBoxIntersect",box,getElementDimension(npc),boxprev)
	end
	if move then
		setElementPosition(npc,x,y,z,false)
		setPedRotation(npc,rot)
		if check_cols then call(server_coldata,"updateElementColData",npc) end
		return maxtime
	else
		setElementPosition(npc,px,py,pz)
		setPedRotation(npc,getPedRotation(npc))
		return maxtime_unm
	end
end

function makeNPCWalkAlongLine(npc,x1,y1,z1,x2,y2,z2,off,maxtime)
	local x_this,y_this,z_this = getElementPosition(npc)
	local walk_dist = NPC_SPEED_ONFOOT[getNPCWalkSpeed(npc)]*maxtime*0.001
	local p2_this = getPercentageInLine(x_this,y_this,x1,y1,x2,y2)
	local p1_this = 1-p2_this
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)
	local p2_next = p2_this+walk_dist/len
	local p1_next = 1-p2_next
	local x_next,y_next,z_next
	local maxtime_unm = maxtime
	if p2_next > 1 then
		maxtime = maxtime*(1-p2_this)/(p2_next-p2_this)
		x_next,y_next,z_next = x2,y2,z2
	else
		x_next = x1*p1_next+x2*p2_next
		y_next = y1*p1_next+y2*p2_next
		z_next = z1*p1_next+z2*p2_next
	end
	local model = getElementModel(npc)
	local rot = -math.deg(math.atan2(x2-x1,y2-y1))

	local move = true
	if check_cols then
		local box = call(server_coldata,"createModelIntersectionBox",model,x_next,y_next,z_next,rot)
		local boxprev = call(server_coldata,"getElementIntersectionBox",npc)
		move = not call(server_coldata,"doesModelBoxIntersect",box,getElementDimension(npc),boxprev)
	end
	if move then
		setElementPosition(npc,x_next,y_next,z_next,false)
		setPedRotation(npc,rot)
		if check_cols then call(server_coldata,"updateElementColData",npc) end
		return maxtime
	else
		setElementPosition(npc,x_this,y_this,z_this)
		setPedRotation(npc,getPedRotation(npc))
		return maxtime_unm
	end
end

function makeNPCWalkAroundBend(npc,x0,y0,x1,y1,z1,x2,y2,z2,off,maxtime)
	local x_this,y_this,z_this = getElementPosition(npc)
	local walk_dist = NPC_SPEED_ONFOOT[getNPCWalkSpeed(npc)]*maxtime*0.001
	local p2_this = getAngleInBend(x_this,y_this,x0,y0,x1,y1,x2,y2)/math.pi*2
	local p1_this = 1-p2_this
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)
	local p2_next = p2_this+walk_dist/len
	local p1_next = 1-p2_next
	local x_next,y_next,z_next,a_next
	local maxtime_unm = maxtime
	if p2_next > 1 then
		maxtime = maxtime*(1-p2_this)/(p2_next-p2_this)
		x_next,y_next,z_next = x2,y2,z2
		a_next = -math.deg(math.atan2(x0-x1,y0-y1))
	else
		x_next,y_next = getPosFromBend(p2_next*math.pi*0.5,x0,y0,x1,y1,x2,y2)
		z_next = z1*p1_next+z2*p2_next
		local x_next_front,y_next_front = getPosFromBend(p2_next*math.pi*0.5+0.01,x0,y0,x1,y1,x2,y2)
		a_next = -math.deg(math.atan2(x_next_front-x_next,y_next_front-y_next))
	end
	local model = getElementModel(npc)

	local move = true
	if check_cols then
		local box = call(server_coldata,"createModelIntersectionBox",model,x_next,y_next,z_next,a_next)
		local boxprev = call(server_coldata,"getElementIntersectionBox",npc)
		move = not call(server_coldata,"doesModelBoxIntersect",box,getElementDimension(npc),boxprev)
	end
	if move then
		setElementPosition(npc,x_next,y_next,z_next,false)
		setPedRotation(npc,a_next)
		if check_cols then call(server_coldata,"updateElementColData",npc) end
		return maxtime
	else
		setElementPosition(npc,x_this,y_this,z_this)
		setPedRotation(npc,getPedRotation(npc))
		return maxtime_unm
	end
end

--[[function makeNPCWalkAlongLine(npc,x1,y1,z1,x2,y2,z2,off,maxtime)
	local x_this,y_this,z_this = getElementPosition(npc)
	local walk_dist = NPC_SPEED_ONFOOT[getNPCWalkSpeed(npc)]*maxtime*0.001
	local p2_this = getPercentageInLine(x_this,y_this,x1,y1,x2,y2)
	local p1_this = 1-p2_this
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)
	local p2_next = p2_this+off/len
	local p1_next = 1-p2_next
	local x_next,y_next,z_next = p1_next*x1+p2_next*x2,p1_next*y1+p2_next*y2,p1_next*z1+p2_next*z2
	local next_dist = getDistanceBetweenPoints3D(x_this,y_this,z_this,x_next,y_next,z_next)
	if p2_next > 1 then
		local p_next = (1-p2_this)/(p2_next-p2_this)
		local p_this = 1-p_next
		x_next = x_this*p_this+x_next*p_next
		y_next = y_this*p_this+y_next*p_next
		z_next = z_this*p_this+z_next*p_next
		local next_dist = getDistanceBetweenPoints3D(x_this,y_this,z_this,x_next,y_next,z_next)
		if next_dist < walk_dist then
			maxtime = maxtime*next_dist/walk_dist
			setPedRotation(npc,-math.deg(math.atan2(x_next-x_this,y_next-y_this)))
		else
			local distmult = walk_dist/next_dist
			x_next = (x_next-x_this)*distmult+x_this
			y_next = (y_next-y_this)*distmult+y_this
			z_next = (z_next-z_this)*distmult+z_this
		end
		setElementPosition(npc,x_next,y_next,z_next,false)
		setPedRotation(npc,-math.deg(math.atan2(x_next-x_this,y_next-y_this)))
		return maxtime
	else
		if next_dist < walk_dist then
			local next2_dist = walk_dist-next_dist
			local p2_next2 = p2_next+next2_dist/len
			if p2_next2 > 1 then
				maxtime = maxtime*(walk_dist-(p2_next2-1)*len)/walk_dist
				x_next,y_next,z_next = x2,y2,z2
			else
				local p1_next2 = 1-p2_next2
				x_next = p1_next2*x1+p2_next2*x2
				y_next = p1_next2*y1+p2_next2*y2
				z_next = p1_next2*z1+p2_next2*z2
			end
			setElementPosition(npc,x_next,y_next,z_next,false)
			setPedRotation(npc,-math.deg(math.atan2(x2-x1,y2-y1)))
			return maxtime
		else
			local distmult = walk_dist/next_dist
			x_next = (x_next-x_this)*distmult
			y_next = (y_next-y_this)*distmult
			z_next = (z_next-z_this)*distmult
			setPedRotation(npc,-math.deg(math.atan2(x_next,y_next)))
			x_next,y_next,z_next = x_next+x_this,y_next+y_this,z_next+z_this
			setElementPosition(npc,x_next,y_next,z_next,false)
			return maxtime
		end
	end
end

function makeNPCWalkAroundBend(npc,x0,y0,x1,y1,z1,x2,y2,z2,off,maxtime)
	local x_this,y_this,z_this = getElementPosition(npc)
	local walk_dist = NPC_SPEED_ONFOOT[getNPCWalkSpeed(npc)]*maxtime*0.001
	local p2_this = getAngleInBend(x_this,y_this,x0,y0,x1,y1,x2,y2)/math.pi*2
	local p1_this = 1-p2_this
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)*math.pi*0.5
	local p2_next = p2_this+off/len
	local p1_next = 1-p2_next
	local x_next,y_next = getPosFromBend(p2_next*math.pi*0.5,x0,y0,x1,y1,x2,y2)
	local z_next = p1_next*z1+p2_next*z2
	local next_dist = getDistanceBetweenPoints3D(x_this,y_this,z_this,x_next,y_next,z_next)
	if p2_next > 1 then
		local p_next = (1-p2_this)/(p2_next-p2_this)
		local p_this = 1-p_next
		x_next = x_this*p_this+x_next*p_next
		y_next = y_this*p_this+y_next*p_next
		z_next = z_this*p_this+z_next*p_next
		local next_dist = getDistanceBetweenPoints3D(x_this,y_this,z_this,x_next,y_next,z_next)
		if next_dist < walk_dist then
			maxtime = maxtime*next_dist/walk_dist
		else
			local distmult = walk_dist/next_dist
			x_next = (x_next-x_this)*distmult+x_this
			y_next = (y_next-y_this)*distmult+y_this
			z_next = (z_next-z_this)*distmult+z_this
		end
		setElementPosition(npc,x_next,y_next,z_next,false)
		setPedRotation(npc,-math.deg(math.atan2(x_next-x_this,y_next-y_this)))
		return maxtime
	else
		if next_dist < walk_dist then
			local next2_dist = walk_dist-next_dist
			local p2_next2 = p2_next+next2_dist/len
			if p2_next2 > 1 then
				maxtime = maxtime*(walk_dist-(p2_next2-1)*len)/walk_dist
				x_next,y_next,z_next = x2,y2,z2
			else
				local p1_next2 = 1-p2_next2
				x_next = p1_next2*x1+p2_next2*x2
				y_next = p1_next2*y1+p2_next2*y2
				z_next = p1_next2*z1+p2_next2*z2
			end
			setElementPosition(npc,x_next,y_next,z_next,false)
			setPedRotation(npc,-math.deg(math.atan2(x2-x1,y2-y1)))
			return maxtime
		else
			local distmult = walk_dist/next_dist
			x_next = (x_next-x_this)*distmult
			y_next = (y_next-y_this)*distmult
			z_next = (z_next-z_this)*distmult
			setPedRotation(npc,-math.deg(math.atan2(x_next,y_next)))
			x_next,y_next,z_next = x_next+x_this,y_next+y_this,z_next+z_this
			setElementPosition(npc,x_next,y_next,z_next,false)
			return maxtime
		end
	end
end]]

function makeNPCDriveToPos(npc,x,y,z,maxtime)
	local car = getPedOccupiedVehicle(npc)
	local px,py,pz = getElementPosition(car)
	local speed = getNPCDriveSpeed(npc)
	local drive_dist = speed*50*maxtime*0.001
	local dx,dy,dz = x-px,y-py,z-pz
	local dist = getDistanceBetweenPoints3D(0,0,0,dx,dy,dz)
	dx,dy,dz = dx/dist,dy/dist,dz/dist
	local rx,ry,rz = math.deg(math.asin(dz)),0,-math.deg(math.atan2(dx,dy))
	local vx,vy,vx
	local maxtime_unm = maxtime
	if dist < drive_dist then
		maxtime = maxtime*dist/drive_dist
		drive_dist = dist
		vx,vy,vz = 0,0,0
	else
		vx,vy,vz = dx*speed,dy*speed,dz*speed
	end
	local model = getElementModel(car)
	x,y,z = px+dx*drive_dist,py+dy*drive_dist,pz+dz*drive_dist

	local move = true
	if check_cols then
		local box = call(server_coldata,"createModelIntersectionBox",model,x,y,z,rz)
		local boxprev = call(server_coldata,"getElementIntersectionBox",car)
		move = not call(server_coldata,"doesModelBoxIntersect",box,getElementDimension(car),boxprev)
	end
	if move then
		setElementPosition(car,x,y,z,true)
		setElementRotation(car,rx,ry,rz)
		setElementVelocity(car,vx,vy,vz)
		setVehicleTurnVelocity(car,0,0,0)
		setElementPosition(npc,x,y,z)
		if check_cols then call(server_coldata,"updateElementColData",car) end
		return maxtime
	else
		setElementPosition(car,px,py,pz,true)
		setElementRotation(car,getElementRotation(car))
		setElementVelocity(car,0,0,0)
		setVehicleTurnVelocity(car,0,0,0)
		return maxtime_unm
	end
end

function makeNPCDriveAlongLine(npc,x1,y1,z1,x2,y2,z2,off,maxtime)
	local car = getPedOccupiedVehicle(npc)
	local x_this,y_this,z_this = getElementPosition(car)
	local speed = getNPCDriveSpeed(npc)
	local drive_dist = speed*50*maxtime*0.001
	local p2_this = getPercentageInLine(x_this,y_this,x1,y1,x2,y2)
	local p1_this = 1-p2_this
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)
	local p2_next = p2_this+drive_dist/len
	local p1_next = 1-p2_next
	local x_next,y_next,z_next
	local dirx,diry,dirz = (x2-x1)/len,(y2-y1)/len,(z2-z1)/len
	local vx,vy,vz
	local maxtime_unm = maxtime
	if p2_next > 1 then
		maxtime = maxtime*(1-p2_this)/(p2_next-p2_this)
		x_next,y_next,z_next = x2,y2,z2
		vx,vy,vz = 0,0,0
	else
		x_next = x1*p1_next+x2*p2_next
		y_next = y1*p1_next+y2*p2_next
		z_next = z1*p1_next+z2*p2_next
		vx,vy,vz = dirx*speed,diry*speed,dirz*speed
	end
	local model = getElementModel(car)
	local rx,ry,rz = math.deg(math.asin(dirz)),0,-math.deg(math.atan2(dirx,diry))

	local move = true
	if check_cols then
		local box = call(server_coldata,"createModelIntersectionBox",model,x_next,y_next,z_next,rz)
		local boxprev = call(server_coldata,"getElementIntersectionBox",car)
		move = not call(server_coldata,"doesModelBoxIntersect",box,getElementDimension(car),boxprev)
	end
	if move then
		setElementPosition(car,x_next,y_next,z_next,true)
		setElementRotation(car,rx,ry,rz)
		setElementVelocity(car,vx,vy,vz)
		setVehicleTurnVelocity(car,0,0,0)
		setElementPosition(npc,x_next,y_next,z_next)
		if check_cols then call(server_coldata,"updateElementColData",car) end
		return maxtime
	else
		setElementPosition(car,x_this,y_this,z_this,true)
		setElementRotation(car,getElementRotation(car))
		setElementVelocity(car,0,0,0)
		setVehicleTurnVelocity(car,0,0,0)
		return maxtime_unm
	end
end

function makeNPCDriveAroundBend(npc,x0,y0,x1,y1,z1,x2,y2,z2,off,maxtime)
	local car = getPedOccupiedVehicle(npc)
	local x_this,y_this,z_this = getElementPosition(car)
	local speed = getNPCDriveSpeed(npc)
	local drive_dist = speed*50*maxtime*0.001
	local p2_this = getAngleInBend(x_this,y_this,x0,y0,x1,y1,x2,y2)/math.pi*2
	local p1_this = 1-p2_this
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)
	local p2_next = p2_this+drive_dist/len
	local p1_next = 1-p2_next
	local x_next,y_next,z_next
	local dirx,diry,dirz,vx,vy,vz
	local maxtime_unm = maxtime
	if p2_next > 1 then
		maxtime = maxtime*(1-p2_this)/(p2_next-p2_this)
		x_next,y_next,z_next = x2,y2,z2
		dirx,diry,dirz = x1-x0,y1-y0,z1-z2
		local dirlen = 1/getDistanceBetweenPoints3D(0,0,0,dirx,diry,dirz)
		dirx,diry,dirz = dirx*dirlen,diry*dirlen,dirz*dirlen
		vx,vy,vz = 0,0,0
	else
		x_next,y_next = getPosFromBend(p2_next*math.pi*0.5,x0,y0,x1,y1,x2,y2)
		z_next = z1*p1_next+z2*p2_next
		local x_next_front,y_next_front = getPosFromBend(p2_next*math.pi*0.5+0.01,x0,y0,x1,y1,x2,y2)
		local z_next_front = z1*(p1_next-0.01)+z2*(p2_next+0.01)

		dirx,diry,dirz = x_next_front-x_next,y_next_front-y_next,z_next_front-z_next
		local dirlen = 1/getDistanceBetweenPoints3D(0,0,0,dirx,diry,dirz)
		dirx,diry,dirz = dirx*dirlen,diry*dirlen,dirz*dirlen
		vx,vy,vz = dirx*speed,diry*speed,dirz*speed
	end
	local model = getElementModel(car)
	local rx,ry,rz = math.deg(math.asin(dirz)),0,-math.deg(math.atan2(dirx,diry))

	local move = true
	if check_cols then
		local box = call(server_coldata,"createModelIntersectionBox",model,x_next,y_next,z_next,rz)
		local boxprev = call(server_coldata,"getElementIntersectionBox",car)
		move = not call(server_coldata,"doesModelBoxIntersect",box,getElementDimension(car),boxprev)
	end
	if move then
		setElementPosition(car,x_next,y_next,z_next,true)
		setElementRotation(car,rx,ry,rz)
		setElementVelocity(car,vx,vy,vz)
		setVehicleTurnVelocity(car,0,0,0)
		setElementPosition(npc,x_next,y_next,z_next)
		if check_cols then call(server_coldata,"updateElementColData",car) end
		return maxtime
	else
		setElementPosition(car,x_this,y_this,z_this,true)
		setElementRotation(car,getElementRotation(car))
		setElementVelocity(car,0,0,0)
		setVehicleTurnVelocity(car,0,0,0)
		return maxtime_unm
	end
end

 

actions_c.Lua

function stopAllNPCActions(npc)
	stopNPCWalkingActions(npc)
	stopNPCWeaponActions(npc)
	stopNPCDrivingActions(npc)

	setPedControlState(npc,"vehicle_fire",false)
	setPedControlState(npc,"vehicle_secondary_fire",false)
	setPedControlState(npc,"steer_forward",false)
	setPedControlState(npc,"steer_back",false)
	setPedControlState(npc,"horn",false)
	setPedControlState(npc,"handbrake",false)
end

function stopNPCWalkingActions(npc)
	setPedControlState(npc,"forwards",false)
	setPedControlState(npc,"sprint",false)
	setPedControlState(npc,"walk",false)
end

function stopNPCWeaponActions(npc)
	setPedControlState(npc,"aim_weapon",false)
	setPedControlState(npc,"fire",false)
end

function stopNPCDrivingActions(npc)
	local car = getPedOccupiedVehicle(npc)
	if not car then return end
	local m = getElementMatrix(car)
	local vx,vy,vz = getElementVelocity(car)
	vy = vx*m[2][1]+vy*m[2][2]+vz*m[2][3]
	setPedControlState(npc,"accelerate",vy < -0.01)
	setPedControlState(npc,"brake_reverse",vy > 0.01)
	setPedControlState(npc,"vehicle_left",false)
	setPedControlState(npc,"vehicle_right",false)
end

function makeNPCWalkToPos(npc,x,y)
	local px,py = getElementPosition(npc)
	setPedCameraRotation(npc,math.deg(math.atan2(x-px,y-py)))
	setPedControlState(npc,"forwards",true)
	local speed = getNPCWalkSpeed(npc)
	setPedControlState(npc,"walk",speed == "walk")
	setPedControlState(npc,"sprint",
		speed == "sprint" or
		speed == "sprintfast" and not getPedControlState(npc,"sprint")
	)
end

function makeNPCWalkAlongLine(npc,x1,y1,z1,x2,y2,z2,off)
	local x,y,z = getElementPosition(npc)
	local p2 = getPercentageInLine(x,y,x1,y1,x2,y2)
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)
	p2 = p2+off/len
	local p1 = 1-p2
	local destx,desty = p1*x1+p2*x2,p1*y1+p2*y2
	makeNPCWalkToPos(npc,destx,desty)
end

function makeNPCWalkAroundBend(npc,x0,y0,x1,y1,x2,y2,off)
	local x,y,z = getElementPosition(npc)
	local len = getDistanceBetweenPoints2D(x1,y1,x2,y2)*math.pi*0.5
	local p2 = getAngleInBend(x,y,x0,y0,x1,y1,x2,y2)/math.pi*2+off/len
	local destx,desty = getPosFromBend(p2*math.pi*0.5,x0,y0,x1,y1,x2,y2)
	makeNPCWalkToPos(npc,destx,desty)
end

function makeNPCShootAtPos(npc,x,y,z)
	local sx,sy,sz = getElementPosition(npc)
	x,y,z = x-sx,y-sy,z-sz
	local yx,yy,yz = 0,0,1
	local xx,xy,xz = yy*z-yz*y,yz*x-yx*z,yx*y-yy*x
	yx,yy,yz = y*xz-z*xy,z*xx-x*xz,x*xy-y*xx
	local inacc = 1-getNPCWeaponAccuracy(npc)
	local ticks = getTickCount()
	local xmult = inacc*math.sin(ticks*0.01 )*1000/math.sqrt(xx*xx+xy*xy+xz*xz)
	local ymult = inacc*math.cos(ticks*0.011)*1000/math.sqrt(yx*yx+yy*yy+yz*yz)
	local mult = 1000/math.sqrt(x*x+y*y+z*z)
	xx,xy,xz = xx*xmult,xy*xmult,xz*xmult
	yx,yy,yz = yx*ymult,yy*ymult,yz*ymult
	x,y,z = x*mult,y*mult,z*mult
	
	setPedAimTarget(npc,sx+xx+yx+x,sy+xy+yy+y,sz+xz+yz+z)
	if isPedInVehicle(npc) then
		setPedControlState(npc,"vehicle_fire",not getPedControlState(npc,"vehicle_fire"))
	else
		setPedControlState(npc,"aim_weapon",true)
		setPedControlState(npc,"fire",not getPedControlState(npc,"fire"))
	end
end

function makeNPCShootAtElement(npc,target)
	local x,y,z = getElementPosition(target)
	local vx,vy,vz = getElementVelocity(target)
	local tgtype = getElementType(target)
	if tgtype == "ped" or tgtype == "player" then
		x,y,z = getPedBonePosition(target,3)
		local vehicle = getPedOccupiedVehicle(target)
		if vehicle then
			vx,vy,vz = getElementVelocity(vehicle)
		end
	end
	vx,vy,vz = vx*6,vy*6,vz*6
	makeNPCShootAtPos(npc,x+vx,y+vy,z+vz)
end

function makeNPCDriveToPos(npc,x,y,z)
	local car = getPedOccupiedVehicle(npc)
	local m = getElementMatrix(car)
	x,y,z = x-m[4][1],y-m[4][2],z-m[4][3]
	local rx,ry,rz =
		x*m[1][1]+y*m[1][2]+z*m[1][3],
		x*m[2][1]+y*m[2][2]+z*m[2][3],
		x*m[3][1]+y*m[3][2]+z*m[3][3]
	if ry <= 0 then
		setPedControlState(npc,"vehicle_left",rx < 0)
		setPedControlState(npc,"vehicle_right",rx >= 0)
	else
		local secondpart = getTickCount()%100
		setPedControlState(npc,"vehicle_left",rx*500/ry < -secondpart)
		setPedControlState(npc,"vehicle_right",rx*500/ry > secondpart)
	end
	local vx,vy,vz = getElementVelocity(car)
	local vrx,vry,vrz =
		vx*m[1][1]+vy*m[1][2]+vz*m[1][3],
		vx*m[2][1]+vy*m[2][2]+vz*m[2][3],
		vx*m[3][1]+vy*m[3][2]+vz*m[3][3]
	local speed
	do
		local x1,y1,z1,x2,y2,z2 = getElementBoundingBox(car)
		z1 = z1+1
		local vx,vy,vz = m[4][1]+m[3][1]*z1,m[4][2]+m[3][2]*z1,m[4][3]+m[3][3]*z1
		local mult = (y2+6)/math.sqrt(x*x+y*y+z*z)
		local dx,dy,dz = x*mult,y*mult,z*mult
		if not isLineOfSightClear(vx,vy,vz,vx+dx,vy+dy,vz+dz,false,true,true,false,true,false,false,car) then
			speed = 0
		else
			speed = getNPCDriveSpeed(npc)*math.sin(math.pi*0.5-math.atan(math.abs(rx/ry))*0.75)
		end
	end
	setPedControlState(npc,"accelerate",vry < speed)
	setPedControlState(npc,"brake_reverse",vry > speed*1.1)
end

function makeNPCDriveAlongLine(npc,x1,y1,z1,x2,y2,z2,off)
	local car = getPedOccupiedVehicle(npc)
	local x,y,z = getElementPosition(car)
	local p2 = getPercentageInLine(x,y,x1,y1,x2,y2)
	local len = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2)
	p2 = p2+off/len
	local p1 = 1-p2
	local destx,desty,destz = p1*x1+p2*x2,p1*y1+p2*y2,p1*z1+p2*z2
	makeNPCDriveToPos(npc,destx,desty,destz)
end

function makeNPCDriveAroundBend(npc,x0,y0,x1,y1,z1,x2,y2,z2,off)
	local car = getPedOccupiedVehicle(npc)
	local x,y,z = getElementPosition(car)
	local len = getDistanceBetweenPoints2D(x1,y1,x2,y2)*math.pi*0.5
	local p2 = getAngleInBend(x,y,x0,y0,x1,y1,x2,y2)/math.pi*2
	p2 = math.max(0,math.min(1,p2))
	p2 = p2+off/len
	local destx,desty = getPosFromBend(p2*math.pi*0.5,x0,y0,x1,y1,x2,y2)
	local destz = (1-p2)*z1+p2*z2
	makeNPCDriveToPos(npc,destx,desty,destz)
end

Where i can add it? 

I need jump for focused zombies on the player.
Zombies jump when they can't see the player and are not focused on him.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.