• MYSQL data saving resets data to "0" rarely, resetting a player's stats.
    20 replies, posted
I had a similar thread earlier but I'm remaking this because I believe the apparent issue is different. I learned recently that sometimes when a players data is updated and thus saved, it will rarely reset all of the data that should be updated, to 0. For context, if a player was Level 5, xp 5, had 5 slots, and 5 metal, instead of increasing, they would instead just reset to 0 for apparently no reason. I firmly believe this has nothing to do with the sql query codes nad stuff as it is very similar to how pointshop 1 does it. However, I think it's a different issue. So, when it retrieves data from the mysql database, it assigns those values to a NWInt/NWFloat on the player. When it's to save the data, it retrieves those NWInt/NWFloat and uses those to update their database entries. However, I recently found out with a different NWInt that has nothing to do with the player's stats, that it will instead of having the correct number, will return as 0. The problem is, it returns the correct number almost all the time, but when the server stays up for seeming to long (by too long, im talking like, 10 minutes+?), it will start returning 0. Is there a limit to how many NW values can be stored on an entity/player? Because I cant find a reason as to why a value would just randomly start return 0 after being on the same map for too long. The wiki pages don't state any bugs either. So, I'm using this as a basis to my MYSQL saving issue. Is this true? If this were the case, what do I use instead of NWInt/NWFloat? I wanted to use these so the player can see their own stats as well as see other player's stats. If the answer is "You have too many of these", how much is too many because as far as I see there's not a lot of them on a player. I'm very desperate to find the cause because I've been having this for several weeks on my server, and players keep getting their data reset because of this. This is going to slowly kill my server if i cannot find a fix for this, and I've been doing different kinds of fixes for my sql code but i dont think its the sql code anymore. I'm so desperate I even tried to ask code_gs, but they're a little busy so I'm asking here as well. Here's how it gets the data function Checklevel(ply,callback)     GetDataStuff(ply, function(exp, level, slots, metal)         ply:SetNWInt("xp",exp)         ply:SetNWInt("level",level)         ply:SetNWInt("slots",slots)         ply:SetNWInt("metal",metal)         ply:ChatPrint("[Racing Attack] Data loaded!")     end) end function GetDataStuff(ply, callback)     local query = radb:query("SELECT * FROM `raceattack` WHERE `id` = "..ply:SteamID64())     function query:onSuccess(sqldata)         if #sqldata > 0 then -- Found data in database             local data = sqldata[1]             local xp = data.experience             local level = data.level             local slots = data.slots             local metal = data.metal             callback(xp, level, slots, metal)         else -- No data has been found             print(ply:Nick().."'s level start.")             ply:SetNWInt("xp",0)             ply:SetNWInt("level",0)             ply:SetNWInt("slots",4)             ply:SetNWInt("metal",0)             local query = radb:query("INSERT INTO raceattack VALUES ('"..ply:SteamID64().."', '"..ply:GetNWInt("level").."', '"..ply:GetNWInt("xp").."', '"..ply:GetNWInt("slots").."', '"..ply:GetNWInt("metal").."')")             query:start()         end     end          function query:onError(err, sql)         if radb:status() ~= mysqloo.DATABASE_CONNECTED then             ply:ChatPrint("[Racing Attack] Re-connecting to database...")             radb:connect()             radb:wait()         if radb:status() ~= mysqloo.DATABASE_CONNECTED then             ErrorNoHalt("Re-connection to database server failed.")             ply:ChatPrint("[Racing Attack] Data failed to load!")             callback(0, 0, 4, 0)             return             end         end         print("An error occured while executing the query: " .. err .. " (" .. sql .. ")")         query:start()     end     query:start() end Here's how it saves the data (Yes its a fucking mess but I'm starting to think this isnt the problem) function Savelevel(ply)     local query = radb:query("SELECT * FROM `raceattack` WHERE `id` = "..ply:SteamID64())     function query:onSuccess(sqldata)         local query = radb:query("UPDATE `raceattack` SET `level` = '"..ply:GetNWInt("level").."' WHERE `id` = "..ply:SteamID64())         function query:onSuccess(sqldata)         end         function query:onError(err)             print("An error occured while executing the query: " .. err)         end         query:start()                  local query = radb:query("UPDATE `raceattack` SET `experience` = '"..ply:GetNWInt("xp").."' WHERE `id` = "..ply:SteamID64())         function query:onSuccess(sqldata)         end         function query:onError(err)             print("An error occured while executing the query: " .. err)         end         query:start()                  local query = radb:query("UPDATE `raceattack` SET `slots` = '"..ply:GetNWInt("slots").."' WHERE `id` = "..ply:SteamID64())         function query:onSuccess(sqldata)         end         function query:onError(err)             print("An error occured while executing the query: " .. err)         end         query:start()                  local query = radb:query("UPDATE `raceattack` SET `metal` = '"..ply:GetNWInt("metal").."' WHERE `id` = "..ply:SteamID64())         function query:onSuccess(sqldata)         end         function query:onError(err)             print("An error occured while executing the query: " .. err)         end         query:start()              end     query:start() end And to further add, I even had a bought script called "Achievements" and the achievements for the reset player ALSO reset too! There is no way a paid script would have the same bug, so something isnt right. Is it possible that the webhost im storing these stuff on is a piece of junk? Because if it is i am going to be extremely upset. There's so many variables here that I fear that i would have to pay someone just to help me at this point and I really don't want to have to resort to this.
There's a limit for NW unique names for all entities: 4096. But it's not your case. Put debug `print` in all of your functions to control the process
I probably should have mentioned it can take up to a couple days for this problem to occur, which makes actually debugging this a pain in the ass because of course all the prints are so far working. it's just only when it "Feels like it" it fails and everytime its been when i was asleep. I asked one person what they did before the problem and it was relatively short and doesnt answer anything for me.
Okay we found a consistant method to screw up the NWInts. The gamemode starts round, and the idea is to simulate a game crash. So, we use task manager to kill gmod after the round starts. rejoining on the same map and using the command to check our stats (which uses getnwint etc), they return 0 after doing this. Got any theories as to why this is? I highly doubt this is a universal bug otherwise ouch thats really bad.
Make sure that SQL data is really gets updated. I'm not sure, but maybe here: UPDATE `raceattack` SET `metal` Instead of [ ` ] use [ ' ]
I guess, but that doesnt quite answer the "crashing" causing the nwints to end up returning 0. id have to probably find the answer to that myself somehow, not sure. I can try what you said still I guess.
Would like to help, but the CREATE query code is missing, which might indicate the problem.
So the data in SQL is corrent?
yes it is. as long as the saving is disabled, the incorrect nwints dont overwrite their data. The nwints breaking on crashing isnt 100% consistant now we did it more but it was certainly causing the bug to happen faster than waiting 2 days
Try not using NWInts then? Use Network Messages.
Also there's SetNW2Int
only works in PVS.
I guess i could try a different method instead of NW, but now i want to know whats causing the NW issue so other people dont do it.
@Rubat please, take a look when you'll have a time for it
For now I'll resort to just doing ply.xp, ply.level, etc and network those to players instead with net messages. I guess that's what i get for trying to take shortcuts... Seems to not bug this way at least. I guess it also means that it only networks when they change instead of constantly so, minor optimization this way too so it's not all that bad I suppose.
Where "GetDataStuff" and "Checklevel" are called?
checklevel uses getdatastuff, its callback stuff. it starts the process by calling Checklevel in a function on serverside which is started by a net message from the client. The client sends the message from GM/InitPostEntity
Don't just use print to debug your code. Use file.Write and do proper checks when saving players info. As of now, you aren't even checking if the player or the steamid is valid before you save info into the database. Also look for duplicate functions with the same name.
While i understand, I've already resolved this by doing this a different way.
Oh shit, this can be an abuse method. For example player sends more than one net message, this cause SQL to block second connection which was too fast from the previous and that reverts to default values. :thinking:
Nah, the server flags them when its sent, it wont work anymore than once
Sorry, you need to Log In to post a reply to this thread.