#1

I want to make a Command that shows something okay for example

Player have 2/5 Paper and 3/5 Phones in database

the cmd is /show [itemname/partofname]

so when the player do /show paper or /show pap
it gives him "paper 2/5"

I don't want to make that stuff "if(strcmp(item, "paper", true) == 0)"

cuz that will take so loonnng to make like 49 item !
I wanna know if there is a away the make PlayerInfo[playerid][%s] and the %s is depends on the Item name just like when you're making a string.. etc etc
Reply
#2

Код:
PlayerInfo[playerid][%s]
No, it's not possible to do that.

However, you can do like this:
Код:
// In example, you have item enum like this
enum e_Items
{
	item_burger,
	item_soda,
	item_rope,
	// ....
}
new PlayerItems[MAX_PLAYERS][e_Items]; // and this variable for playeritems

// Variable for item names, must be in same order as item enum
static const
	s_itemnames[][] = {	
		{!"Burger" }, 
		{!"Soda" }, 
		{!"Rope" }
	}
;

e_Items:GetItemEnum(name[])
{
	for(new i; i < 3; i++)
	{
		if (strfind(s_itemnames[i], name, true) != -1)
			return e_Items:i;
	}
	return e_Items:-1;
}

CMD:show(playerid, params[])
{
	new itemname[28];
	if(sscanf(params, "s[28]", itemname))
		return SendClientMessage(playerid, -1, "Usage: /show [itemname]");

	new e_Items:itemenum = GetItemEnum(itemname);
	if(itemenum == e_Items:-1)
		return SendClientMessage(playerid, -1, "Invalid item name");

	new fmt[128];
	format(fmt, 128, "You have %d %s", PlayerItems[playerid][itemenum], s_itemnames[_:itemenum]);
	SendClientMessage(playerid, -1, fmt); // ex: You have 3 Burger
	return 1;
}
Reply
#3

Thanks, It's working fine ! but there's something that when you type /show burg ! it prints "You have 3 burg" Instead of "You have 3 Burger" +REP btw.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)