I'm getting this error when I run my moderation script:
[code]Hook 'PlayerInitialSpawnbadmin' Failed: [gamemodes\bhop\gamemode\badmin.lua:5] attempt to concatenate local 'length' (a nil value)[/code]
Any help would be appreciated.
[lua]
local meta = FindMetaTable( "Player" )
function meta:CheckBanned()
Msg(self:Nick().." RAN\n")
local length = sql.QueryValue("SELECT length FROM badmin WHERE unique_id = '"..self:SteamID().."'")
Msg(length.."\n") --Line 5
local starttime = sql.QueryValue("SELECT starttime FROM badmin WHERE unique_id = '"..self:SteamID().."'")
Msg(starttime.."\n")
local rank = sql.QueryValue("SELECT rank FROM badmin WHERE unique_id = '"..self:SteamID().."'")
Msg(rank.."\n")
if tonumber(length) == 0 then return end
if rank == "guest" || rank == "vip" then
if (length + starttime) > tonumber(os.time()) then
self:Kick("You are banned from this server")
Msg("Banned\n")
else
self:Bnotify( "Authenticated, you were not found in the ban list." )
Msg("Not Banned\n")
end
end
end
function meta:Bnotify( message )
umsg.Start("badmin", self)
umsg.String( message )
umsg.End()
end
hook.Add( "Initialize", "Initializebadmin", function( )
if sql.TableExists("badmin") then
Msg("Database already exists. [BADMIN]\n")
else
query = "CREATE TABLE badmin ( unique_id varchar(255), length int, starttime int, rank varchar(255) )"
result = sql.Query(query)
if sql.TableExists("badmin") then
Msg("badmin successfully created!\n")
else
Msg("An error occured while creating the badmin SQL table! \n")
Msg( sql.LastError( result ) .. "\n" )
end
end
end)
function new_player_badmin( ply )
sql.Query( "INSERT INTO badmin (`unique_id`, `length`, `starttime`, `rank` )VALUES ('"..ply:SteamID().."', '0', '0', 'guest')" )
result = sql.Query( "SELECT unique_id, length FROM badmin WHERE unique_id = '"..ply:SteamID().."'" )
if result then
Msg("badmin account created!\n")
else
Msg("An error was experienced when creating a player's badmin database!\n")
end
end
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawnbadmin", function(ply)
result = sql.Query("SELECT unique_id, score FROM player_score WHERE unique_id = '"..ply:SteamID().."'")
if !result then
new_player_badmin( ply )
else
ply:CheckBanned()
end
end)[/lua]
the SQL query that you are running is probably not returning anything and so when you go to print out the length variable, it contains a null.
Are you sure the user you are trying to ban is actually in the database?
I have never used this type of mySQL in gmod, so I am not sure what the return-type for [B]sql.QueryValue[/B] is - but I would also double check that it returns what you think it returns.
[QUOTE=SharpCoder;35318439]the SQL query that you are running is probably not returning anything and so when you go to print out the length variable, it contains a null.
Are you sure the user you are trying to ban is actually in the database?
I have never used this type of mySQL in gmod, so I am not sure what the return-type for [B]sql.QueryValue[/B] is - but I would also double check that it returns what you think it returns.[/QUOTE]I found the problem.
In my PlayerInitialSpawn hook, I look to see if there are 2 values, unique_id and score, but there is no score value, there never was.
I replaced score with rank and it worked flawlessly.
Sorry, you need to Log In to post a reply to this thread.