SQL Problem -
vIBIENNYx - 29.05.2012
https://sampforum.blast.hk/showthread.php?tid=71136
^^ I used that link above to make all money clientside, however, I have an issue when registering and saving the money variable to the database, after setting the players money via a /givemoney the money doesn't save to the database but the player gets it.
I have used the functions from the above link with a small edit to the database, here are all functions, commands and stocks:
Stocks:
pawn Код:
#define ResetMoneyBar ResetPlayerMoney
#define UpdateMoneyBar GivePlayerMoney
stock GivePlayerCash(playerid, moneya)
{
PVar[playerid][money] += moneya;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid, PVar[playerid][money]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return PVar[playerid][money];
}
stock SetPlayerCash(playerid, moneya)
{
PVar[playerid][money] = moneya;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,PVar[playerid][money]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return PVar[playerid][money];
}
stock ResetPlayerCash(playerid)
{
PVar[playerid][money] = 0;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,PVar[playerid][money]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return PVar[playerid][money];
}
stock GetPlayerCash(playerid)
{
return PVar[playerid][money];
}
Command
pawn Код:
command(givemoney, playerid, params[])
{
if(PVar[playerid][alevel] > 3)
{
new id, cash, str[128];
if(sscanf(params, "ud", id, cash)) return SendClientMessage(playerid, 0x66666666, "Usage: /givemoney [Player ID] [0-100000000]");
{
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0x66666666, "That player is not connected");
if(cash > 100000000) return SendClientMessage(playerid, 0x66666666, "You can only spawn $10,000,000 at a time");
if(playerid == id)
{
format(str, sizeof(str), "You have given yourself $%d", cash);
SendClientMessage(id, 0x66CCFFFF, str);
GivePlayerCash(id, cash);
}
else
{
format(str, sizeof(str), "You have given %s $%d", RemoveUnderScore(id), cash);
SendClientMessage(playerid, 0x66CCFFFF, str);
format(str, sizeof(str), "%s has given you $%d", RemoveUnderScore(playerid), cash);
SendClientMessage(id, 0x66CCFFFF, str);
GivePlayerCash(id, cash);
}
}
}
else
{
SendClientMessage(playerid, 0x66666666, "You are not authorised to use that command");
return 1;
}
return 1;
}
OnPlayerDisconnect, variable save:
pawn Код:
stock SavePVar(playerid)
{
if(IsPlayerConnected(playerid))
{
new Query[600];
if(GetPlayerMoney(playerid) != PVar[playerid][money])
{
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PVar[playerid][money]);
}
format(Query, sizeof(Query), "UPDATE `username` SET `username` = '%s', `ppassword` = '%s', `alevel` = '%d', `kills` = '%d', `deaths` = '%d', `money` = '%d', `level` = '%d', `factionID` = '%d', `factionRank` = '%d', `clothes` = '%d'", // Also remember to update this...
PVar[playerid][username],
PVar[playerid][ppassword],
PVar[playerid][alevel],
PVar[playerid][kills],
PVar[playerid][deaths],
GetPlayerMoney(playerid),
PVar[playerid][level],
PVar[playerid][factionID],
PVar[playerid][factionRank],
GetPlayerSkin(playerid),
pName(playerid));
mysql_query(Query);
mysql_free_result();
return 1;
}
else return 0;
}
Enuming the Playerinfo
pawn Код:
enum playerstats
{
username[24],
ppassword[35],
alevel,
kills,
deaths,
money,
level,
factionID,
factionRank,
clothes,
pInt // Add more info
}
new PVar[MAX_PLAYERS][playerstats];
I don't really know why but it will not save whatever the new variable is, for instance, when the player registers they are given the $500 but the database doesn't show that, nor does it show the newer variable when the player has his money set or when the player logs out.
How can I fix this issue?
Re: SQL Problem -
mati233 - 29.05.2012
Why don't you try to add the queries for the money on your special functions?
Like this:
PHP код:
stock GivePlayerCash(playerid, moneya)
{
PVar[playerid][money] += moneya;
new query[128];
format(query, sizeof(query), "UPDATE users SET money=%d WHERE username='%s'", PVar[playerid][money], PVar[playerid][username]);
mysql_query(query);
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid, PVar[playerid][money]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return PVar[playerid][money];
}
That way you will always have your database updated, I'm not sure, but your problem should be because you are getting the player hp onplayerdisconnect.
Re: SQL Problem -
vIBIENNYx - 29.05.2012
Thanks, can you please explain where you said that I am getting the player HP?
Edit: It didn't work either ^^
Re: SQL Problem -
mati233 - 29.05.2012
On your query, maybe if you replace GetPlayerMoney(playerid), by PVar[playerid][money], it will work fine, just take a try
Re: SQL Problem -
vIBIENNYx - 29.05.2012
Okay, trying it now..
Edit: Nope, still didn't work..
Re: SQL Problem -
mati233 - 29.05.2012
Quote:
Originally Posted by vIBIENNYx
Okay, trying it now..
Edit: Nope, still didn't work..
|
I think my first suggestion should work without any problem, don't forget to remove from the onplayerdisconnect query, the money, and let your function update that value.
Re: SQL Problem -
vIBIENNYx - 29.05.2012
Okay, I have changed these:
pawn Код:
stock SavePVar(playerid)
{
if(IsPlayerConnected(playerid))
{
new Query[600];
format(Query, sizeof(Query), "UPDATE `username` SET `username` = '%s', `ppassword` = '%s', `alevel` = '%d', `kills` = '%d', `deaths` = '%d', `level` = '%d', `factionID` = '%d', `factionRank` = '%d', `clothes` = '%d'", // Also remember to update this...
PVar[playerid][username],
PVar[playerid][ppassword],
PVar[playerid][alevel],
PVar[playerid][kills],
PVar[playerid][deaths],
PVar[playerid][level],
PVar[playerid][factionID],
PVar[playerid][factionRank],
GetPlayerSkin(playerid),
pName(playerid));
mysql_query(Query);
mysql_free_result();
return 1;
}
else return 0;
}
And:
pawn Код:
stock GivePlayerCash(playerid, moneya)
{
new query[128];
PVar[playerid][money] += moneya;
format(query, sizeof(query), "UPDATE `playerinfo` SET `money` = '%d' WHERE `username` = '%s'", PVar[playerid][money], PVar[playerid][username]);
mysql_query(query);
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid, PVar[playerid][money]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return PVar[playerid][money];
}
Still doesn't work..
Re: SQL Problem -
mati233 - 29.05.2012
Can you print the query please, that should be working...
Re: SQL Problem -
vIBIENNYx - 29.05.2012
What do you mean, print the query?
Re: SQL Problem -
Jonny5 - 29.05.2012
then look in your server console and post back what it prints.