22.04.2014, 13:45
I would use OnEnterExitModShop callback so I can toggle to a variable whether the player is in the mod shop or not.
Then in a global timer (5 seconds for example), I'd loop through the players (using foreach - since it loops through connected players only) and reset their money, then give the registered money back. Before doing so, a simple check about if the player's money (from GetPlayerMoney) are lesser than the registered one and if the variable is 1 (that the player is in the mod shop) so then you set the registered money as the money GetPlayerMoney returned.
An example:
EDIT: It seems that everything works fine except one thing. If you have for example $150 and you try to buy a colour which costs $150, then it doesn't remove the money and it gives you that money back. But if you have more than that, then it works fine. If you have less than that, it returns the error message.
Then in a global timer (5 seconds for example), I'd loop through the players (using foreach - since it loops through connected players only) and reset their money, then give the registered money back. Before doing so, a simple check about if the player's money (from GetPlayerMoney) are lesser than the registered one and if the variable is 1 (that the player is in the mod shop) so then you set the registered money as the money GetPlayerMoney returned.
An example:
pawn Код:
static
bool: Player_ModShop[MAX_PLAYERS char],
Player_Money[MAX_PLAYERS],
Timer_Money = -1;
// On(GameMode/FilterScript)Init:
Timer_Money = SetTimer("OnMoneyUpdate", 5000, true);
// On(GameMode/FilterScript)Exit:
KillTimer(Timer_Money);
// OnPlayerConnect:
Player_ModShop{playerid} = false;
Player_Money[playerid] = 0;
// on logging, set the registered money to "Player_Money[playerid]"
// OnEnterExitModShop:
Player_ModShop{playerid} = !!enterexit;
forward OnMoneyUpdate();
public OnMoneyUpdate()
{
new
money;
foreach(new i : Player)
{
if ((money = GetPlayerMoney(i)) < Player_Money[i] && Player_ModShop{i}) Player_Money[i] = money;
ResetPlayerMoney(i);
GivePlayerMoney(i, Player_Money[i]);
}
}