• Some errors with mysql and sv_networking.lua
    9 replies, posted
Hi, I recently tried using an old gamemode again after not having a server for a few months, however I find that whenever anyone joins they get the following error and they don't get a character creation screen or anything saved to the database. Error: https://files.facepunch.com/forum/upload/288044/67f3cfbe-5a6b-4ab2-8aae-40c78462d695/image.png Code at sv_networking.lua function GM.LoadPlayerProfile ( Player ) --if (Player.AlreadyLoaded) then return false; end Player.SMFID = Player:SteamID() ------------------ LINE 38 Player.Buddies = Player.Buddies or {} Msg("Loading " .. Player:Nick() .. "...\n"); if (!Player.StartedSendingVars) then Player.StartedSendingVars = true; Msg("Starting var transfer to " .. Player:Nick() .. "...\n"); local curNum = 5; for _, p in pairs(player.GetAll()) do if (p != Player && p.StringRedun) then for k, v in pairs(p.StringRedun) do curNum = curNum + .2; timer.Simple(curNum, function ( ) if (Player && IsValid(Player)) then if (!p || !IsValid(p) || !p.StringRedun[k]) then umsg.Start("gta_umsg_f", Player); umsg.End(); else Player:SendUMsgVar("gta_ums", Player, p, k, v.value, true); end end end); end end end umsg.Start("gta_expect", Player); umsg.Short((curNum - 5) * 5); umsg.End(); end tmysql.query("SELECT `steamid`, `rp_name_first`, `rp_name_last`, `time_played`, `cash`, `model`, `items`, `storage`, `skills`, `genes`, `formulas`, `organization`, `bank`, `vehicles`, `blacklists`, `ringtone`, `ammo_pistol`, `ammo_rifle`, `ammo_shotgun`, `fuelleft`, `lastcar` FROM `gta_users` WHERE `steamid`='" .. Player:SteamID() .. "'", function ( PlayerInfo ) if (!Player || !Player:IsValid() || !IsValid(Player)) then return end if (!PlayerInfo || !PlayerInfo[1]) then tmysql.query("INSERT INTO `gta_users` (`id`, `uid`, `steamid`, `rp_name_first`, `rp_name_last`, `time_played`, `cash`, `model`, `items`, `skills`, `genes`, `formulas`, `organization`, `bank`, `vehicles`, `ringtones`, `ringtone`, `last_played`) VALUES ('" .. Player.SMFID .. "', '" .. Player:UniqueID() .. "', '" .. Player:SteamID() .. "', 'John', 'Doe', '5', '15000', '', '', '', '5;0;0;0;0;0;0', '', '0', '0', '', '', '1', '0')", function (...) PrintTable({...}) tmysql.query("INSERT INTO `gta_fuel` (`uid`) VALUES ('" .. Player:UniqueID() .. "')"); if (!Player || !Player:IsValid() || !IsValid(Player)) then return end Player.CanSetupPlayer = true; timer.Simple(1, function() GAMEMODE.LoadPlayerProfile(Player); end) -- LINE 83 end); return; end if (PlayerInfo[1][2] == "John" && PlayerInfo[1][3] == "Doe") then Player.CanSetupPlayer = true; end if (Player.CanSetupPlayer) then Msg("Allowing " .. Player:Nick() .. " to setup new player...\n"); umsg.Start("gta_newchar", Player); umsg.End(); else end Player.joinTime = CurTime(); end concommand.Add('gta_lp', GM.LoadPlayerProfile); I removed part of the code because it was pretty long and I didn't think the rest of it would be relevant, if you think it will help you can find it here: https://pastebin.com/uvp6GD6g
The Player validity check should go above the tmysql query since you're calling Player:SteamID()
I'm being stupid rn, which bit are you referring to when you say player validity check
Check your code and try to figure it out - should be very obvious.
Well presuming you meant timer.Simple(1, function() GAMEMODE.LoadPlayerProfile(Player); end) I tried it and it made no difference :/
You should move it to the top of the function - you cannot run any functions on the player until you verify they're valid. Also, the check can just be simplified to !IsValid(Player) - the rest of the checks are unnecessary.
I moved the check to the first line of the function, it fixed the error but I'm still having a problem where I can't create a character, I guess that's being caused by something else, regardless thank you for helping me fix my error.
It's probably being ran as a RunConsoleCommand call instead of Player/ConCommand
As far as I can tell it doesn't use a concommand, it uses uMsg
How is a umsg running a concommand?
Sorry, you need to Log In to post a reply to this thread.