Jump to content

Some Lua Help


MatthewD
 Share

Recommended Posts

Hi, and thanks for looking at my post! I am a long time viewer and first time poster so please forgive any errors.

I am trying to learn Lua and a little MySQL at the same time. I am attempting to setup a local perp2 server for myself. (perp2 is a game mode for Garrys Mod) Also I would like to state that i rather not just be given the answer but more of a push in the right direction as to what the issue is so I can fix it myself (Sounds strange but I am trying to learn :) )

So here is the problem:

When I disconnect from the server, the player data does not get saved into the MySQL database. I know the database is working correctly and that the server can add new entries.

When I first join the server and register the console spams me with this message until I disconnect:

Loading TriConIck's SMF ID... //When I first join the server the server spits this out
Loading TriConIck's SMF ID... //Right after i register my account for the server, this is what happens.... 
Loading TriConIck...
Starting var transfer to TriConIck...
Loading TriConIck...
Loading TriConIck...
Loading TriConIck...
Loading TriConIck... // I get spamed this message until I disconnect

Than once I disconnect the server gives me this error:

Refused to save TriConIck.
Dropped TriConIck from server (Disconnect by user.)
[@garrysmod\gamemodes\perp2\gamemode\sv_networking.lua:72] Tried to use a NULL entity!

This is the code block that seems to be spamming my console:

function GM.LoadPlayerProfile ( Player )
	if (Player.AlreadyLoaded) then return false; end

	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("perp_umsg_f", Player);
								umsg.End();
							else
								Player:SendUMsgVar("perp_ums", Player, p, k, v.value, true);
							end
						end
					end);
				end
			end
		end

		umsg.Start("perp_expect", Player);
			umsg.Short((curNum - 5) * 5);
		umsg.End();
	end

This is the code block responsible for the saving of the player data:

tmysql.query("SELECT `id`, `rp_name_first`, `rp_name_last`, `time_played`, `cash`, `model`, `items`, `skills`, `genes`, `formulas`, `organization`, `bank`, `vehicles`, `blacklists`, `ringtone`, `ammo_pistol`, `ammo_rifle`, `ammo_shotgun` FROM `perp_users` WHERE `id`='" .. Player.SMFID .. "'", function ( )
		if (!PlayerInfo || !PlayerInfo[1]) then
			tmysql.query("INSERT INTO `perp_users` (`id`, `uid`, `steamid`, `rp_name_first`, `rp_name_last`, `genes`, `cash`) VALUES ('" .. Player.SMFID .. "', '" .. Player:UniqueID() .. "', '" .. Player:SteamID() .. "', 'John', 'Doe', '5', '500')", function ( )
				Player.CanSetupPlayer = true;
				GAMEMODE.LoadPlayerProfile(Player);
			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("perp_newchar", Player);
			umsg.End();
		else

Thank you for reading my long post, I appreciate any help that can be given, but if you could, please just give me a helping hand and not just the answer.

-Matthew

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...