Need Help - Items system [sscanf zcmd] - Enums and parameters
#1

So I was busy creating my own items system and I needed to create a command, where you can dynamically add an item to the mysql database.
Everything works, except I think the enums and the parameters don't go together in this way:

Код:
CMD:createitem(playerid, params[])
{
    if(playerVariables[playerid][pAdminLevel] >= 4)
	{
		new
			IDdeItem,
			TypeDeItem,
			NameDeItem[128],
			itemcreatestring[128];
		if(sscanf(params, "ds", TypeDeItem, NameDeItem)) SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/createitem [Type] [Name]");
		
		mysql_query("INSERT INTO items (itemStandard) VALUES ('1')");
		IDdeItem = mysql_insert_id();
		TypeDeItem = systemItems[IDdeItem][iType];
		NameDeItem = systemItems[IDdeItem][iName];
		format(itemcreatestring, sizeof(itemcreatestring),"You have successfully created the item %s Type: %d.", systemItems[IDdeItem][iName], systemItems[IDdeItem][iType]);
		SendClientMessage(playerid, COLOR_GREY, itemcreatestring);

		saveItem(IDdeItem);
	}
		
	return 1;
}
as IG I get: You have succesfully created the item - Type: 0 (even thoughh I entered 3, and it doesn't give the items name as it's mentioned)
Hopefully someone can work me out, looks difficult but I think it's something easy, just something I don't know yet.
Reply
#2

NameDeItem = systemItems[IDdeItem][iName];

You set the value of NameDeItem to systemItems[IDdeItem][iName].
It shoukd be the other way around:
systemItems[IDdeItem][iName] = NameDeItem;
Same for TypeDeItem = ...
And IDdeItem = ...
Reply
#3

Thank you alot!
Didn't know that would matter!

now another small issue:
It saves the item name and type in a new file in the mySQL database, but it also overwrites all the previous ones: So instead of:

ID: Type: Name:
1 1 Cigar
2 2 Beer
3 3 Sprunk

I get:

ID: Type: Name:
1 1 Beer
2 1 Beer
3 1 Beer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)