23.01.2017, 21:56
hi all.
i havent been coding PAWN for a long time but i started again as i have some free time.
is there a better way of doing this ? basically what i'm doing is a sell / accept command.
the command verify if the item the player want to sell is valid ( so they dont sell a zippo if i dont want a zippo in the game ). i'll add other valid item at a later time as needed.
i'm using Player Inventory fromJoe Staff
https://sampforum.blast.hk/showthread.php?tid=130436
everything seems to work , but i dont like how it look and how many lines of code it need.
i havent been coding PAWN for a long time but i started again as i have some free time.
is there a better way of doing this ? basically what i'm doing is a sell / accept command.
the command verify if the item the player want to sell is valid ( so they dont sell a zippo if i dont want a zippo in the game ). i'll add other valid item at a later time as needed.
i'm using Player Inventory fromJoe Staff
https://sampforum.blast.hk/showthread.php?tid=130436
everything seems to work , but i dont like how it look and how many lines of code it need.
Код:
YCMD:sell(playerid, params[], help) { if (help) { } else { new targetid, itemname[20], itemprice, itemamount, HasManyItem; if(PlayerInfo[playerid][pJob] == 2) { if(sscanf(params, "s[20]iiu", itemname, itemamount, itemprice, targetid)) return SendClientMessage(playerid, 0xFFFFFFF,"Syntax error.Correct usage: /sell [itemname] [amount] [price [playerid]]"); if(!strcmp(itemname, "IRON", true) || !strcmp(itemname, "ALUMINIUM", true) || !strcmp(itemname, "COPPER", true)) { for(new i, len = strlen(itemname); i < len; ++i) { itemname[i] = toupper(itemname[i]); } if(PlayerHasItem(playerid, itemname)) { HasManyItem = PlayerHasItem(playerid, itemname); if(HasManyItem <itemamount) { SetPVarString(playerid, "itemname", itemname); SetPVarInt(playerid, "amount", itemamount); SetPVarInt(playerid, "price", itemprice); Offering[playerid] = true; Pending[targetid] = true; SendClientMessageFormatted(targetid, COLOR_ORANGE, "%s want to sell you %i %s for $%i. type /accept to accept.", GetName(targetid), itemamount, itemname, itemprice); SendClientMessageFormatted(playerid, COLOR_ORANGE, "You offered %s to %s", itemname, GetName(playerid)); } } } else { SendClientMessageFormatted(playerid, -1, "Invalid item [%s]", itemname); } } } return 1; } YCMD:accept(playerid, params[], help) { if (help) { } else { new targetid, itemname[20], itemprice, itemamount; if(PlayerInfo[playerid][pJob] == 3) { if(sscanf(params, "s[20]iu", itemname, itemamount, targetid)) return SendClientMessage(playerid, 0xFFFFFFF,"Syntax error.Correct usage: /sell [itemname] [amount] [price [playerid]]"); for(new i, len = strlen(itemname); i < len; ++i) { itemname[i] = toupper(itemname[i]); } if(Pending[playerid] == true) { if(Offering[targetid] == true) { if(GetPlayerMoney(playerid) <itemprice) { if(sscanf(params, "%s[20]u", itemname, targetid)) SendClientMessage(playerid, 0xFFFFFFF,"Syntax error.Correct usage: /accept [itemname] [playerid]]"); GetPVarString(targetid, "itemname", itemname, sizeof(itemname)); itemamount = GetPVarInt(targetid, "amount"); itemprice = GetPVarInt(targetid, "price"); Offering[targetid] = false; Pending[playerid] = false; SendClientMessageFormatted(playerid, -1, "You accepted", itemname, itemamount, itemprice, GetName(targetid)); RemoveItem(targetid, itemname, itemamount); AddItem(playerid, itemname, itemamount); GivePlayerMoney(targetid, itemprice); GivePlayerMoney(playerid, -itemprice); DeletePVar(targetid, "itemname"); DeletePVar(targetid, "amount"); DeletePVar(targetid, "price"); } } } } } return 1; }