29.05.2012, 16:06
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:
Command
OnPlayerDisconnect, variable save:
Enuming the Playerinfo
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?
^^ 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];
}
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;
}
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;
}
pawn Код:
enum playerstats
{
username[24],
ppassword[35],
alevel,
kills,
deaths,
money,
level,
factionID,
factionRank,
clothes,
pInt // Add more info
}
new PVar[MAX_PLAYERS][playerstats];
How can I fix this issue?