19.11.2011, 18:40
File functions in OnPlayerUpdate are a very bad idea. Also, why do you need to check so often?
I've re-written most of the code and optimized it a little:
Remove the code from OnPlayerUpdate and just use the timer in the above code:
To load their money, I'm not sure what systems you have in place but basically
EDIT: Reading it back, It would probably be better to use PVars to use the system between scripts.
Also there's no need for mResetPlayerMoney, just mSetPlayerMoney(playerid, 0); ?
I've re-written most of the code and optimized it a little:
pawn Код:
new pMoney[MAX_PLAYERS];
stock mGivePlayerMoney(playerid, AMOUNT)//if use this in the FS it will only make the "pMoney" variable to its own
{
pMoney[playerid] += AMOUNT;
GivePlayerMoney(playerid, AMOUNT);
return 1;
}
stock mSetPlayerMoney(playerid, AMOUNT)
{
pMoney[playerid] = AMOUNT;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, AMOUNT);
}
stock mRemovePlayerMoney(playerid, AMOUNT)
{
pMoney[playerid] -= AMOUNT;
GivePlayerMoney(playerid, pMoney[playerid]);
}
stock mGetPlayerMoney(playerid) return pMoney[playerid];
forward MoneyCheck();
public MoneyCheck()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && GetPlayerMoney(i) != pMoney[i])
{
ResetPlayerMoney(i);
GivePlayerMoney(i, pMoney[i]);
}
}
return 1;
}
pawn Код:
// Under OnGameModeInit/OnFilterScriptInit
SetTimer("MoneyCheck", 4321, 1); // Every 4~ seconds check everyone's cash
pawn Код:
pMoney[playerid] = money_that_is_saved;
Also there's no need for mResetPlayerMoney, just mSetPlayerMoney(playerid, 0); ?