Help with Dialog
#1

I am creating a dialog which will display weapons to sell. The user selling the weapons will type a command "/sellweapon [playerid]". The player that is buying the weapon will see the dialog and will get the option to buy the weapons.
So far everything is working except the part where the player selling the weapon gets the money from the player buying the weapons.

Ex:
1. I initiate selling weapons /sellweapon 2
2. Player id 2 gets the dialog and is able to choose and buy the weapons.
3. Player id 2 gets money taken away and weapon is given
4. Player who initiated the selling does not get any money from player id 2.

What will be the correct way to get the results of the dialog to the player that initiated the command (in this case the person selling the weapons?).
Reply
#2

I would suggest setting a variable containing the seller id to the player who's buying (In your example, 2) The variable is set when the seller uses the command /sellweapon
When the player id2 buys a gun, the money removed from him & you'll be able to access the seller's ID ( SetPVarInt, GetPVarInt). So everything would be in the OnPlayerDialogResponce to be able to know if the buyer bought a gun or no.
Reply
#3

I am not really understanding it. I have the code below that I am working on:

Defined above:
pawn Код:
#define DIALOG_SELLWEAPON 1384
The command:
pawn Код:
CMD:sellweapons(playerid, params[])
{
    new giveplayerid;
    if(sscanf(params, "i", giveplayerid)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /offerweapons [Playerid]");
    ShowPlayerDialog(giveplayerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
    return 1;
}
On Dialog Reponse:
pawn Код:
if(dialogid == DIALOG_SELLWEAPON)
{
    if(response == 0)
    {
        SendClientMessage(playerid, COLOR_ERROR, "You canceled the purchase.");
        return 1;
    }
    switch(listitem)
    {
        case 0:
        {
            if(GetPlayerMoney(playerid) < 2500)
            {
                SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase Failed_|");
                SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy a Silenced 9mm");
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
                return 1;
            }
            GivePlayerMoney(playerid,-2500);
            SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase_|");
            SendClientMessage(playerid, 0x00C7FFAA, "You have bought a Silenced 9mm. You were charged $2500");
            GivePlayerWeapon(playerid,23,100);
            ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
        }
        case 1:
        {
            if(GetPlayerMoney(playerid) < 3900)
            {
                SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase Failed_|");
                SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy Tec9 ($3900)");
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
                return 1;
            }
            GivePlayerMoney(playerid,-3900);
            SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase_|");
            SendClientMessage(playerid, 0x00C7FFAA, "You have bought Tec9. You were charged $3900");
            GivePlayerWeapon(playerid,32,500);
            ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
        }
        case 2:
        {
                    if(GetPlayerMoney(playerid) < 4000)
            {
                SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase Failed_|");
                SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy a Sawn Off Shotguns ($4000)");
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
                return 1;
            }
            GivePlayerMoney(playerid,-4000);
            SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase_|");
            SendClientMessage(playerid, 0x00C7FFAA, "You have bought a Sawn Off Shotguns. You were charged $4000");
            GivePlayerWeapon(playerid,26,30);
            ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
        }
        case 3:
        {
                    if(GetPlayerMoney(playerid) < 20000)
            {
                      SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase Failed_|");
                  SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy Sniper Rifle ($20000)");
                  ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
            return 1;
            }
            GivePlayerMoney(playerid,-20000);
            SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase_|");
            SendClientMessage(playerid, 0x00C7FFAA, "You have bought Sniper Rifle. You were charged $20000");
            GivePlayerWeapon(playerid,34,30);
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
        }
        case 4:
        {
                  if(GetPlayerMoney(playerid) < 8000)
              {
                    SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase Failed_|");
                SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy a AK-47 ($8000)");
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
            return 1;
            }
             GivePlayerMoney(playerid,-8000);
             SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase_|");
             SendClientMessage(playerid, 0x00C7FFAA, "You have bought a AK-47. You were charged $8000");
                GivePlayerWeapon(playerid,30,200);
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
            }
            case 5:
            {
                if(GetPlayerMoney(playerid) < 500)
                {
                    SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase Failed_|");
                    SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy Armor ($500)");
                    ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
                    return 1;
                }
                GivePlayerMoney(playerid,-500);
                SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase_|");
                SendClientMessage(playerid, 0x00C7FFAA, "You have bought Armor. You were charged $500");
                SetPlayerArmour(playerid, 100);
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
            }
            case 6:
            {
                if(GetPlayerMoney(playerid) < 4000)
                {
                    SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase Failed_|");
                    SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy 3 Blocks of C4 ($4000)");
                    ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
                    return 1;
                }
                if(HasC4[playerid] == 1)
                {
                    SendClientMessage(playerid, COLOR_ERROR, "You already have C4 on you. You cannot buy more C4.");
                    return 1;
                }
                GivePlayerMoney(playerid,-4000);
                SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Dealer Purchase_|");
                SendClientMessage(playerid, 0x00C7FFAA, "You have bought 3 Blocks of C4. You were charged $4000");
                HasC4[playerid] =1;
                ShowPlayerDialog(playerid, DIALOG_SELLWEAPON, DIALOG_STYLE_LIST, "{33CCFF}Weapon Dealer","{33CCFF}1. {FFFFFF}[100 Ammo] Silenced 9mm ($2500)\n{33CCFF}2. {FFFFFF}[500 Ammo] Tec9 ($3900)\n{33CCFF}3. {FFFFFF}[30 Ammo] Sawn Off Shotguns ($4000)\n{33CCFF}4. {FFFFFF}[30 Ammo] Sniper Rifle ($20000)\n{33CCFF}5. {FFFFFF}[200 Ammo] AK-47 ($8000)\n{33CCFF}6. {FFFFFF}Armor ($500)\n{33CCFF}7. {FFFFFF}3 Blocks of C4 ($4000)","Okay","Cancel");
            }
        }
    }
Reply
#4

1. define a new variable in which you will store the seller's id.

Код:
new Seller[MAX_PLAYERS];
2. assign that variable in /sellweapons:

Код:
Seller[giveplayerid] = playerid;
3. Give the money to the seller in ondialogresponse:

Код:
GivePlayerMoney( SellPartner[playerid], 5000);
Seller[playerid] = -1;
4. Initialize the variable in OnPlayerConnect ( It's optional but I prefer to initialize it to avoid garbage )
Код:
Seller[playerid] = -1;
Reply
#5

Thank you so much to both. Especially Kincaid. I got it to work all nicely one small change is to change GivePlayerMoney(Seller[playerid], 5000); as opposed to SellPartner. +Rep
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)