Jump to content

[HELP] Slothbot. again.


Bean666

Recommended Posts

Hello, This has been bugging me for quite a while now, and it's even weirder as this happens not always, sometimes only, but that is the flaw here, I managed to edit slothbot a bit, making the boss run when he's far and when he's near setting ped animation, thats all I did and since the original slothbot was giving errors, and I was not happy about it, so I edited it a bit, to remove those showing errors, here are the errors: 

so I managed to remove the errors by doing checks where the errors show, bot works perfectly, but there are times like these, happening, see video below:

Now, here are the parts of the vanilla slothbot code I modified, none other, just those. can you tell me which part makes him behave like that? its weird since it doesn't always happen, just barely but its still a big flaw:

C SIDE: ALL PARTS I EDITED, and i put detailed marks where I modified it. please try and compare to the vanilla slothbot to see what's wrong. Thankyou. i

NOTE: I suggest checking this on Notepad++ since the code is too big to fit on this MTA forums screen. Any help appreciated, thankyou.!

Clientside:
function changestatus(dataName)
	if getElementType(source) == "ped" and dataName == "status" and (getElementData(source, "slothbot") == true) then
		if (getElementData(source, "status") == "chasing") then
			local player = getElementData(source, "target")
			if isElement(player) then -- THIS I MODIFIED, ADDED CHECK
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(chase_aim, 80, 1, source)
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
			setTimer(chase_shoot, 1500, 1, source)
			else 
			setTimer(chase_aim, 80, 1, source)
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
			setTimer(chase_shoot, 1500, 1, source)
			end
		elseif (getElementData(source, "status") == "hunting") then
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(enemy_check, 600, 1, source)
			 -- starts scanning for enemies
			setTimer(hunt_move, 800, 1, source, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "following") then
			local player = getElementData(source, "leader")
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(follow_enemy_check, 500, 1, source)
			setTimer(follow_move, 800, 1, source, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "waiting") then
			setTimer(wait_enemy_check, 500, 1, source)
		elseif (getElementData(source, "status") == "guarding") then
			setTimer(guard_enemy_check, 800, 1, source)
			 -- starts scanning for enemies
			setTimer(guard_move, 400, 1, source)
		end
	end
end
addEventHandler("onClientElementDataChange", getRootElement(), changestatus)

