13.03.2011, 12:32
So I'm making an inventory system, but i don't know how should I assign certain item to a player. Should i make in PlayerInfo enum something like this:
Or there is a way simplier method?
Those are my current functions.
Any suggestions? Maybe functions above can be simplier and shortier?
Код:
pItem1, pItem2, pItem3, pItem4, pItem5, pItem6 ...
Those are my current functions.
pawn Код:
public LoadItems()
{
new string[128], name[128];
new i = 0;
while(i <= MAX_ITEMS)
{
i++;
format(string, sizeof(string), "Items/%d.ini", i);
if(fexist(string))
{
format(name, sizeof(name), "%s", dj(string, "Name"));
ItemInfo[i][iName] = name;
ItemInfo[i][iType] = djInt(string, "Type");
ItemInfo[i][iVar1] = djInt(string, "Var1");
ItemInfo[i][iVar2] = djInt(string, "Var2");
return 1;
}
}
return 1;
}
public AddItem(playerid, itemname[], type, var1, var2)
{
new string[128];
new i = 0;
while(i <= MAX_ITEMS)
{
i++;
format(string, sizeof(string), "Items/%d.ini", i);
if(!fexist(string))
{
new name[128];
djCreateFile(string);
format(name, sizeof(name), "%s", itemname);
djSet(string, "Name", name);
djSetInt(string, "Type", type);
djSetInt(string, "Var1", var1);
djSetInt(string, "Var2", var2);
LoadCertainItem(i);
// HERE I WANT TO ASSIGN CERTAIN ITEM TO FIRST FREE SLOT IN PLAYER INVENTORY
return 1;
}
}
return 1;
}
public LoadCertainItem(itemid)
{
new name[128], string[128];
format(string, sizeof(string), "Items/%d.ini", itemid);
format(name, sizeof(name), "%s", dj(string, "Name"));
ItemInfo[itemid][iName] = name;
ItemInfo[itemid][iType] = djInt(string, "Type");
ItemInfo[itemid][iVar1] = djInt(string, "Var1");
ItemInfo[itemid][iVar2] = djInt(string, "Var2");
return 1;
}