SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 05/07/2019, 09:07 PM   #11
Fuzzy
Big Clucker
 
Join Date: May 2019
Posts: 94
Reputation: 5
Default Re: How to give weapons after they choosed?

Quote:
Originally Posted by Edvukas View Post
Here is add instantly nos. There is example: /weapons > I choose weapon > When I click "Cancel" it give me weapons which I choosed
this is an example for the dialog

Its need to be like that /weapons > Dialog opens > List of guns > choosing gun > Dialog closed > player gets the gun.
Same like the nos just change it to guns and add it to the cmd
__________________
My Releases:
Tutorial:
Gamemode:
Fuzzy is offline   Reply With Quote
Old 05/07/2019, 09:12 PM   #12
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: How to give weapons after they choosed?

Create an array for the weapons and use listitem as index. Saves a lot of typing and you can reuse the array for other stuff.
Example:
Code:
//if you use different types, use an enum
enum exampleEnum {
   wName[30],
   wID.
   wAmmo,
   wPrice
}
new weaponArray[][exampleEnum] = {
   {"M4", WEAPON_M4,500,2000},
   {...}
};
//OnDialogResponse
GivePlayerWeapon(playerid, weaponArray[listitem][wID],weaponArray[listitem][wAmmo]);
Plastikmensch is offline   Reply With Quote
Old 06/07/2019, 02:50 AM   #13
SiaReyes
Gangsta
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 614
Reputation: 57
Default Re: How to give weapons after they choosed?

Quote:
Originally Posted by Edvukas View Post
How can I save player's options and then give him weapons which he choosed?
I'll just give an example

pawn Code:
new SelectedWeapon[MAX_PLAYERS] = 0; // Put this on top

public OnPlayerConnect(playerid)
{

  SelectedWeapon[playerid] =0; // reset
   return 1;
}

// Under OnDialogResponse
   if(dialogid == Weapons)
  {
        if(!response) return true;
        if(response)
        {
                   SelectedWeapon[playerid] = listitem+1; // is case 0 , it will be 0+1 = 1, so take 1 as eagle and 2 as some other weapon id
          }    
    }                        
 

// Function to give player selected weapons
stock GivePlayerSelectedWeapon(playerid)
{
       if(SelectedWeapon[playerid] == 0) return true; // it's not needed but just a simple check
        switch(SelectedWeapon[playerid])
        {
                 case 1 :  GivePlayerWeapon(playerid, 24, 500);  // deagle
                 case 2 : GivePlayerWeapon(playerid, 25, 500); // some other weapon
         }
}
SiaReyes is offline   Reply With Quote
Old 06/07/2019, 02:01 PM   #14
Edvukas
Little Clucker
 
Join Date: Nov 2018
Posts: 18
Reputation: 0
Default Re: How to give weapons after they choosed?

I think you guys don't understand me :/ I want to make 2 weapons dialogues in first dialogue player choose 1 weapon and in second dialogue he chooses second weapon and when he close dialogue he get them. Example: I type /weapons > I choose desert eagle in first dialogue but I don't get it now > I choose m4 in second dialogue also I don't get it now > When I click "Cancel" I get weapons which I have choosed
Edvukas is offline   Reply With Quote
Old 06/07/2019, 02:23 PM   #15
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: How to give weapons after they choosed?

Why when the player presses cancel? That is not how dialogs work.
Code:
new chosenWeapons[MAX_PLAYERS][2];

//OnDialogResponse
//Dialog 1
if(response) 
{
   chosenWeapons[playerid][0]=weaponid;//weaponid is a placeholder
   ShowPlayerDialog(...);//Dialog 2
}
//Dialog 2
if(response)
{
   chosenWeapons[playerid][1]=weaponid;//this line isn't necessary, if you give weapons here.
   GivePlayerWeapon(playerid,chosenWeapons[playerid][0], ammo);//ammo placeholder for your amount
   GivePlayerWeapon(...);
}
Plastikmensch is offline   Reply With Quote
Old 06/07/2019, 03:30 PM   #16
Edvukas
Little Clucker
 
Join Date: Nov 2018
Posts: 18
Reputation: 0
Default Re: How to give weapons after they choosed?

pawn Code:
CMD:weapons(playerid,params[])
{
    new info[2000], string[150];
    for(new i = 0; i < MAX_WEAPONS; i++)
    {
    format(string, sizeof string, "%s\n", weaponArray[i][wName]);
    strcat(info, string);
    }
    ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "First gun", info, "Choose", "Cancel");
    }
    return 1;
}


if(dialogid == DIALOG_WEAPONS)
    {
        if(response)
        {
            if(listitem >= 0)
            {
                new info[2000], string[150];
                for(new i = 0; i < MAX_WEAPONS2; i++)
                {
                format(string, sizeof string, "%s\n", weaponArray2[i][wName]);
                strcat(info, string);
                }
                ShowPlayerDialog(playerid, DIALOG_WEAPONS2, DIALOG_STYLE_LIST, "Second Gun", info, "Done", "Cancel");
            }
        return 1;
    }
}

if(dialogid == DIALOG_WEAPONS2)
    {
        if(response)
        {
            if(listitem >= 0)
            {
                GivePlayerWeapon(playerid, weaponArray[listitem][wID],weaponArray[listitem][wAmmo]);
                GivePlayerWeapon(playerid, weaponArray2[listitem][wID],weaponArray2[listitem][wAmmo]);
            }
        return 1;
    }
}
what's wrong with this code? Because I get only second dialogue's weapon choosed weapons

Last edited by Edvukas; 06/07/2019 at 04:23 PM.
Edvukas is offline   Reply With Quote
Old 06/07/2019, 06:20 PM   #17
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 272
Reputation: 22
Default Re: How to give weapons after they choosed?

You have to save the listitem in the first dialog in a global (or local in OnDialogResponse) variable.
listitem >= 0 is unnecessary, because it will always be 0 or greater.
Code:
new selectedWeapon[MAX_PLAYERS];
if(dialogid==DIALOG_WEAPONS)
{
   if(response)
   {
      selectedWeapon[playerid]=listitem;
      //Your code
   }
}
if(dialogid == DIALOG_WEAPONS2)
{
   if(response)
   {
      GivePlayerWeapon(playerid, weaponArray[selectedWeapon[playerid]][wID],weaponArray[selectedWeapon[playerid]][wAmmo]);
      GivePlayerWeapon(playerid, weaponArray2[listitem][wID],weaponArray2[listitem][wAmmo]);
   }
}
Plastikmensch is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Doesn't give weapons TheNerka Scripting Help 0 16/10/2014 05:39 AM
How to give weapons to All with one CMD? MAFIAWARS Scripting Help 5 26/09/2013 08:16 AM
Give player weapons from name Snowman12 Scripting Help 6 14/01/2012 01:46 AM
Give weapons when you tele? Quest123 Help Archive 1 30/10/2009 10:43 AM
Command To Give Weapons Dmac_91 Help Archive 4 27/05/2009 08:19 AM


All times are GMT. The time now is 06:58 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.