function chase_move(ped, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
	if (isElement(ped)) then
		local thetarget = getElementData(ped, "target")
		if (getElementData(ped, "status") == "chasing") and (isElement(thetarget)) and (getElementData(ped, "slothbot") == true)
		 then
			local pedhp = getElementHealth(ped)
			local tarhp = getElementHealth(thetarget)
			if pedhp > 0 and tarhp > 0 then
				local tx, ty, tz = getElementPosition(thetarget)
				local px, py, pz = getElementPosition(ped)
				local isclear = isLineOfSightClear(px, py, pz + .6, tx, ty, tz + .6, true, false, false, true, false, false, false)
				local angle = (360 - math.deg(math.atan2((tx - px), (ty - py)))) % 360 --set the peds angle to the target
				setPedRotation(ped, angle)
				if (isclear == true) then -- if the ped can see the target
					local angle = (360 - math.deg(math.atan2((tx - px), (ty - py)))) % 360 --set the peds angle to the target
					setPedRotation(ped, angle)
					setElementData(ped, "seestarget", true)
					setTimer(chase_move, 700, 1, ped, tx, ty, tz, px, py, pz)
				else
					local angle = (360 - math.deg(math.atan2((oldTx - px), (oldTy - py)))) % 360 --set the peds angle to the target
					setPedRotation(ped, angle)
					setElementData(ped, "seestarget", false)
					if oldTx and oldTy and oldTz and oldPx and oldPy and oldPz then -- THIS I MODIFIED, ADDED CHECK
					setTimer(chase_move, 700, 1, ped, oldTx, oldTy, oldTz, px, py, pz)
					end
				end
			end
		end
	end
end

function resourcestart()
	local players = getElementsByType("player")
	if #players == 1 then
		local peds = getElementsByType("ped")
		for theKey, thePed in ipairs(peds) do
			if (getElementData(thePed, "slothbot") == true) then
				triggerServerEvent("onClientSetBotController", thePed, thePed)
				local pedstatus = getElementData(thePed, "stasisstatus")
				if (pedstatus ~= false) then
					setElementData(thePed, "status", pedstatus)
					setElementData(thePed, "stasisstatus", nil)
				else
					setElementData(thePed, "status", "hunting")
				end
			end
		end
	else
		local peds = getElementsByType("ped")
		for theKey, thePed in ipairs(peds) do
			if (getElementData(thePed, "status") == "chasing") then
				local player = getElementData(thePed, "target")
				if isElement(player) then   -- THIS I MODIFIED, ADDED CHECK
				local oldTx, oldTy, oldTz = getElementPosition(player)
				local oldPx, oldPy, oldPz = getElementPosition(thePed)
				setTimer(chase_aim, 80, 1, thePed)
				setTimer(chase_move, 700, 1, thePed, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
				setTimer(chase_shoot, 1500, 1, thePed)
				else 
				setTimer(chase_aim, 80, 1, source)
			    setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
			    setTimer(chase_shoot, 1500, 1, source)
				end
			elseif (getElementData(thePed, "status") == "hunting") then
				local oldPx, oldPy, oldPz = getElementPosition(thePed)
				setTimer(enemy_check, 600, 1, thePed)
				 -- starts scanning for enemies
				setTimer(hunt_move, 800, 1, thePed, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
			elseif (getElementData(thePed, "status") == "following") then
				local player = getElementData(thePed, "leader")
				local oldTx, oldTy, oldTz = getElementPosition(player)
				local oldPx, oldPy, oldPz = getElementPosition(thePed)
				setTimer(follow_enemy_check, 500, 1, thePed)
				setTimer(follow_move, 800, 1, thePed, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
			elseif (getElementData(thePed, "status") == "waiting") then
				setTimer(wait_enemy_check, 500, 1, thePed)
			elseif (getElementData(thePed, "status") == "guarding") then
				setTimer(guard_enemy_check, 800, 1, thePed)
				 -- starts scanning for enemies
				setTimer(guard_move, 400, 1, thePed)
			end
		end
	end
end
addEventHandler("onClientResourceStart", resourceRoot, resourcestart)

 

Server Side same with C side, here are some parts I edited with marks on them:

All Marks are - "ADDED CHECK HERE" and "ADDED ELSE HERE"

function changestatus(dataName)
	if getElementType(source) == "ped" and dataName == "status" and (getElementData(source, "slothbot") == true) then
		if (getElementData(source, "status") ~= "stasis") then
			local allshapes = getElementsByType("colshape")
			for SKey, theShape in ipairs(allshapes) do
				if (isElement(theShape)) then
					if getElementParent(theShape) == source then
						destroyElement(theShape) -- removes the target colshape that the ped was running towards in hunt mode
					end
				end
			end
		end
		if (getElementData(source, "status") == "chasing") then
			local player = getElementData(source, "target")
			if isElement(player) then  -- THIS I MODIFIED ADDED CHECK HERE
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
			else 
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
			end
		elseif (getElementData(source, "status") == "hunting") then
			setTimer(findPath, 200, 1, source)
		elseif (getElementData(source, "status") == "waiting") then
			setTimer(wait_mode, 200, 1, source)
		elseif (getElementData(source, "status") == "following") then
			local player = getElementData(source, "leader")
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(follow_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "guarding") then
			local px, py, pz = getElementPosition(source)
			guard_move(source, px, py, pz)
		end
	end
end
addEventHandler("onElementDataChange", getRootElement(), changestatus)

function chase_move(ped, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
	if (isElement(ped)) then
		if (getElementData(ped, "status") == "chasing") and (getElementData(ped, "slothbot") == true) then
			local px, py, pz = getElementPosition(ped)
			local player = getElementData(ped, "target")
			if (isElement(player)) then
				local tx, ty, tz = getElementPosition(player)
				local pedhp = getElementHealth(ped)
				if getElementType(player) == "player" then
					if pedhp > 0 and (isPedDead(player) == false) then
						if (getElementData(ped, "seestarget") == true) then -- if the ped can see the target
							local inrange = 0
							local tdist = (getDistanceBetweenPoints3D(px, py, pz, tx, ty, tz))
							if (getPedWeaponSlot(ped) == 0) then -- fists
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							    if tdist > 5 then 
								setPedAnimation ( ped, "PED", "sprint_civi", -1, true, true, true)
								elseif tdist < 5 then
								setPedAnimation ( ped)
								end
							elseif (getPedWeaponSlot(ped) == 1) then -- melee
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 2) then -- pistols
								if tdist < 14 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 3) then -- shotguns
								if tdist < 10 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 4) then -- submachine
								if tdist < 7 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 5) then -- assault
								if tdist < 14 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 6) then --rifles
								if tdist < 22 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 7) then --heavy
								if tdist < 12 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 8) then --projectiles (dont work afaik)
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 9) then -- special
								if tdist < 2 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 10) then -- gifts
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 11) then -- special2
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 12) then -- detonator
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							else -- probably useless part.
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							end
							if oldPx and oldPy and oldPz and px and py and pz then -- THIS I MODIFIED ADDED CHECK HERE
							local pdistance = (getDistanceBetweenPoints3D(oldPx, oldPy, oldPz, px, py, pz))
							if (pdistance < 1) and (inrange == 0) then -- if the ped is stuck but not in range of the player
								local weap = getPedWeaponSlot(ped)
								if (weap == 1) or (weap == 7) then
									setPedWeaponSlot(ped, 0)
									triggerClientEvent("bot_Jump", ped)
									setTimer(setPedWeaponSlot, 850, 1, ped, weap)
								else
									triggerClientEvent("bot_Jump", ped)
								end
								setTimer(chase_move, 600, 1, ped, tx, ty, tz, px, py, pz)
							else
								setTimer(chase_move, 600, 1, ped, tx, ty, tz, px, py, pz)
							end
							else
							setTimer(chase_move, 1200, 1, ped, tx, ty, tz, px, py, pz) -- ADDED AN ELSE HERE OF IF OLD PX, etc
							end
						else -- if the ped cant see the target
							if oldPx and oldPy and oldPz and px and py and pz then -- ADDED A CHECK HERE
							triggerClientEvent("bot_Forwards", ped)
							local pdistance = (getDistanceBetweenPoints3D(oldPx, oldPy, oldPz, px, py, pz))
							if (pdistance < 1.2) then --if the ped is stuck
								local decide = math.random(1, 7) -- randomly decide to
								if decide == 1 then -- give up chasing and go back on the hunt
									setTimer(beginsearch, 800, 1, ped)
								elseif decide < 4 then -- jump
									local weap = getPedWeaponSlot(ped)
									if (weap == 1) or (weap == 7) then
										setPedWeaponSlot(ped, 0)
										triggerClientEvent("bot_Jump", ped)
										setTimer(setPedWeaponSlot, 850, 1, ped, weap)
									else
										triggerClientEvent("bot_Jump", ped)
									end
									setTimer(chase_move, 600, 1, ped, tx, ty, tz, px, py, pz)
								else -- randomly turn a new direction, walk a bit, then resume
									local randomangle = math.random(1, 360)
									setPedRotation(ped, randomangle)
									setTimer(chase_move, 1200, 1, ped, tx, ty, tz, px, py, pz)
								end
								else
								setTimer(chase_move, 1200, 1, ped, tx, ty, tz, px, py, pz) -- ADDED AN ELSE HERE 
								end
							else -- if the ped isnt stuck
							if oldPx and oldPy and oldPz and px and py and pz then -- ADDED A CHECK HERE
								local distance = (getDistanceBetweenPoints3D(px, py, pz, oldTx, oldTy, oldTz))
								if (distance > 5) then -- if the ped hasnt reached its target
									local flatdist = (getDistanceBetweenPoints2D(px, py, tx, ty))
									if flatdist < 2 then -- if the ped hasnt reached its target, but is directly below or above (for multiple levels in maps)
										setTimer(beginsearch, 800, 1, ped)
									else -- keep going
										local angle = (360 - math.deg(math.atan2((oldTx - px), (oldTy - py)))) % 360
										--	setPedRotation( ped, angle )
										setTimer(chase_move, 600, 1, ped, oldTx, oldTy, oldTz, px, py, pz)
									end
								else -- if the ped has reached its target ( reached the spot it last saw you standing in)
									setTimer(beginsearch, 800, 1, ped)
								end
							  end
							end
						end
						else -- ADDED AN ELSE HERE IF CHECK DONT EXIST, DO CHASE_MOVE
					  setTimer(chase_move, 1200, 1, ped, tx, ty, tz, px, py, pz)
					end
				elseif getElementType(player) == "ped" then
					if pedhp > 0 and (getElementHealth(player) > 0) then
						if (getElementData(ped, "seestarget") == true) then -- if the ped can see the target
							local inrange = 0
							local tdist = (getDistanceBetweenPoints3D(px, py, pz, tx, ty, tz))
							if (getPedWeaponSlot(ped) == 0) then -- fists
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
								if tdist > 5 then 
								setPedAnimation ( ped, "PED", "sprint_civi", -1, true, true, true)
								elseif tdist < 5 then
								setPedAnimation ( ped)
								end
							elseif (getPedWeaponSlot(ped) == 1) then -- melee
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 2) then -- pistols
								if tdist < 14 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 3) then -- shotguns
								if tdist < 10 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 4) then -- submachine
								if tdist < 8 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 5) then -- assault
								if tdist < 17 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 6) then --rifles
								if tdist < 22 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 7) then --heavy
								if tdist < 12 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 8) then --projectiles (dont work afaik)
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 9) then -- special
								if tdist < 2 then
									triggerClientEvent("bot_Stop", ped)
									inrange = 1
								else
									triggerClientEvent("bot_Forwards", ped)
									inrange = 0
								end
							elseif (getPedWeaponSlot(ped) == 10) then -- gifts
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 11) then -- special2
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							elseif (getPedWeaponSlot(ped) == 12) then -- detonator
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							else -- probably useless part.
								triggerClientEvent("bot_Forwards", ped)
								inrange = 0
							end
							if oldPx and oldPy and oldPz and px and py and pz then -- ADDED A CHECK HERE
							local pdistance = (getDistanceBetweenPoints3D(oldPx, oldPy, oldPz, px, py, pz))
							if (pdistance < 1) and (inrange == 0) then -- if the ped is stuck but not in range of the target
								local weap = getPedWeaponSlot(ped)
								if (weap == 1) or (weap == 7) then
									setPedWeaponSlot(ped, 0)
									triggerClientEvent("bot_Jump", ped)
									setTimer(setPedWeaponSlot, 850, 1, ped, weap)
								else
									triggerClientEvent("bot_Jump", ped)
								end
								setTimer(chase_move, 700, 1, ped, tx, ty, tz, px, py, pz)
							else
								setTimer(chase_move, 700, 1, ped, tx, ty, tz, px, py, pz)
							end
							else
							setTimer(chase_move, 700, 1, ped, tx, ty, tz, px, py, pz) -- ADDED AN ELSE HERE DO CHASEMOVE IF NO CHECK - BEAN
						    end
						else
						if oldPx and oldPy and oldPz and px and py and pz then -- ADDED A CHECK HERE
							local pdistance = (getDistanceBetweenPoints3D(oldPx, oldPy, oldPz, px, py, pz))
							if (pdistance < 1.3) then --if the ped is stuck
								local decide = math.random(1, 7) -- randomly decide to
								if decide == 1 then -- give up chasing and go back on the hunt
									setTimer(beginsearch, 800, 1, ped)
								elseif decide < 4 then -- jump
									local weap = getPedWeaponSlot(ped)
									if (weap == 1) or (weap == 7) then
										local slot = getPedWeaponSlot(ped)
										setPedWeaponSlot(ped, 0)
										triggerClientEvent("bot_Jump", ped)
										setTimer(setPedWeaponSlot, 850, 1, ped, slot)
									else
										triggerClientEvent("bot_Jump", ped)
									end
									setTimer(chase_move, 700, 1, ped, tx, ty, tz, px, py, pz)
								else -- randomly turn a new direction, walk a bit, then resume
									local randomangle = math.random(1, 360)
									setPedRotation(ped, randomangle)
									setTimer(chase_move, 1200, 1, ped, tx, ty, tz, px, py, pz)
								end
							else -- if the ped isnt stuck
								local distance = (getDistanceBetweenPoints3D(px, py, pz, oldTx, oldTy, oldTz))
								if (distance > 5) then -- if the ped hasnt reached its target
									local flatdist = (getDistanceBetweenPoints2D(px, py, tx, ty))
									if flatdist < 2 then -- if the ped hasnt reached its target, but is directly below or above (for multiple levels in maps)
										setTimer(beginsearch, 800, 1, ped)
									else -- keep going
										setTimer(chase_move, 700, 1, ped, oldTx, oldTy, oldTz, px, py, pz)
									end
								else -- if the ped has reached its target ( reached the spot it last saw you standing in)
									setTimer(beginsearch, 800, 1, ped)
								end
							end
							else -- ADDED AN ELSE HERE, IF NO CHECK, CHASE_MOVE - BEAN
							setTimer(chase_move, 1200, 1, ped, tx, ty, tz, px, py, pz)
						   end
						end
					else
						setTimer(beginsearch, 800, 1, ped)
					end
				end
			else
				setTimer(beginsearch, 800, 1, ped)
			end
		end
	end
