Public Function ?
#2

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:

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;
}
Remove the code from OnPlayerUpdate and just use the timer in the above code:

pawn Код:
// Under OnGameModeInit/OnFilterScriptInit
SetTimer("MoneyCheck", 4321, 1); // Every 4~ seconds check everyone's cash
To load their money, I'm not sure what systems you have in place but basically

pawn Код:
pMoney[playerid] = money_that_is_saved;
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); ?
Reply


Messages In This Thread
Public Function ? - by park4bmx - 19.11.2011, 17:01
Re: Public Function ? - by MP2 - 19.11.2011, 18:40

Forum Jump:


Users browsing this thread: 1 Guest(s)