Jump to content

Unlogical error occurs


Rettox

Recommended Posts

Hello guys... I have big problem with my em... Mr. Error....

A weird error occurs when checking for player level (comparing player's wanted level with number. But huh. tonumber(wl) doesn't work either, where wl stands for player's level...)

Basically, im going to paste full police code for all servers, so you can use it on your server (after fixing it, of course)

criminals = createTeam ("Criminals", 255, 0, 0 )
citizens = createTeam ("Citizens", 0, 0, 255 )
-- Instruções para eles não atacarem-se entre si (ou não)
setTeamFriendlyFire (getTeamFromName("Citizens"), false )
setTeamFriendlyFire (getTeamFromName("Criminals"), false )

-- função que cria o policial patrulhando a cada 4min

setTimer(function()
	if getPlayerCount() > 0 then
		for i, players in ipairs(getElementsByType("player")) do 
			if getPlayerWantedLevel(players) == 6 then
				x, y, z = getElementPosition(players)
				dim = getElementDimension(players)
				addx = math.random(-15,15)
				addy = math.random(-15,15)
           		spawnCops(x+addx,y+addy,z,players)
    		end
    	end
	end
end,30000,0)

function spawnCops(x,y,z,thePlayer)
	local dim = 0
    call(getResourceFromName("slothbot"), "spawnBot") cop1 = exports.slothbot:spawnBot (x, y, z, 90, 265, 0, dim, getTeamFromName("Citizens"), 22)
    call(getResourceFromName("slothbot"), "setBotChase") cp1 = exports.slothbot:setBotChase (cop1, thePlayer)
end

setTimer(function()
if getPlayerCount() > 0 then -- checa se tem alguém jogando
	local players = getElementsByType ( "player" ) -- get a table of all the players in the server
	for theKey,thePlayer in ipairs(players) do
   		local wlevel = getPlayerWantedLevel(thePlayer)
    	wlevel = wlevel - 1
    	setPlayerWantedLevel(thePlayer, tonumber(wlevel))
    end
end
end, 60000,0)

setTimer(function()
local peds = getElementsByType ( "ped" ) -- get a table of all the players in the server
for theKey,thePed in ipairs(peds) do
	call(getResourceFromName("slothbot"), "isPedBot") is = exports.slothbot:isPedBot(thePed)
    if is then
    	killPed(thePed)
    end
end
end, 150000, 0)

also i have no idea why the code is shaped so weirdly in here...

ERROR: [string "?"]:15: attempt to call global 'type' (a number value) - WTF? What does that mean? To which line it applies? Why it appears? WTF???!

Link to comment

I think math.random only accepts number 1 and above.

  • math.random() with no arguments generates a real number between 0 and 1.
  • math.random(upper) generates integer numbers between 1 and upper.
  • math.random(lower, upper) generates integer numbers between lower and upper.

Might be wrong.

Edited by raysmta
Link to comment
17 minutes ago, raysmta said:

I think math.random only accepts number 1 and above.

  • math.random() with no arguments generates a real number between 0 and 1.
  • math.random(upper) generates integer numbers between 1 and upper.
  • math.random(lower, upper) generates integer numbers between lower and upper.

Might be wrong.

ofc you're wrong. :D

Link to comment
21 hours ago, Rettox said:

Hello guys... I have big problem with my em... Mr. Error....

A weird error occurs when checking for player level (comparing player's wanted level with number. But huh. tonumber(wl) doesn't work either, where wl stands for player's level...)

Basically, im going to paste full police code for all servers, so you can use it on your server (after fixing it, of course)


criminals = createTeam ("Criminals", 255, 0, 0 )
citizens = createTeam ("Citizens", 0, 0, 255 )
-- Instruções para eles não atacarem-se entre si (ou não)
setTeamFriendlyFire (getTeamFromName("Citizens"), false )
setTeamFriendlyFire (getTeamFromName("Criminals"), false )

-- função que cria o policial patrulhando a cada 4min

setTimer(function()
	if getPlayerCount() > 0 then
		for i, players in ipairs(getElementsByType("player")) do 
			if getPlayerWantedLevel(players) == 6 then
				x, y, z = getElementPosition(players)
				dim = getElementDimension(players)
				addx = math.random(-15,15)
				addy = math.random(-15,15)
           		spawnCops(x+addx,y+addy,z,players)
    		end
    	end
	end
end,30000,0)

function spawnCops(x,y,z,thePlayer)
	local dim = 0
    call(getResourceFromName("slothbot"), "spawnBot") cop1 = exports.slothbot:spawnBot (x, y, z, 90, 265, 0, dim, getTeamFromName("Citizens"), 22)
    call(getResourceFromName("slothbot"), "setBotChase") cp1 = exports.slothbot:setBotChase (cop1, thePlayer)
end

setTimer(function()
if getPlayerCount() > 0 then -- checa se tem alguém jogando
	local players = getElementsByType ( "player" ) -- get a table of all the players in the server
	for theKey,thePlayer in ipairs(players) do
   		local wlevel = getPlayerWantedLevel(thePlayer)
    	wlevel = wlevel - 1
    	setPlayerWantedLevel(thePlayer, tonumber(wlevel))
    end
end
end, 60000,0)

setTimer(function()
local peds = getElementsByType ( "ped" ) -- get a table of all the players in the server
for theKey,thePed in ipairs(peds) do
	call(getResourceFromName("slothbot"), "isPedBot") is = exports.slothbot:isPedBot(thePed)
    if is then
    	killPed(thePed)
    end
end
end, 150000, 0)

also i have no idea why the code is shaped so weirdly in here...

ERROR: [string "?"]:15: attempt to call global 'type' (a number value) - WTF? What does that mean? To which line it applies? Why it appears? WTF???!

So basically it says somewhere the var type is being called, and in this code there's not a 'type' variable. So what if you post all the scripts that are joint to this one like the slothbot.

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...