end

NOTE: this seldom happens so its probably I missed one small thing or did one thing wrong! and I only added checks to those lines that gave errors!

I have been trying to fix this many times but now I just cant seem to fix it no matter how hard I tried, and decided to ask for help here.

Edited by Bean666
Link to comment

You've added too many else, most of them you don't need, try removing all of them and only let checks like if isElement(ped) then don't need else as if there's no element you don't need to make that element move, got me?

Also read this tuto by YIAMA about debugging (it might help you a little):

 

Link to comment
9 minutes ago, Tekken said:

You've added too many else, most of them you don't need, try removing all of them and only let checks like if isElement(ped) then don't need else as if there's no element you don't need to make that element move, got me?

Also read this tuto by YIAMA about debugging (it might help you a little):

 

I added else since when I didn't, they didnt recognize me and won't attack me. I've always did the checks without the else, they just won't attack me.

But okay i'll try once again and remove the elses,

Edited by Bean666
Link to comment
2 minutes ago, Tekken said:

try adding debug lines such as outputChatBox(tostring(getElementData(ped, "status")))

sometimes things gets clog up in such old and complex scripts

okay i removed an else, but see if this code would work fine? I removed the else and the extra chase_move function and just added the check instead, this is mostly all the same on the chase_move function on serverside, there are multiple lines like these.

