MySQL issues
#1

Hello there,

I think I am having certain issues with MySQL database, basically I have two questions regarding this, which I couldn't or haven't tried yet to find an answer to. First of all, my player user enum has the AccID primary key, but even once the table is clean from all of accounts, the AccID starts at something ridiculous like 303. In long term, this might be a bit annoying :P

Second of all, at random times, the statistics on my account get reset. For instance, my friend crashed from the server, and I entered just after he's crashed. My account then reset to default state, as after registration.

EDIT: We've both crashed after testing some objects, and I've received his stats, and he received mine. Odd, or I've made a mistake somewhere? The only columns that weren't jumbled up are AccID, Username, IP and Password.

How can I solve these? I'm happy to supply any snippets of code, in case I went wrong anywhere.

Cheers.
Reply
#2

1. Your primary key auto-increments (AUTO_INCREMENT), because all keys are unique the key is always incremented and never re-used, even when rows are removed. If you have 10 accounts (keys 1 to 10) and you remove all 10 of them the next value will still be 11, regardless of the amount of rows. You can reset your AUTO_INCREMENT value using something like:

Код:
ALTER TABLE `table_name` AUTO_INCREMENT = 0;
2. Do you reset your enum values when a player connects? It's likely that they are not reset (set back to 0 or whatever you want their default values to be) when a player crashes and the next player that joins with that ID will still have the old values.
Reply
#3

Thanks for your reply. I'm slightly confused with the new phpMyAdmin layout, where can I input this?

Regarding point 2, I'm not really an expert on MySQL. Do you have maybe any example of how I can reset them to default values? Or maybe, would it work, to save statistics OnPlayerDisconnect or not really?
Reply
#4

In the left pane should be a button called 'Query window', use that.

Regarding point 2; when a player crashes, OnPlayerDisconnect is only called a few seconds after the player has already left the game. Though I don't think the server releases the slot before calling OnPlayerDisconnect. You can reset enum values using a loop:
pawn Код:
for(new i; i < enumname; i++)
{
    enumvar[enumname:i] = 0;
}
Obviously replacing enunname with the name of your enum and enumvar with the name of your variable. This will clear out everything. If you want other default values than 0 you have to set them manually afterwards.
Reply
#5

Thank you. Fair enough about the OnPlayerDisconnect. I never actually tangled on that far with enums, if you don't mind, could you explain please the difference between 0 and default values? Does that mean, that the data for the player resets in the database to the default values or am I completely wrong thinking that? Also, which variable would I use in this case?

I'd have something like this so far :P

Код:
for(new i; i < pInfo; i++)
{
    enumvar[pInfo:i] = 0;
}
Reply
#6

They are in no way linked to each other. You'll obviously need to clear out the enum after the player's data has been saved on disconnect. You can also clear out the enum for the next player on connect, should you so wish.
Reply
#7

Not sure how to get this to work still, defined it OnPlayerConnect.

Код:
for(new i; i < pInfo; i++)
{
    Player[pInfo:i] = 0;
}
Reply
#8

Bump.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)