Inventory Trading
#1

Hello,

I really could use some help.
I am creating an inventory system.
Everything works fine, but if i want to trade it using /giveitem. It gives the item to ID0.
How can i make it, that INVENTORY_TRADE also receives the ID that is given at /giveitem?

Code:
Код:
//==============================================================================
CMD:giveitem(playerid,params[])
{

    new player1;
	if(IsMuted(playerid))return 1;
	{
   	if(sscanf(params,"u",player1)) return SendClientMessage(playerid,GREY,"USAGE: /giveitem [playerid]");
   	if(!IsPlayerConnectedEx(player1) || player1==playerid)return SendClientMessage(playerid,GREY,"Invalid player ID");
 	ShowInventoryTrade(playerid);
   	}
    return 1;
}
//==============================================================================
public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
{
if(extraid == INVENTORY_TRADE)
    {
        if(response)
        {
        if(modelid == 18631) return SendClientMessage(playerid,-1,"There slot does not have any item. ");
        if(modelid == 346)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a 9mm to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 331)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a set of brass knuckles to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 347)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Silenced 9mm to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 348)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Desert Eagle to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 349)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Shotgun to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 350)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Sawed-off Shotgun to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 351)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a SPAS-12 Shotgun to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 352)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Uzi to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 353)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a MP5 to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 355)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a AK-47 to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 356)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a M4 to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 372)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a TEC-9 to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 357)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Rifle to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 358)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Sniper Rifle to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 371)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Parachute to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 335)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Knife to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 336)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Baseball bat to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 337)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Spade to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 367)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Camera to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 19921)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Toolkit to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 11738)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave a Medkit to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 11736)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave some bandages to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        if(modelid == 325)
        {
        new player1,str[128];
        format(str,sizeof(str),"%s(%i) gave some flowers to %s(%i)",PlayerName(playerid),playerid,PlayerName(player1),player1);
        SendNearbyMessage(playerid,30.0,str,ORANGE);
        RemoveItem(playerid,modelid);
        AddItem(player1,modelid);
        }
        }
        else SendClientMessage(playerid, 0xFF0000FF, "Trading canceled");
    }
return 1;
}
//==============================================================================
stock ShowInventoryTrade(playerid)
{
	new iteminv[21];
	for(new i = 0; i < 20;i++)
	{
	iteminv[i] = InvInfo[playerid][iSlot][i];
	if(InvInfo[playerid][iSlot][i] == 0)
	{
	iteminv[i] = 18631;
	}

	}
	ShowModelSelectionMenuEx(playerid, iteminv,20, "Inventory",INVENTORY_TRADE, 0.0, 0.0,0.0);
	return 1;
}
Reply
#2

Hello!

PHP код:
ShowInventoryTrade(playerid); 
to
PHP код:
ShowInventoryTrade(player1); 
Does it work?
Reply
#3

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

PHP код:
ShowInventoryTrade(playerid); 
to
PHP код:
ShowInventoryTrade(player1); 
Does it work?
I guess it will not, because player1 is not the player who should see the inventory, but that should receive the item that playerid selected.

The simplest approach would be a global variable (per player obviously).

Store the playerid to that var in the code for the command, then in OnPlayerModelSelection you set player1 to that value.
Reply
#4

Ahh, I understood this issue wrong. Thanks!

@jasperschellekens:
When you need help then feel free to ask.
Reply
#5

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

PHP код:
ShowInventoryTrade(playerid); 
to
PHP код:
ShowInventoryTrade(player1); 
Does it work?
Does not work unfortunately. It shows the trade dialog to player1 , but still sends the item to Id 0.

"I guess it will not, because player1 is not the player who should see the inventory, but that should receive the item that playerid selected.

The simplest approach would be a global variable (per player obviously).

Store the playerid to that var in the code for the command, then in OnPlayerModelSelection you set player1 to that value."

Could anyone give me an example on how i can do that?

EDIT: Can this be done by storing the player id into an enum?
Reply
#6

Yes, of course.
This is a global variable:
PHP код:
new playerGiveItem[MAX_PLAYERS]; //under the includes 
And this is your code.
PHP код:
CMD:giveitem(playerid,params[])
{
    new 
player1;
    if(
IsMuted(playerid))return 1;
    {
           if(
sscanf(params,"u",player1)) return SendClientMessage(playerid,GREY,"USAGE: /giveitem [playerid]");
           if(!
IsPlayerConnectedEx(player1) || player1==playerid)return SendClientMessage(playerid,GREY,"Invalid player ID");
         
ShowInventoryTrade(playerid);
         
playerGiveItem[playerid] = player1;
       }
    return 
1;
}
//==============================================================================
public OnPlayerModelSelectionEx(playeridresponseextraidmodelid)
{
    if(
extraid == INVENTORY_TRADE)
    {
        if(
response)
        {
            if(
modelid == 18631) return SendClientMessage(playerid,-1,"There slot does not have any item. ");
            if(
modelid == 346)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a 9mm to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 331)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a set of brass knuckles to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 347)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Silenced 9mm to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 348)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Desert Eagle to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 349)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Shotgun to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 350)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Sawed-off Shotgun to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 351)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a SPAS-12 Shotgun to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 352)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Uzi to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 353)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a MP5 to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 355)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a AK-47 to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 356)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a M4 to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 372)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a TEC-9 to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 357)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Rifle to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 358)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Sniper Rifle to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 371)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Parachute to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 335)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Knife to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 336)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Baseball bat to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 337)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Spade to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 367)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Camera to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 19921)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Toolkit to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 11738)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave a Medkit to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 11736)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave some bandages to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
            if(
modelid == 325)
            {
                new 
str[128];
                
format(str,sizeof(str),"%s(%i) gave some flowers to %s(%i)",PlayerName(playerid),playerid,PlayerName(playerGiveItem[playerid]),playerGiveItem[playerid]);
                
SendNearbyMessage(playerid,30.0,str,ORANGE);
                
RemoveItem(playerid,modelid);
                
AddItem(playerGiveItem[playerid],modelid);
            }
        }
        else 
SendClientMessage(playerid0xFF0000FF"Trading canceled");
    }
    return 
1;
}
//==============================================================================
stock ShowInventoryTrade(playerid)
{
    new 
iteminv[21];
    for(new 
020;i++)
    {
        
iteminv[i] = InvInfo[playerid][iSlot][i];
        if(
InvInfo[playerid][iSlot][i] == 0)
        {
            
iteminv[i] = 18631;
        }
    }
    
ShowModelSelectionMenuEx(playeriditeminv,20"Inventory",INVENTORY_TRADE0.00.0,0.0);
    return 
1;

Reply
#7

Thank you ! It works now, but when i type the command again, it doesn't work.
It literally does nothing.

Edit: It works now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)