if oldPx and oldPy and oldPz and px and py and pz then
local pdistance = (getDistanceBetweenPoints3D(oldPx, oldPy, oldPz, px, py, pz))
	if (pdistance < 1) and (inrange == 0) then -- if the ped is stuck but not in range of the player
	local weap = getPedWeaponSlot(ped)
	if (weap == 1) or (weap == 7) then
	setPedWeaponSlot(ped, 0)
		triggerClientEvent("bot_Jump", ped)
		setTimer(setPedWeaponSlot, 850, 1, ped, weap)
		else
		triggerClientEvent("bot_Jump", ped)
	end
	setTimer(chase_move, 600, 1, ped, tx, ty, tz, px, py, pz)
	else
	setTimer(chase_move, 600, 1, ped, tx, ty, tz, px, py, pz)
	end
    end

 

Link to comment
7 minutes ago, Tekken said:

An update? You have took away the else's ?

yes I removed the elses I've put on the first code, first they were fine but now there's something wrong again hahaha, it seems like the bots are not updating when I die:

I also edited the changestatus and removed the else

function changestatus(dataName)
	if getElementType(source) == "ped" and dataName == "status" and (getElementData(source, "slothbot") == true) then
		if (getElementData(source, "status") == "chasing") then
			local player = getElementData(source, "target")
			if isElement(player) then -- HERE
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(chase_aim, 80, 1, source)
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
			setTimer(chase_shoot, 1500, 1, source)
			end
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "hunting") then
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(enemy_check, 600, 1, source)
			 -- starts scanning for enemies
			setTimer(hunt_move, 800, 1, source, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "following") then
			local player = getElementData(source, "leader")
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(follow_enemy_check, 500, 1, source)
			setTimer(follow_move, 800, 1, source, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "waiting") then
			setTimer(wait_enemy_check, 500, 1, source)
		elseif (getElementData(source, "status") == "guarding") then
			setTimer(guard_enemy_check, 800, 1, source)
			 -- starts scanning for enemies
			setTimer(guard_move, 400, 1, source)
		end
	end
