[Tutorial] Easy Weapons-Dialog System!
#1

INTRODUCTION

Hi,this is my first tutorial.In this tutorial you'll be able to learn How To Make An Easy Weapons-Dialog System.

REQUIREMENTS

Basic Pawn Scripting Knowledge
ZCMD

LET'S GET STARTED


Step 1:

Go open up Pawno and then press File --> New.
You'll see a bunch of codes just select them all and press delete button.

Step 2:

Now to the scripting.On the first few lines type in:
pawn Код:
#include <zcmd>
#define DIALOG_WEAPONS 67
main(){}
#include <zcmd> :
This will include zcmd.inc ,we need it to script out /weapons command.

#define DIALOG_WEAPONS 67 :
When we do the command /weapons a dialog(box) will open ,we need to define that dialog.67 is the id of the dialog box,you can use any number you like as long as no other dialogs or anything has that same id.

main(){} :
We just need that before making any script.


Step 3:

Since this is completely a new pwn file we have to add a few player classes.If we don't when we click the spawn button in game the screen will start blinking yellow and 'STAY WITHIN WORLD BOUNDARIES'.
Add this a line after "main(){}"
pawn Код:
public OnGameModeInit()
{
        AddPlayerClass(265,1723.8688,-1630.1272,20.2140,1.0711,24,1000,27,1000,29,1000); // Cops1
            AddPlayerClass(107,2508.1628,-1655.6744,13.5938,138.6173,24,1000,27,1000,29,1000); // Grove1
    return 1;
}


Step 4:

Now lets script our weapons command.Add this after adding your player classes.
pawn Код:
CMD:weapons(playerid, params[])
{
    ShowPlayerDialog(playerid,DIALOG_WEAPONS, DIALOG_STYLE_LIST,"Weapons", "Deagle 2500$\nMP5 3000$\nAK-47 4500$\nM4 4500$", "Select", "Cancel");
    return 1;
}
CMD:weapons(playerid, params[])
CMD:weapons,in that 'weapons' is the command you will be using in game to open the dialog box. Playerid is the id of the player who will use the command. Params are the parameters of the command.

ShowPlayerDialog(playerid,DIALOG_WEAPONS, DIALOG_STYLE_LIST,"Weapons","weaponnames","Select" ,"Cancel");
ShowPlayerDialog shows the dialog to the player.Player id is the id of the player who uses /weapons to see the dialog box.
DIALOG_WEAPONS,remember before we started scripting we defined a dialog with the id 67 (#define DIALOG_WEAPONS 67)we add that name or the id we had entered there on top so that the script and recognize which dialog it is.
DIALOG_STYLE_LIST ,it just tells the style of the dialog box.In this one the names in the dialog box would appear in style of a list.
"Weapons" is the title/heading of Dialog Box.In place of "weaponnames" we add the names of the weapon with its price.
"Select" and "Cancel" are just buttons of the dialog box.


Step 5:

Now lets working on the response for the dialog box.After entering the code above,just add this on the next line.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_WEAPONS)
    {
    switch(listitem)
    {
    case 0:
    {
        if(GetPlayerMoney(playerid) <= 2500)
    return SendClientMessage(playerid, 0x0000FFAA, "You don't have enough cash to buy this Weapon.");
    GivePlayerMoney(playerid, -2500);
    GivePlayerWeapon(playerid, 24, 1000);
    SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");
    }
    case 1:
    {
        if(GetPlayerMoney(playerid) <= 3000)
    return SendClientMessage(playerid, 0x0000FFAA, "You don't have enough cash to buy this Weapon.");
    GivePlayerMoney(playerid, -3000);
    GivePlayerWeapon(playerid, 29, 1000);
    SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");
    }
    case 2:
    {
        if(GetPlayerMoney(playerid) <= 4500)
    return SendClientMessage(playerid, 0x0000FFAA, "You don't have enough cash to buy this Weapon.");
    GivePlayerMoney(playerid, -4500);
    GivePlayerWeapon(playerid, 30, 1000);
    SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");
    }
    case 3:
    {
        if(GetPlayerMoney(playerid) <= 4500)
    return SendClientMessage(playerid, 0x0000FFAA, "You don't have enough cash to buy this Weapon.");
    GivePlayerMoney(playerid, -4500);
    GivePlayerWeapon(playerid, 31, 1000);
    SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");
    }
    }
    }
    return 0;
    }
OnDialogResponse
OnDialogResponse ,it is just a callback used for making a response/outcome from the dialog box when a player selects and item of the DialogBox.In this case if a weapon the DialogBox will response according to how we code him.

if(dialogid == DIALOG_WEAPONS)
This if statement just checks if the dialogid matches to dialog id/dialog name we had defined at first.

switch(listitem)
It just switches between each cases/items in the list.

