[Tutorial] How to make a Weapon Dialog
#1

Hey all you SAMP Forum users!!!

Today I will be making a tutorial on how to make a Weapon Dialog System!

First, you need to download zCmd to do this, because I will be using it to make the commands.
zCmd Tutorial
zCmd download

Now, I will get into the include and defines code.

First, you want to include a_samp and zcmd
Code:
//Includes
#include <a_samp>
#include <zcmd>
Now, you need to define the colors and dialogs.
Code:
//Color Defines
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_BLUE 0x0000BBAA

//Defines
#define DIALOG_STORE 0
#define DIALOG_PISTOLS 1
#define DIALOG_SUBS 2
#define DIALOG_SHOTGUNS 3
#define DIALOG_ASSAULT 4
#define DIALOG_RIFLES 5
#define DIALOG_MELEE 6
#define DIALOG_HEAVY 7
Because this was in a new folder, this was some of my new Dialog ID's.

Defining the colors will help us later when we actually get to some of the coding.

Now, we need to make a couple of stock functions.
One is for money and one is for SendClientMessage
Code:
//Stock Functions

stock Money(playerid,amount)
{
	if(GetPlayerMoney(playerid)>=amount)return 1;
	return 0;
}

stock SCM(playerid, color, string[])
{
	SendClientMessage(playerid, color, string);
}
Now, I will get into the commands, where you need zCmd.

Code:
CMD:store(playerid, params[])
{
	ShowPlayerDialog(playerid, DIALOG_STORE, DIALOG_STYLE_LIST, "Weapons Shop", "Melee Weapons\nPistols\nSub-Machine Guns\nShotguns\nAssault Rifles\nRifles\nHeavy Weapons\n$500 - Body Armour", "Select", "Cancel");
	return 1;

}
As you can see above, that is the coding for the Dialog with the CMD: Store.

Now, we will make the responses to this dialog command.

Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{

	if(dialogid == DIALOG_STORE)
	{
	if(response){
	switch(listitem){
	case 0:{ShowPlayerDialog(playerid, DIALOG_MELEE, DIALOG_STYLE_LIST, "Melee Weapons Shop", "$10 - Brass Knuckles\n$50 - Golf Club\n$50 - NightStick\n$100 - Knife\n$50 - Baseball Bat\n$50 - Shovel\n$50 - Pool Cue\n$100 - Katana\n$10 - Flowers\n$50 - Cane", "Select", "Back");}
	case 1:{ShowPlayerDialog(playerid, DIALOG_PISTOLS, DIALOG_STYLE_LIST, "Pistols Shop", "$500 - Colt .45\n$750 - Silenced Colt .45\n$1000 - Desert Eagle", "Select", "Back");}
	case 2:{ShowPlayerDialog(playerid, DIALOG_SUBS, DIALOG_STYLE_LIST, "Sub-Machine Gun Shop", "$1000 - UZI\n$1000 - Tec-9\n$1000 - MP5", "Select", "Back");}
	case 3:{ShowPlayerDialog(playerid, DIALOG_SHOTGUNS, DIALOG_STYLE_LIST, "Shotgun Shop", "$500 - Shotgun\n$2000 - Sawn-Off Shotgun\n$2000 - Combat Shotgun", "Select", "Back");}
	case 4:{ShowPlayerDialog(playerid, DIALOG_ASSAULT, DIALOG_STYLE_LIST, "Assault Rifle Shop", "$1000 - AK47\n$1000 - M4", "Select", "Back");}
	case 5:{ShowPlayerDialog(playerid, DIALOG_RIFLES, DIALOG_STYLE_LIST, "Rifle Shop", "$750 - Country Rifle\n$1000 - Sniper Rifle", "Select", "Back");}
	case 6:{ShowPlayerDialog(playerid, DIALOG_HEAVY, DIALOG_STYLE_LIST, "Heavy Weapons Shop", "$20,000 - RPG\n$20,000 - Flamethrower\n$60,000 - Minigun", "Select", "Back");}
	case 7:{if(!Money(playerid, 500))return SCM(playerid, COLOR_GREY, "You can't afford that!");SetPlayerArmour(playerid, 100);GivePlayerMoney(playerid,-500);SCM(playerid, COLOR_YELLOW, "You have purchased a full set of Body Armour for $500");}
	}
	}
	}
The code above is the responses to the original CMD. This is what will show when you pick one of the choices. And the body armor of course.

Now, we will get into the responses to when they pick weapons.

First is the Pistols.
Code:
	if(dialogid == DIALOG_PISTOLS)
	{
	if(response){
	switch(listitem){
	case 0:{if(!Money(playerid, 500))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 22, 250);GivePlayerMoney(playerid,-500);SCM(playerid, COLOR_YELLOW, "You have purchased a Colt .45 with 250 rounds for $500");}
	case 1:{if(!Money(playerid, 750))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 23, 250);GivePlayerMoney(playerid,-750);SCM(playerid, COLOR_YELLOW, "You have purchased a Silenced Colt .45 with 250 rounds for $750");}
	case 2:{if(!Money(playerid, 1000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 24, 250);GivePlayerMoney(playerid,-1000);SCM(playerid, COLOR_YELLOW, "You have purchased a Desert Eagle with 250 rounds for $1000");}
	}
	}else return ShowPlayerDialog(playerid, DIALOG_STORE, DIALOG_STYLE_LIST, "Weapons Shop", "Melee Weapons\nPistols\nSub-Machine Guns\nShotguns\nAssault Rifles\nRifles\nHeavy Weapons\n$500 - Body Armour", "Select", "Cancel");
	}
