Rettox Posted July 13, 2017 Share Posted July 13, 2017 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
FlyingSpoon Posted July 13, 2017 Share Posted July 13, 2017 (edited) 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 July 13, 2017 by raysmta Link to comment
Rettox Posted July 13, 2017 Author Share Posted July 13, 2017 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. Link to comment
Tails Posted July 13, 2017 Share Posted July 13, 2017 What line is it in the code? It's definitely not on line 15. Might be an error in slothbot? Are you sure you're passing the right arguments? Link to comment
Simple0x47 Posted July 14, 2017 Share Posted July 14, 2017 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
Rettox Posted July 15, 2017 Author Share Posted July 15, 2017 I have solved it. On some line i had a variable that was not a local one, so it was calling it (i don't know why it was even doing it lol) (the global variable). Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now