02.12.2009, 09:00
Quote:
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"); |
How can I database it? (IS there a way to plug in the cash system to xtremeadmin2?)
How could i do a /inventory command to see what items i currently hold.
How do i make a player able to drop an item using /dropitem [slot]? (or item name - whichever is easier)
How do i make a player able to /use [item]? (I don't really need to learn to use the effects - maybe in future i will need to request how to get a specific object to work as i want)