When I try to run a function the server gives a lua panic error and crashes.
[CODE]function police_addCop(ply, _, args)
testfunc("xd", "dab")
if #args ~= 1 then
sendMessage(ply, "Wrong use of command! police_addcop <insert steamid64 here>")
return
end
if not checkAddCop(ply) then
sendMessage(ply, "Moron")
return
end
local callerid = tostring(ply:SteamID64())
local target = args[1]
local targetid = targetIsValid(target)
if targetid ~= nil then
if policedb_userRank(targetid) == 0 then
policedb_addOfficer(targetid, callerid)
return
else
return
end
else
sendMessage(ply, "Give me a name/SteamID/SteamID64 that I can use.")
return
end
if policedb_userRank(targetid) == 1 then
sendMessage(ply, "The target has successfully been added to the database!")
else
sendMessage(ply, "The target couldn't be added. Maybe the developper is just bad?")
end
end
concommand.Add("police_addcop", police_addCop)[/CODE]
So when I try to run the policedb_addOfficer function it gives a lua panic error.
I tried to run a simple test function and that didn't work either.
Though the function policedb_userRank that is in the same file does work.
Thank you for your time.
TFK
It might be this part:
[CODE]
local callerid = tostring(ply:SteamID64())
[/CODE]
Sorry for my stupid question, but why do you need it to be a string anyway? Couldn't you make this function:
[CODE]
policedb_addOfficer
[/CODE]
Accept a number instead?
[QUOTE=MPan1;52426511]It might be this part:
[CODE]
local callerid = tostring(ply:SteamID64())
[/CODE]
Sorry for my stupid question, but why do you need it to be a string anyway? Couldn't you make this function:
[CODE]
policedb_addOfficer
[/CODE]
Accept a number instead?[/QUOTE]
The panic occurs when the function policedb_addOfficer is called. And if I make a function that just prints hello it crashes to.
Btw: It must be a string because the number is too large for an int.
Why do you need the function to use a string rather than just the plain ID number though?
I tried to make your code a bit simpler, and I think this would work, but I changed the callerid to be the SteamID64 (not a string). It might work now, but you'll have to change policedb_addOfficer to work with a number instead of a string (if possible)
[CODE]
local function police_addCop( ply, cmd, args, argStr )
if not checkAddCop(ply) then sendMessage( ply, "Moron" ) return end
local callerid = ply:SteamID64()
local targetid = targetIsValid(argStr)
if targetid then
if policedb_userRank( targetid ) == 0 then
policedb_addOfficer( targetid, callerid )
sendMessage( ply, "The target has successfully been added to the database!" )
else
sendMessage( ply, "The target couldn't be added. Maybe the developer is just bad?" )
end
else
sendMessage( ply, "Give me a name/SteamID/SteamID64 that I can use." )
end
end
concommand.Add( "police_addcop", police_addCop )
[/CODE]
I don't believe the problem lies with the callerid as I am able to use it without problem, but the moment I run the function policedb_addOfficer it panics.
Even if I try to run this function
[CODE]function testfunc()
print("hello")
end[/CODE]
It errors.
[QUOTE=MPan1;52426511]It might be this part:
[CODE]
local callerid = tostring(ply:SteamID64())
[/CODE]
Sorry for my stupid question, but why do you need it to be a string anyway? Couldn't you make this function:
[CODE]
policedb_addOfficer
[/CODE]
Accept a number instead?[/QUOTE]
Why would that be a problem?
[editline]2nd July 2017[/editline]
[QUOTE=ThaFartKnight;52426571]I don't believe the problem lies with the callerid as I am able to use it without problem, but the moment I run the function policedb_addOfficer it panics.
Even if I try to run this function
[CODE]function testfunc()
print("hello")
end[/CODE]
It errors.[/QUOTE]
What do you mean run that function?
[QUOTE=code_gs;52426718]Why would that be a problem?[/QUOTE]
I'm not sure to be honest, but there was some other thread about SteamID64 being converted into a scientific number because it was too large to print
[QUOTE=MPan1;52426738]I'm not sure to be honest, but there was some other thread about SteamID64 being converted into a scientific number because it was too large to print[/QUOTE]
That relates to incorrect number comparisons caused by floating point inaccuracy at higher bit counts.
When the code passes the if statement [CODE]if policedb_userRank(targetid) == 0[/CODE]
it should run the function: [CODE]policedb_addOfficer[/CODE]
But when it tries to do that it gives a lua panic.
So I tried to replace that function with a test function, something simple.
And again it gives a lua panic. Then I tried to run the test function as the first thing in the code. (Obviously commented out [CODE]policdedb_addOfficer[/CODE] when testing)
As you can see on the second line [CODE]testfunc("xd", "dab")[/CODE]
You guessed it, another lua panic.
I have literally tried to fix this problem for over 3 hours and couldn't find the problem.
The lua panic is coming from something else then. Perhaps you're overflowing the stack?
Overflowing the stack?
It would be better if you gave the code for the addOfficer function
[CODE]function policedb_addOfficer(plyid, callerid)
local Timestamp = os.time()
local date = os.date("%X - %d/%m/%y", Timestamp)
local query = "INSERT INTO policedb_officer(plyid, callerid, date) VALUES ('" ..plyid.. "', '"..callerid.."', '"..date.."')"
sql.Query(query)
end[/CODE]
Sorry, you need to Log In to post a reply to this thread.