Jump to content

How do i remove warnings like these?


Bean666

Recommended Posts

i'm always getting a debug output "expected element at argument 1, got boolean", whenever a bot spawns with "chasing" mode, although there's not any problems with it but it's kinda irritating everytime a botspawns it gives an output warning, is there anyway to remove this warning? , its the getElementPosition(player) line, this is from slothbot

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

 

Link to post
  • Moderators
5 minutes ago, Bean666 said:

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)

For example:

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)

To:

local player = getElementData(source, "leader") 
if isElement(player) then
	local oldTx, oldTy, oldTz = getElementPosition(player) 
	local oldPx, oldPy, oldPz = getElementPosition(source) 
	
	setTimer(follow_move, 800, 1, source, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
end
setTimer(follow_enemy_check, 500, 1, source) 

 

 

 

Link to post
1 hour ago, IIYAMA said:

For example:



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)

To:



local player = getElementData(source, "leader") 
if isElement(player) then
	local oldTx, oldTy, oldTz = getElementPosition(player) 
	local oldPx, oldPy, oldPz = getElementPosition(source) 
	
	setTimer(follow_move, 800, 1, source, oldPx, oldPy, oldPz, oldPx, oldPy, oldPz)
end
setTimer(follow_enemy_check, 500, 1, source) 

 

 

 

this fixed the error but now idk why i'm getting these when they start chasing me

uIAAtEq.png

i've never modified anything just those u sent me, and i did it well, no bugs, but now those error shows up, there seems to be nothing wrong as well

The clientside that has error on line 97

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
--THIS IS LINE 97 	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)
					setTimer(chase_move, 700, 1, ped, oldTx, oldTy, oldTz, px, py, pz)
				end
			end
		end
	end
end

also in server this is line 251 and 252, there really seems to be nothing wrong:

function chase_move(ped, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz) -- function name that has the oldTx variable, i cant post the full chase move function ,its too long, but if u insist i can send it 

local pdistance = (getDistanceBetweenPoints3D(oldPx, oldPy, oldPz, px, py, pz)) -- line 251
if (pdistance < 1.2) then -- line 252

 

Edited by Bean666
  • Like 1
Link to post
  • Moderators
5 minutes ago, Bean666 said:

if (isElement(ped)) then

 

Basic validation: (works in most cases just fine)

if isElement(ped) and oldTx and oldTy and oldTz and oldPx and oldPy and oldPz then

 

Advanced validation: (recommended using this when the data comes from user input, export functions or database. But using it for here is also fine.)

if isElement(ped) and type(oldTx) == "number" and type(oldTy) == "number" and type(oldTz) == "number" and type(oldPx) == "number" and type(oldPy) == "number" and type(oldPz) == "number" then

 

 

 

Link to post
13 minutes ago, IIYAMA said:

 

Basic validation: (works in most cases just fine)




if isElement(ped) and oldTx and oldTy and oldTz and oldPx and oldPy and oldPz then

 

Advanced validation: (recommended using this when the data comes from user input, export functions or database. But using it for here is also fine.)




if isElement(ped) and type(oldTx) == "number" and type(oldTy) == "number" and type(oldTz) == "number" and type(oldPx) == "number" and type(oldPy) == "number" and type(oldPz) == "number" then

 

 

 

it gave no more errors, but they don't move anymore. anyway the error of those boolean numbers only happens when close with the bots but it spams

Edited by Bean666
Link to post
  • Moderators
32 minutes ago, Bean666 said:

setTimer(chase_move, 700, 1, ped, oldTx, oldTy, oldTz, px, py, pz)

You can also move the oldTx, oldTy, oldTz, px, py, pz validation to here.

32 minutes ago, Bean666 said:

else

Or here, line 96

@Bean666

Edited by IIYAMA
Link to post
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)
				if oldTx and oldTy and oldTz and oldPx and oldPy and oldPz then
					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)
					setTimer(chase_move, 700, 1, ped, oldTx, oldTy, oldTz, px, py, pz)
				end
			end
			end
		end
	end
end

just did this, its fine at the start, no errors, but hell after a few seconds it gives massive lag. they also go crazy

EDIT: oops my bad i removed the else, but no lags now, but they go crazy after a player dies, if htey just spawned they're fine, but when player dies and comes back, they dont shoot anymore,

Edited by Bean666
Link to post
  • Moderators
10 minutes ago, Bean666 said:

just did this, its fine at the start, no errors, but hell after a few seconds it gives massive lag. they also go crazy

There was an:

if

else

end

 

And you changed it to an:

if

    if

    end

end

 

 

While you probably need an :

if

-- element data

else

-- element data

   if -- validation

   end

end

 

Not sure if that fixes everything, it is still a puzzle.

 

 

Link to post

missed somethings serverside, forgot to add the check on some parts, thats why they were acting crazy, but thankyou you helped me once again ❤️ 

Edited by Bean666
  • Like 1
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...