As you can see, we used the Money stock as well as the SCM stock. The else return is for to if they pick back.

Next is the Sub-Machine Gun responses.
Code:
if(dialogid == DIALOG_SUBS)
	{
	if(response){
	switch(listitem){
	case 0:{if(!Money(playerid, 1000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 28, 250);GivePlayerMoney(playerid,-1000);SCM(playerid, COLOR_YELLOW, "You have purchased a UZI with 250 rounds for $1000");}
	case 1:{if(!Money(playerid, 1000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 32, 250);GivePlayerMoney(playerid,-1000);SCM(playerid, COLOR_YELLOW, "You have purchased a Tec-9 with 250 rounds for $1000");}
	case 2:{if(!Money(playerid, 1000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 29, 250);GivePlayerMoney(playerid,-1000);SCM(playerid, COLOR_YELLOW, "You have purchased a MP5 with 250 rounds for $1000");}
	}
	}else return ShowPlayerDialog(playerid, DIALOG_STORE, DIALOG_STYLE_LIST, "Weapons Shop", "Melee Weapons\nPistols\nSub-Machine Guns\nShotguns\nAssault Rifles\nRifles\nHeavy Weapons\n$500 - Body Armour", "Select", "Cancel");
	}
Above is the coding for the Sub-Machine Gun shop.

Next on the list is the Shotgun shop.
Code:
if(dialogid == DIALOG_SHOTGUNS)
	{
	if(response){
	switch(listitem){
	case 0:{if(!Money(playerid, 500))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 25, 250);GivePlayerMoney(playerid,-500);SCM(playerid, COLOR_YELLOW, "You have purchased a Shotgun with 250 rounds for $500");}
	case 1:{if(!Money(playerid, 2000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 26, 250);GivePlayerMoney(playerid,-2000);SCM(playerid, COLOR_YELLOW, "You have purchased a Sawn-Off Shotgun with 200 rounds for $2000");}
	case 2:{if(!Money(playerid, 2000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 27, 250);GivePlayerMoney(playerid,-2000);SCM(playerid, COLOR_YELLOW, "You have purchased a Combat Shotgun with 250 rounds for $2000");}
	}
	}else return ShowPlayerDialog(playerid, DIALOG_STORE, DIALOG_STYLE_LIST, "Weapons Shop", "Melee Weapons\nPistols\nSub-Machine Guns\nShotguns\nAssault Rifles\nRifles\nHeavy Weapons\n$500 - Body Armour", "Select", "Cancel");
	}
Next is Assault Rifles
Code:
	if(dialogid == DIALOG_ASSAULT)
	{
	if(response){
	switch(listitem){
	case 0:{if(!Money(playerid, 1000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 30, 250);GivePlayerMoney(playerid,-1000);SCM(playerid, COLOR_YELLOW, "You have purchased a AK47 with 250 rounds for $1000");}
	case 1:{if(!Money(playerid, 1000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 31, 250);GivePlayerMoney(playerid,-1000);SCM(playerid, COLOR_YELLOW, "You have purchased a M4 with 250 rounds for $1000");}
	}
	}else return ShowPlayerDialog(playerid, DIALOG_STORE, DIALOG_STYLE_LIST, "Weapons Shop", "Melee Weapons\nPistols\nSub-Machine Guns\nShotguns\nAssault Rifles\nRifles\nHeavy Weapons\n$500 - Body Armour", "Select", "Cancel");
	}
Next is the regular Rifle shop.
Code:
if(dialogid == DIALOG_RIFLES)
	{
	if(response){
	switch(listitem){
	case 0:{if(!Money(playerid, 750))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 33, 250);GivePlayerMoney(playerid,-750);SCM(playerid, COLOR_YELLOW, "You have purchased a Country Rifle with 250 rounds for $750");}
	case 1:{if(!Money(playerid, 1000))return SCM(playerid, COLOR_GREY, "You can't afford that!");GivePlayerWeapon(playerid, 34, 250);GivePlayerMoney(playerid,-1000);SCM(playerid, COLOR_YELLOW, "You have purchased a Sniper Rifle with 250 rounds for $1000");}
	}
	}else return ShowPlayerDialog(playerid, DIALOG_STORE, DIALOG_STYLE_LIST, "Weapons Shop", "Melee Weapons\nPistols\nSub-Machine Guns\nShotguns\nAssault Rifles\nRifles\nHeavy Weapons\n$500 - Body Armour", "Select", "Cancel");
	}
If you would like to download this, you can check out this thread.
Dialog Download Thread
Reply
#2

Undefined: "SCM"
Reply
#3

Quote:
Originally Posted by DanDRT
View Post
Undefined: "SCM"
Then you didnt do the stock correctly.
Reply
#4

Why use a SCM stock when you can just do this?:

pawn Code:
#define SCM SendClientMessage
Good explanation to the tutorial though.
Reply
#5

Quote:
Originally Posted by DanishHaq
View Post
Why use a SCM stock when you can just do this?:

pawn Code:
#define SCM SendClientMessage
Good explanation to the tutorial though.
or use shorten.inc (than simply shorten the work)
Reply
#6

That's nice but will be more efficiently to use arrays.
Reply
#7

Good, this will help newbies alot.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)