• MYSQL problem
    3 replies, posted
So the following code for mysql keeps returning nil even though there is a 1 in the position: [lua] function team_2( ply ) local cpjoin = tmysql.escape( "SELECT CP FROM hl2rp_whitelist WHERE STEAMID = '"..ply:SteamID().."'" ) if cpjoin == 1 then ply:SetTeam( 2 ) else ply:PrintMessage( HUD_PRINTTALK, "You, cannot use the CP class "..ply:SteamID() ) ply:PrintMessage( cpjoin ) end end [/lua] The steamid is working properly but cpjoin keeps saying it's a nil value for the printmessage meaning it's not grabbing 1 out of the slot. Any help would be appreciated. Thank you!
[lua] function team_2( ply ) local function CanCP(res, status, err) if res[1].CP == 1 then ply:SetTeam( 2 ) else ply:PrintMessage( HUD_PRINTTALK, "You, cannot use the CP class "..ply:SteamID() ) end end tmysql.query( "SELECT CP FROM hl2rp_whitelist WHERE STEAMID = '"..ply:SteamID().."'", CanCP, 1 ) end [/lua] Untested, tmysql.escape doesn't run queries.
[lua] function team_2( ply ) local cpjoin = tmysql.query( "SELECT CP FROM hl2rp_whitelist WHERE STEAMID = '"..ply:SteamID().."'" ) if cpjoin[1][1] == 1 then ply:SetTeam( 2 ) else ply:PrintMessage( HUD_PRINTTALK, "You, cannot use the CP class "..ply:SteamID() ) ply:PrintMessage( cpjoin ) end end [/lua] Should work. For some reason it always returns a table so you need the [1][1]
Thank you Loures, that was the one that worked for me!
Sorry, you need to Log In to post a reply to this thread.