new PlayerCash[MAX_PLAYERS];
new String[30];
format(String,sizeof(String),"Your Cash: %d",PlayerCash[playerid]);
SendClientMessage(playerid,COLOR,String);
if(PlayerCash[playerid] >= 500)
{
//give the player the m4 or do whatever because the players cash is above 500
PlayerCash[playerid] -= 500;//this will take the 500 from the players cash for purchasing the M4.
}
else
{
SendClientMessage(playerid,COLOR,"You do not have enough cash to buy a M4!");
}
Originally Posted by Miokie*
You could do:
pawn Код:
Use a format string like so: pawn Код:
|
stock MoneyPlus(playerid, amount)
{
PlayerCash[playerid]+=amount;
}
stock MoneyMinus(playerid, amount)
{
if(PlayerCash[playerid]-amount>=0)
{
PlayerCash[playerid]-=amount;
return 1;
}
return 0;
}
// top new pCash[MAX_PLAYERS]; #define GiveUserMoney(%1,%2) pCash[%1] += %2 #define GetUserMoney(%1) pCash[%1] #define ResetUserMoney(%1) pCash[%1] = 0
if(GetUserMoney(playerid) < 200) return SendClientMessage(playerid, COLOR, "You dont have the cash"); GiveUserMoney(playerid, -200); // Remove 200 from the cash of the player
// top #define ITEM_NONE 0 #define ITEM_CONDOM 1 #define ITEM_DRUGS 2 #define ITEM_DRINKS 3 #define ITEM_PHONE 4 // more items here #define MAX_ITEMS 5 // increase if you use more items #define MAX_ITEMSLOT 3 // amount of items player can carry, remember you need to save each item #define MAX_ITEMAMOUNT 20 // the max amount of an item a player can carry new pItem[MAX_PLAYERS][MAX_ITEMSLOT], pItemAmount[MAX_PLAYERS][MAX_ITEMSLOT]; stock GiveUserItem(playerid, item, amount) { /* returns 0 if NOT successfull returns 1 if successfull */ new slot = MAX_ITEMSLOT; for(new i = 0; i < MAX_ITEMSLOT; i++) { if(pItem[playerid][i] == ITEM_NONE || pItem[playerid][i] == item) { slot = i; break; } } if(slot == MAX_ITEMSLOT) return 0; if((pItemAmount[playerid][slot]+amount) > MAX_ITEMAMOUNT) return 0; pItem[playerid][slot] = item; pItemAmount[playerid][slot] += amount; if(pItemAmount[playerid][slot] <= 0) pItem[playerid][slot] = ITEM_NONE; return 1; } stock GetUserItem(playerid, item) { /* returns the amount of an item */ for(new i = 0; i < MAX_ITEMSLOT; i++) { if(pItem[playerid][i] == item) return pItemAmount[playerid][i]; } return 0; } stock GetItem(item) { new string[30]; switch(item) { case ITEM_CONDOM: format(string, sizeof(string), "Condom"); case ITEM_DRUGS: format(string, sizeof(string), "Drogen"); case ITEM_DRINKS: format(string, sizeof(string), "Drinks"); case ITEM_PHONE: format(string, sizeof(string), "Phone"); // Add more items here default: format(string, sizeof(string), "Nothing"); } return string; }
GiveUserItem(playerid, item, amount): Give or Remove an item of a player ( returns 1 if successfull and 0 if not) GetUserItem(playerid, item): Amount of the item in the bag ( returns the amount of the item in the bag of the player) GetItem(item); returns the name of the item |
// buy command new item, amount, string[80]; if(sscanf(params, "dd", item,amount)) // check the parameters with sscanf or strtok { SendClientMessage(playerid, COLOR, "USAGE: /buy [item] [amount]"); format(string, sizeof(string), "Available Items -> Phone:%d | Condom:%d ", ITEM_PHONE, ITEM_CONDOM); SendClientMessage(playerid, COLOR, string); return 1; } if(amount <= 0) return SendClientMessage(playerid, COLOR, " Wrong amount"); if(item != ITEM_PHONE && item != ITEM_CONDOM) return SendClientMessage(playerid, COLOR, "You cant bought this here"); new bool:success = GiveUserItem(playerid, item, amount); if(!success) return SendClientMessage(playerid, COLOR, "Check your bag, you cant put this item in the bag right now"); format(string, sizeof(string), "You bought %d %s", amount, GetItem(item)); SendClientMessage(playerid, COLOR, string); // in the call command you could then check if(GetUserItem(playerid, ITEM_PHONE) == 0) return SendClientMessage(playerid, COLOR, "You dont have a phone");
Originally Posted by Doktor
Couldnt you just use defines for it?
Код:
// top new pCash[MAX_PLAYERS]; #define GiveUserMoney(%1,%2) pCash[%1] += %2 #define GetUserMoney(%1) pCash[%1] #define ResetUserMoney(%1) pCash[%1] = 0 instead of "GivePlayerMoney(playerid, amount)", use "GiveUserMoney(playerid, amount)" Instead of "GetPlayerMoney(playerid)", use "GetUserMoney(playerid)" instead of "ResetPlayerMoney(playerid)" user "ResetUserMoney(playerid)" So you could for example use Код:
if(GetUserMoney(playerid) < 200) return SendClientMessage(playerid, COLOR, "You dont have the cash"); GiveUserMoney(playerid, -200); // Remove 200 from the cash of the player Код:
// top #define ITEM_NONE 0 #define ITEM_CONDOM 1 #define ITEM_DRUGS 2 #define ITEM_DRINKS 3 #define ITEM_PHONE 4 // more items here #define MAX_ITEMS 5 // increase if you use more items #define MAX_ITEMSLOT 3 // amount of items player can carry, remember you need to save each item #define MAX_ITEMAMOUNT 20 // the max amount of an item a player can carry new pItem[MAX_PLAYERS][MAX_ITEMSLOT], pItemAmount[MAX_PLAYERS][MAX_ITEMSLOT]; stock GiveUserItem(playerid, item, amount) { /* returns 0 if NOT successfull returns 1 if successfull */ new slot = MAX_ITEMSLOT; for(new i = 0; i < MAX_ITEMSLOT; i++) { if(pItem[playerid][i] == ITEM_NONE || pItem[playerid][i] == item) { slot = i; break; } } if(slot == MAX_ITEMSLOT) return 0; if((pItemAmount[playerid][slot]+amount) > MAX_ITEMAMOUNT) return 0; pItem[playerid][slot] = item; pItemAmount[playerid][slot] += amount; if(pItemAmount[playerid][slot] <= 0) pItem[playerid][slot] = ITEM_NONE; return 1; } stock GetUserItem(playerid, item) { /* returns the amount of an item */ for(new i = 0; i < MAX_ITEMSLOT; i++) { if(pItem[playerid][i] == item) return pItemAmount[playerid][i]; } return 0; } stock GetItem(item) { new string[30]; switch(item) { case ITEM_CONDOM: format(string, sizeof(string), "Condom"); case ITEM_DRUGS: format(string, sizeof(string), "Drogen"); case ITEM_DRINKS: format(string, sizeof(string), "Drinks"); case ITEM_PHONE: format(string, sizeof(string), "Phone"); // Add more items here default: format(string, sizeof(string), "Nothing"); } return string; } Quote:
Код:
// buy command new item, amount, string[80]; if(sscanf(params, "dd", item,amount)) // check the parameters with sscanf or strtok { SendClientMessage(playerid, COLOR, "USAGE: /buy [item] [amount]"); format(string, sizeof(string), "Available Items -> Phone:%d | Condom:%d ", ITEM_PHONE, ITEM_CONDOM); SendClientMessage(playerid, COLOR, string); return 1; } if(amount <= 0) return SendClientMessage(playerid, COLOR, " Wrong amount"); if(item != ITEM_PHONE && item != ITEM_CONDOM) return SendClientMessage(playerid, COLOR, "You cant bought this here"); new bool:success = GiveUserItem(playerid, item, amount); if(!success) return SendClientMessage(playerid, COLOR, "Check your bag, you cant put this item in the bag right now"); format(string, sizeof(string), "You bought %d %s", amount, GetItem(item)); SendClientMessage(playerid, COLOR, string); // in the call command you could then check if(GetUserItem(playerid, ITEM_PHONE) == 0) return SendClientMessage(playerid, COLOR, "You dont have a phone"); |