end
addEventHandler("onClientElementDataChange", getRootElement(), changestatus)

 

server

function changestatus(dataName)
	if getElementType(source) == "ped" and dataName == "status" and (getElementData(source, "slothbot") == true) then
		if (getElementData(source, "status") ~= "stasis") then
			local allshapes = getElementsByType("colshape")
			for SKey, theShape in ipairs(allshapes) do
				if (isElement(theShape)) then
					if getElementParent(theShape) == source then
						destroyElement(theShape) -- removes the target colshape that the ped was running towards in hunt mode
					end
				end
			end
		end
		if (getElementData(source, "status") == "chasing") then
			local player = getElementData(source, "target")
			if isElement(player) then -- HERE
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
			end
			setTimer(chase_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "hunting") then
			setTimer(findPath, 200, 1, source)
		elseif (getElementData(source, "status") == "waiting") then
			setTimer(wait_mode, 200, 1, source)
		elseif (getElementData(source, "status") == "following") then
			local player = getElementData(source, "leader")
			local oldTx, oldTy, oldTz = getElementPosition(player)
			local oldPx, oldPy, oldPz = getElementPosition(source)
			setTimer(follow_move, 700, 1, source, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz)
		elseif (getElementData(source, "status") == "guarding") then
			local px, py, pz = getElementPosition(source)
			guard_move(source, px, py, pz)
		end
	end
