[Tutorial] /shop
#1

Introduction
__________________
Hello guys, this is my first tutorial, and today we will be making a /shop or /buygun depending if you want it on a Roleplay or a DeathMatch server. Im gonna try to make this simple as possible. So Lets get started.
___________________________________________
Step 1:Lets start off by opening up a new pawno, adding #define DIALOG_WEAPONS 1 under #include <a_samp>. After that is done we are going to make the cmd name (full script will be shown after).
Code:
if (strcmp("/buygun", cmdtext, true, 10) == 0)
Im just gonna start dragging the script in so its a little faster
Step 2: Adding the dialog, the dialog is one of the most important things in this script, we are going to use a List box for the dialog.
Code:
ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\nAK-47\nCombat Shotgun\nM4\nShotgun\n[add a gun here]", "Select", "Close");
Put that under
Code:
if (strcmp("/buygun", cmdtext, true, 10) == 0)
{
So it looks like this:
Code:
if (strcmp("/buygun", cmdtext, true, 10) == 0)
{
ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\nAK-47\nCombat Shotgun", "Select", "Close");
     return 1;
      }
   return 0;
}
Your pretty Much done with that. You can add:
Code:
if (IsPlayerInRangeOfPoint(playerid,"x,y,z"); 
ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\nAK-47\nCombat Shotgun", "Select", "Close");
else
SendClientMessage(playerid,color_red,"Your not at the right point");
return 1;
If you want it to be in a interior or anywhere. Now lets do our OnDialogResponse

_____________________
Now usally you can fine the OnDialogResponse in a new pawno, or easydialog by Emmet_ So you can use either of those but im gonna use the one in pawno.
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
     
    if(dialogid == DIALOG_WEAPONS)
    {
        if(response) // If they clicked select.
        {
            // Give them the weapon
            if(listitem == 0) // They selected the  Desert Eagle
            {
                GivePlayerWeapon(playerid, 24, 2000); // Give them a desert eagle
                // You can add GivePlayerMoney(playerid, -2000) if you want it to take money, you can do it on all of the weapons you want
            }
            if(listitem == 1) // They selected the second item - AK-47
            {
                GivePlayerWeapon(playerid, 31, 120); // Give them an AK-47
            }
            if(listitem == 2) // They selected the third item - Desert Eagle
            {
                GivePlayerWeapon(playerid, 27, 28); // Give them a Combat Shotgun
            }
            if(listitem == 3)  // if they chose m4
            {
            GivePlayerWeapon(playerid,31,30);
            }
            if(listitem == 4) // they chose shotgun
        }
        return 1; 
    }
Here is the full code
Code:
if (strcmp("/buygun", cmdtext, true, 10) == 0)
{
ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\nAK-47\nCombat Shotgun", "Select", "Close");
     return 1;
      }
   return 0;
}
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_WEAPONS)
    {
        if(response) // If they clicked 'Select' or double-clicked a weapon
        {
            // Give them the weapon
            if(listitem == 0) // They selected the first item - Desert Eagle
            {
                GivePlayerWeapon(playerid, WEAPON_DEAGLE, 14); // Give them a desert eagle
            }
            if(listitem == 1) // They selected the second item - AK-47
            {
                GivePlayerWeapon(playerid, 31, 120); // Give them an AK-47
            }
            if(listitem == 2) // They selected the third item - Desert Eagle
            {
                GivePlayerWeapon(playerid, 27, 28); // Give them a Combat Shotgun
            }
            if(listitem == 3)
            {
            GivePlayerWeapon(playerid,41,30);
             }
             if(listitem == 4)
             {
               GivePlayerWeapon(playerid, 25, 30);
        }
        return 1; 
    }
 
    return 0; 
}
Credits to:
Emmet_ for easy dialog
cluckintucker
Download
EasyDialog include by Emmet_ http://www.pastebin.com/raw.php?i=TGKmPZQa
Full Dialog weapon script by cluckin tucker http://pastebin.com/rcYLXytc
Reply
#2

This tutorial is horrible, you didn't explain what the functions/etc are, you just said add this, under this. You are suppose to define the information.

Also, I'm pretty sure almost everyone knows how to do this...

3/10
Reply
#3

sir i think this is pretty good for new scripters like me
Reply
#4

Nice,but very simple tutorial
Reply
#5

Quote:
Originally Posted by Plovix
View Post
Nice,but very simple tutorial
Thanks
Reply
#6

Good for beginners.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)