27.01.2016, 23:50
(
Последний раз редактировалось AmigaBlizzard; 28.01.2016 в 10:51.
)
You got to be kidding me.
You're using a DATABASE, not a textfile where you need to overwrite the entire file when you change 1 value.
When your players earn some money, and by that I mean they ONLY earn some money, nothing else, why would you update ALL those fields with the exact same data which is already there, just to be able to change 1 value (money)?
Split that query in ALOT of smaller queries which are only executed when your players change THAT specific field.
When players earn money, execute a query that only updates the money.
When they get a scorepoint, execute another query that updates the score.
You can even create a dedicated function for those things.
Snippet from my own script:
I have alot more small functions like these.
They change the data in the server memory and also save them to the database.
This is one small function that only changes the money and score for the given player, nothing more, nothing less.
Small code and very easy to debug in case you have problems.
MySQL performs not well when it's being fed such huge queries all the time.
It has to break down the wall of text to single pieces, find each column and row, update the data (if it even needs updating), adjust search-indexes based on the data for faster searching and alot more.
A query that only has 50 characters is processed alot faster than a query that has 1500 characters.
If 1 value changes, don't update 100+ values.
Especially data that rarely changes, like a player's password, age, sex, admin-level, there is no need to update that all the time.
In real-life, when you wrote a message on a piece of paper with a crayon and you fix a typo, you don't go wiping out the entire piece of paper and rewrite everything as it was while fixing the typo, would you?
You only replace the typo and leave the rest alone.
Do the same when you use a database.
This looks like you're only saving everything at once upon OnPlayerDisconnect.
You really have to save whatever changes at the time those changes are made.
Player earns money -> save it.
Player earns score -> save it.
Player buys a house -> save it.
Player gets jailed -> save it (and again when he gets out of jail, and for longer jailtimes you might need to save in between as well).
Why?
Some players plays for hours in a row on your server and earn lots of money, lots of scorepoints, they buy a house, even some house-vehicle, they rank up, they make alot of kills, whatever they do.
And suddenly, there is a power failure at the server's datacenter.
Or the server gets attacked by a DDOS attack, or it just breaks down.
Basically, anything you can't possibly predict.
All the progress of that player is just gone because nothing has been saved for hours.
When he logs back in later on after such a crash, he still has the data he got when he logged in before the crash and lost hours of valuable stuff he acquired during his 10-hour long play time before the crash.
Nothing he acquired was saved and he has to start over from scratch and re-earn the stuff he already got yesterday.
My guess would be that he leaves and never comes back because of lousy data management by the scripter/server owner.
I would.
You're using a DATABASE, not a textfile where you need to overwrite the entire file when you change 1 value.
When your players earn some money, and by that I mean they ONLY earn some money, nothing else, why would you update ALL those fields with the exact same data which is already there, just to be able to change 1 value (money)?
Split that query in ALOT of smaller queries which are only executed when your players change THAT specific field.
When players earn money, execute a query that only updates the money.
When they get a scorepoint, execute another query that updates the score.
You can even create a dedicated function for those things.
Snippet from my own script:
PHP код:
// This function adds the given Money and Score values to the given player
Player_Reward(playerid, Money, Score)
{
new Query[128];
// Add the given Money and Score to the player's account
pData[playerid][PlayerMoney] = pData[playerid][PlayerMoney] + Money;
pData[playerid][PlayerScore] = pData[playerid][PlayerScore] + Score;
// Update money and score for this player in the player's account in MySQL
mysql_format(SQL_db, Query, sizeof(Query), "UPDATE playerdata SET Money = '%i', Score = '%i' WHERE ID = '%i'", pData[playerid][PlayerMoney], pData[playerid][PlayerScore], pData[playerid][SQLID]);
mysql_tquery(SQL_db, Query, "", "");
return 1;
}
They change the data in the server memory and also save them to the database.
This is one small function that only changes the money and score for the given player, nothing more, nothing less.
Small code and very easy to debug in case you have problems.
MySQL performs not well when it's being fed such huge queries all the time.
It has to break down the wall of text to single pieces, find each column and row, update the data (if it even needs updating), adjust search-indexes based on the data for faster searching and alot more.
A query that only has 50 characters is processed alot faster than a query that has 1500 characters.
If 1 value changes, don't update 100+ values.
Especially data that rarely changes, like a player's password, age, sex, admin-level, there is no need to update that all the time.
In real-life, when you wrote a message on a piece of paper with a crayon and you fix a typo, you don't go wiping out the entire piece of paper and rewrite everything as it was while fixing the typo, would you?
You only replace the typo and leave the rest alone.
Do the same when you use a database.
This looks like you're only saving everything at once upon OnPlayerDisconnect.
You really have to save whatever changes at the time those changes are made.
Player earns money -> save it.
Player earns score -> save it.
Player buys a house -> save it.
Player gets jailed -> save it (and again when he gets out of jail, and for longer jailtimes you might need to save in between as well).
Why?
Some players plays for hours in a row on your server and earn lots of money, lots of scorepoints, they buy a house, even some house-vehicle, they rank up, they make alot of kills, whatever they do.
And suddenly, there is a power failure at the server's datacenter.
Or the server gets attacked by a DDOS attack, or it just breaks down.
Basically, anything you can't possibly predict.
All the progress of that player is just gone because nothing has been saved for hours.
When he logs back in later on after such a crash, he still has the data he got when he logged in before the crash and lost hours of valuable stuff he acquired during his 10-hour long play time before the crash.
Nothing he acquired was saved and he has to start over from scratch and re-earn the stuff he already got yesterday.
My guess would be that he leaves and never comes back because of lousy data management by the scripter/server owner.
I would.