end
addEventHandler("onElementDataChange", getRootElement(), changestatus)

 

Edited by Bean666
Link to comment
20 minutes ago, Tekken said:

Well you should make them wait when you die

what do you mean, set their status to wait? that's already on the chase_move function I think its just the checks, whenever I tried to fix the debug errors showing up by adding checks they start to act weird

I think i've found the problem but let's see again if he acts like this, basically here:

else -- if the ped isnt stuck
if px and py and pz and oldTx and oldTy and oldTz then -- I had this on if oldPx and oldPy and oldPz and px and py and pz, which does not match the distance variable
	local distance = (getDistanceBetweenPoints3D(px, py, pz, oldTx, oldTy, oldTz))
		if (distance > 5) then -- if the ped hasnt reached its target
			local flatdist = (getDistanceBetweenPoints2D(px, py, tx, ty))
			if flatdist < 2 then -- if the ped hasnt reached its target, but is directly below or above (for multiple levels in maps)
					setTimer(beginsearch, 800, 1, ped)
					else -- keep going
					local angle = (360 - math.deg(math.atan2((oldTx - px), (oldTy - py)))) % 360
					setTimer(chase_move, 600, 1, ped, oldTx, oldTy, oldTz, px, py, pz)
						end
						else -- if the ped has reached its target ( reached the spot it last saw you standing in)
						setTimer(beginsearch, 800, 1, ped)
						end
				 end
		end
end
end

EDIT: but yeah they started walking again when I died despite having the check corrected, maybe put the setTimer(chase_move) after the check? im realy confused

Edited by Bean666
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...