[Tutorial] Creating 1 Or Multiple Weapon Shop
#1

Creating 1 Or Multiple Weapon Shop


Introduction:

Hi Everyone, I will be showing how to make 1 Or Multiple Weapon Shop. The tutorial will cover 4 weapons(Deagle/Sawn-Off/M4/Sniper) to keep the code minimum.
The shop will be dialogs and you can easily make multiple shops by modifying just one line. Lets start.

Step 1:

I am going to use zcmd(Credits to ZeeX) for this tutorial, It is much easier

Lets begin with defining our weapon shop dialog id.
Type the following under the includes:


Code:
#include <a_samp>
#include <zcmd>

#define SHOP_DIALOG 0//Change 0 to suit other dialog id's in your script/s.

Step 2:

Ok, now we have defined our dialog id, we can start developing the dialog structure.
Follow the comments provided:


Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == SHOP_DIALOG)//If the dialog responded to is our Weapon Shop dialog.
	{
	    if(!response) return SendClientMessage(playerid, -1, "You have left the Weapon Shop.");//If they click "Exit" they have left the dialog(Shop).
		switch(listitem)
		{
			case 0://Deagle
			{
			    if(GetPlayerMoney(playerid) >= 500)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 500);//Take the cost.
			        GivePlayerWeapon(playerid, 24, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "Deagle purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
			case 1://Sawn-Off
			{
			    if(GetPlayerMoney(playerid) >= 1000)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 1000);//Take the cost.
			        GivePlayerWeapon(playerid, 26, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "Sawn-Off purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
			case 2://M4
			{
			    if(GetPlayerMoney(playerid) >= 2000)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 2000);//Take the cost.
			        GivePlayerWeapon(playerid, 31, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "M4 purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
			case 3://Sniper
			{
			    if(GetPlayerMoney(playerid) >= 3000)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 3000);//Take the cost.
			        GivePlayerWeapon(playerid, 34, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "Sniper purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
		}
	}
	return 1;
}public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == SHOP_DIALOG)//If the dialog responded to is our Weapon Shop dialog.
	{
	    if(!response) return SendClientMessage(playerid, -1, "You have left the Weapon Shop.");//If they click "Exit" they have left the dialog(Shop).
		switch(listitem)
		{
			case 0://Deagle
			{
			    if(GetPlayerMoney(playerid) >= 500)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 500);//Take the cost.
			        GivePlayerWeapon(playerid, 24, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "Deagle purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
			case 1://Sawn-Off
			{
			    if(GetPlayerMoney(playerid) >= 1000)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 1000);//Take the cost.
			        GivePlayerWeapon(playerid, 26, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "Sawn-Off purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
			case 2://M4
			{
			    if(GetPlayerMoney(playerid) >= 2000)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 2000);//Take the cost.
			        GivePlayerWeapon(playerid, 31, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "M4 purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
			case 3://Sniper
			{
			    if(GetPlayerMoney(playerid) >= 3000)//If they have more or equal to the price.
			    {
			        GivePlayerMoney(playerid, GetPlayerMoney(playerid) - 3000);//Take the cost.
			        GivePlayerWeapon(playerid, 34, 100);//Give them the weapon/ammo.
			        SendClientMessage(playerid, -1, "Sniper purchased.");//And let them know they just purchased a weapon.
			        return 1;//Tell pawno to stop processing now.
			    }
			    else//Else the dont have enough money to cover the purchase.
			    {
			        SendClientMessage(playerid, -1, "You dont have the enough money to purchase this weapon.");//Tell them.
			        return 1;//Tell pawno to stop processing now.
			    }
			}
		}
	}
	return 1;
}


Step 3:

Now we have our Weapon Shop we can make the command to activate the dialog menu, we can place multiple coordinates here for multiple Weapon Shop's.
Follow the comments provided:



Code:
CMD:shop(playerid, params[])//If the player types /shop
{
    if(IsPlayerInRangeOfPoint(playerid, 1.0, 0.0, 0.0, 0.0))//If there within the coordinates set for the Weapon Shop(For multiple shop locations do "0.0, 0.0, 0.0 || 0.0, 0.0, 0.0 || 0.0, 0.0, 0.0" etc.)
    {
    	ShowPlayerDialog(playerid, SHOP_DIALOG, DIALOG_STYLE_LIST, "Weapon Shop", "Deagle: $500\nSawn-Off: $1000\nM4: $2000\nSniper: $3000", "Select", "Exit");//Show them the dialog.
    	return true;//Tell pawno to stop processing now.
    }
    else//Else there NOT within the coordinates set for the Weapon Shop.
    {
        SendClientMessage(playerid, -1, "Your not at a Weapon Shop.");//Tell them.
    }
	return true;
}


And Boom SHAKALAKA Your very own weapon shop Have a nice time !

Reply
#2

Why there are 2 OnDialogResponse callback?
Reply
#3

How do I put them into categories of weapons?
Such as: handheld, assaults, heavy artilleries, melee etc..
Reply
#4

he don't know and get banned because i guess he took that part from another script
Reply
#5

Quote:
Originally Posted by newbienoob
View Post
Why there are 2 OnDialogResponse callback?
There is because he posted it 2 times by accident
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)