30.03.2009, 08:35
(
Last edited by Norn; 13/05/2011 at 10:32 PM.
)
Serverside Money Tutorial
* This tutorial was intended for roleplay gamemodes.
* This will not work with clientside features, etc stunt bonuses, sprunk machines and burger shot, they will just be able to purchase stuff for free.
Functions:
pawn Code:
#define ResetMoneyBar ResetPlayerMoney
#define UpdateMoneyBar GivePlayerMoney
new Cash[MAX_PLAYERS];
stock GivePlayerCash(playerid, money)
{
Cash[playerid] += money;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return Cash[playerid];
}
stock SetPlayerCash(playerid, money)
{
Cash[playerid] = money;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return Cash[playerid];
}
stock ResetPlayerCash(playerid)
{
Cash[playerid] = 0;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return Cash[playerid];
}
stock GetPlayerCash(playerid)
{
return Cash[playerid];
}
pawn Code:
ResetPlayerCash(playerid); //Resetting the players cash variable to zero.
pawn Code:
SetTimer("MoneyTimer", 1000, 1);
pawn Code:
public MoneyTimer()
{
new username[MAX_PLAYER_NAME];
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetPlayerCash(i) != GetPlayerMoney(i))
{
ResetMoneyBar(i);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(i,GetPlayerCash(i));//Sets the money in the moneybar to the serverside cash, Do not remove!
new hack = GetPlayerMoney(i) - GetPlayerCash(i);
GetPlayerName(i,username,sizeof(username));
printf("%s has picked up/attempted to spawn $%d.", username,hack);
}
}
}
}