SA-MP Forums Archive
Loop through 3D Array - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loop through 3D Array (/showthread.php?tid=583532)



Loop through 3D Array - jeffery30162 - 28.07.2015

Here is what im working with for testing purposes:
Код:
new Items[][3][] =
{   //ItemID/////Category///Name/////
	{0000,0,"Blank"},
	{1650,0,"Gas Can"},
	{3409,0,"Marijuana"},
	{2216,0,"Snack"},
	{2033,0,"Matches"}
};

stock GetInventoryItemNames(itemid)
{
    new itemname[256];
	for(new idx=1; idx< sizeof(Items); idx++)
	{
	    if(itemid==Items[idx][0])
	    {
	        format(itemname, 256, Items[idx][2]);
	        break;
	    }
	}
return itemname;
}

CMD:getitemname(playerid, params[])
{
	new id, string[256];
	if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GREY, "This command does not exist.");
	if(sscanf(params,"i", id)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /GetItemName id");
	format(string, sizeof(string), "%d: %s", id, GetInventoryItemNames(id));
	SendClientMessage(playerid, COLOR_BLUE, string);
return 1;
}
When i compile I get:
Код:
array must be indexed (variable "Items")
at
Код:
if(itemid==Items[idx][0])



AW: Loop through 3D Array - Nero_3D - 28.07.2015

Its only a 2d array
pawn Код:
new Items[][] =
{   //ItemID/////Category///Name/////
    {0000,0,"Blank"},
    {1650,0,"Gas Can"},
    {3409,0,"Marijuana"},
    {2216,0,"Snack"},
    {2033,0,"Matches"}
};



Re: Loop through 3D Array - jeffery30162 - 29.07.2015

lol, i got it working now