17.04.2013, 12:08
Hello everyone.
i am making inventory system, and i wanna loop items then check if item was the selected at
How possible can i do this.
If you didnt understand, i ill give you example.
I've 2 items, 1 is medkit and the 2nd is anti-virus.
i've made loop for items (This step works fine).
Then i've made another loop on
to check item's type but it only works for listitem number 0.
Here is my code.
When i select the 2 listitem, listiem number 0 will be called.
i am making inventory system, and i wanna loop items then check if item was the selected at
pawn Код:
OnDialogResponse
If you didnt understand, i ill give you example.
I've 2 items, 1 is medkit and the 2nd is anti-virus.
i've made loop for items (This step works fine).
Then i've made another loop on
pawn Код:
OnDialogResponse
Here is my code.
pawn Код:
#define MAX_ITEMS 20
enum pInv
{
Items,
Type[MAX_ITEMS],
Medkit,
Antivirus,
};
new Inventory[MAX_PLAYERS][pInv];
stock GivePlayerItem(playerid,itemid)
{
switch(itemid)
{
case MEDKIT:
{
Inventory[playerid][Medkit]++;
Inventory[playerid][Items]++;
}
case ANTIVIRUS:
{
Inventory[playerid][Antivirus]++;
Inventory[playerid][Items]++;
}
}
UpdateInventory(playerid);
}
stock RemovePlayerItem(playerid,itemid)
{
switch(itemid)
{
case MEDKIT:
{
Inventory[playerid][Medkit]--;
Inventory[playerid][Items]--;
}
case ANTIVIRUS:
{
Inventory[playerid][Antivirus]--;
Inventory[playerid][Items]--;
}
}
UpdateInventory(playerid);
}
stock UpdateInventory(playerid)
{
new i;
if( Inventory[playerid][Items] == 0) return 0;
for(i = 0; i < Inventory[playerid][Items]; i++)
{
Inventory[playerid][Type][i] = MEDKIT;
if(i == Inventory[playerid][Medkit])
{
break;
}
}
for(new v = i; v < Inventory[playerid][Items]; v++)
{
Inventory[playerid][Type][v] = ANTIVIRUS;
if(v == Inventory[playerid][Antivirus])
{
break;
}
}
return 1;
}
CMD:inv(playerid,params[])
{
new strct[1200];
if(Inventory[playerid][Items] == 0) return SendClientMessage(playerid,COLOR_LIGHTBLUE,"** You dont have any item in your inventory **");
for(new i = 0;i<Inventory[playerid][Items];i++)
{
if(Inventory[playerid][Type][i] == MEDKIT)
{
strcat(strct,"Medkit \t\t\t "RED"(20 HP) \n");
}
else if(Inventory[playerid][Type][i] == ANTIVIRUS)
{
strcat(strct,"Anti-virus\t\t "Gold"(Only for one round)\n");
}
}
ShowPlayerDialog(playerid,DIALOG_INVENTORY,DIALOG_STYLE_LIST,"Inventory",strct,"Use","Clsoe");
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_INVENTORY)
{
new string[120];
if(response)
{
for(new i =0; i < Inventory[playerid][Items]; i++)
{
if(Inventory[playerid][Type][i] == MEDKIT)
{
format(string,sizeof string,"%s has used "Gold"medkit!",GetPlayerNameEx(playerid));
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
Inventory[playerid][Type][i] = 0;
RemovePlayerItem(playerid,MEDKIT);
new Float:Health;
GetPlayerHealth(playerid,Health);
SetPlayerHealth(playerid,Health+20);
break;
}
else if(Inventory[playerid][Type][i] == ANTIVIRUS)
{
format(string,sizeof string,"%s has used "Gold"anti-virus!",GetPlayerNameEx(playerid));
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
Inventory[playerid][Type][i] = 0;
RemovePlayerItem(playerid,ANTIVIRUS);
Anti_virus[playerid] = true;
break;
}
}
}
}
return 1;
}