01.05.2014, 16:45
(
Последний раз редактировалось NviDa; 02.05.2014 в 16:07.
)
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
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:
#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.
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(){}
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(){}"
Step 4:
Now lets script our weapons command.Add this after adding your player classes.
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.
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.
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):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,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 ,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.");
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.
-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
Thanks for reading! Hope you understood it!
REP + if this helped you out!