Now you see a total of 4 cases.There are only 4 cases cause I have added only 4 weapons in dialog box ,you can add more(I'll show you how to later.).Each case has its differences but only 2 things.The weapon id and the price of the weapon.

pawn Код:
if(GetPlayerMoney(playerid) <= 2500)
return SendClientMessage(playerid, 0x0000FFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -2500);
GivePlayerWeapon(playerid, 24, 1000);
SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");
if(GetPlayerMoney(playerid) <= 2500)
return SendClientMessage(playerid, 0x0000FFAA, "You don't have enough cash to buy this Weapon.");

if(GetPlayerMoney(playerid) < 2500) checks if the player who selected a particular weapon (in this case deagle which has a price of 2500)has the money to buy that weapon,even if its only a dollar lesser than the price of the weapon the server will send a message to the player telling him he doesn't have enough cash to buy that weapon.0x0000FFAA is a HEX color code.You can find more of these if you search it in ******.
NOTE:- The player still can buy the weapon if he has the exact amount of the weapon too.
GivePlayerMoney(playerid, -2500);
GivePlayerWeapon(playerid, 24, 1000);
SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");

GivePlayerMoney(playerid, -2500):Now if he has the the money to buy that particular weapon ,the server will subtract the price of the weapon from how much ever money the player has.
GivePlayerWeapon(playerid, 24, 1000);:But for the server to subtract the money the player has to select his choice of weapon first.After he selects it,'GivePlayerWeapon' will give the weapon.Here "24" is the id of the weapon and "1000" is the ammo of the weapon.
SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");:This message will be shown in the chat screen if the player has brought his weapon succesfully.
Note(s):
-To add more weapons in the dialog box.In 'ShowPlayerDialog' add any weapon name and price you want.Just like how its added in the tutorial.And then make a new case in OnDialogResponse.In GivePlayerWeapon correct the first number after 'playerid',with the id of the weapon you want.And on GivePlayerMoney and GetPlayerMoney correct the price of the weapon.
-If you receive a warning 'loose indentation' add this to the top of your script after include <zcmd>
pawn Код:
#pragma tabsize 0
That warning comes only if the brackets are correctly and neatly placed.


Thanks for reading! Hope you understood it!
REP + if this helped you out!
Reply
#2

Change GetPlayerMoney(playerid) < 2500 to GetPlayerMoney(playerid) <= 2500.
with your code If player has the exact 2500 can't buy it and must have 2501 to able to buy.
but with mine code player can buy with 2500.

This is like my release https://sampforum.blast.hk/showthread.php?tid=502177 Dialog-in-Dialog and configurable prices with Y_INI but helpful +rep
Reply
#3

EDIT:
Oh yea! Thanks.Didn't think of that.

Thanks! and I really like that part of your script where you just don't need to go in code and edit the prices and all!I'll download it soon
Thanks for REP !
Reply
#4

Quote:
Originally Posted by NviDa
Посмотреть сообщение
Thanks! and I really like that part of your script where you just don't need to go in code and edit the prices and all!I'll download it soon
Thanks for REP !
Yes you go in the INI File and set the prices manually. this is good for begginners in PAWN.
Reply
#5

Nice tutorial, useful for newbies
Reply
#6

Код:
You have succesfully buyed your weapon
Its Bought not Buyed...
Reply
#7

Thank you guys!
Reply
#8

Actually a simple thing, can be learned from wiki without help and explenation. But good job anyway, I can see you did a great job making this, put a lot of effort in it, and explained a lot.
Quote:

Change GetPlayerMoney(playerid) < 2500 to GetPlayerMoney(playerid) <= 2500.

Just saying, I hate using two orperators at one place (except at cases where we have to use " == ") so people who are just like me can use
pawn Код:
if(GetPlayerMoney(playerid) < 2499)
I like mathematical numbers more than orperators, it's just how I like it.
Reply
#9

Quote:
Originally Posted by iFarbod
Посмотреть сообщение
Change GetPlayerMoney(playerid) < 2500 to GetPlayerMoney(playerid) <= 2500.
with your code If player has the exact 2500 can't buy it and must have 2501 to able to buy.
but with mine code player can buy with 2500.
Nonsense. The first way is correct. With your "corrected" code, if the player has exactly 2500 it will still send the message, despite the player having enough money.

Quote:
Originally Posted by NaClchemistryK
Посмотреть сообщение
Just saying, I hate using two orperators at one place (except at cases where we have to use " == ") so people who are just like me can use
pawn Код:
if(GetPlayerMoney(playerid) < 2499)
I like mathematical numbers more than orperators, it's just how I like it.
This is also bullshit. They aren't two operators. I'll take you also don't use +=, -=, etc?
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
This is also bullshit. They aren't two operators. I'll take you also don't use +=, -=, etc
Sorry for the incorrect expression of the english language. And correct, I don't use those orperators.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)