11.11.2013, 11:21
(
Last edited by bensmart469; 01/04/2015 at 10:39 AM.
)
Hello there, and welcome to my tutorial on how to make a simple weapon shop. For this tutorial, you will not need any specific includes, although you can use the Streamer plugin by Incognito. I have explained most things with comments, so it is easy to understand when you look at the code.
First of all, we need to define the variable for the weapon pickup, example:
Now, under OnGameModeInit (or OnFilterScriptInit if you are adding to a filterscript), you will need to create the pickup, example:
We now need to add the code for when the player enters the pickup, using the OnPlayerPickUpPickup callback
Finally, we need to add the code for when the player buys the weapon, using OnDialogResponse
Thank you for reading this tutorial, and criticism is always welcomed.
PS: If the indentation looks messed up, it's due to the way that it was copied onto SA:MP's forum.
First of all, we need to define the variable for the weapon pickup, example:
pawn Code:
new gunpickup; // Variable for the gun pickup
pawn Code:
public OnGameModeInit()
{
gunpickup = CreatePickup(1239,1, -314.4824,824.4612,14.2422, -1); // Information icon, outside Fort Carson ammunation, visible in all virtual worlds
return 1;
}
pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
if(pickupid == gunpickup) // If the player picks up our gun pickup
{
ShowPlayerDialog(playerid,1,DIALOG_STYLE_LIST,"Guns","Desert Eagle ($900)","Choose","Cancel"); // Show them the gun menu so they can buy the weapons
}
return 1;
}
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid) // We use switch since it is quicker than using multiple 'if' statements
{
case 1: // Same as: if(dialogid == 1)
{
if(response) // If the player didn't cancel the dialog
{
switch(listitem) // Switch through the list items, quicker and is easier for adding more guns to the dialog
{
case 0: // List item 0
{
if(GetPlayerMoney(playerid) < 900) return SendClientMessage(playerid,0xFF0000FF,"You cannot afford this!"); // If the player does not have $900, send them a message in red saying they cannot afford it
GivePlayerWeapon(playerid,24,900); // Give the player the weapon
GivePlayerMoney(playerid,-900); // Give the player $-900
}
}
}
}
}
return 1;
}
PS: If the indentation looks messed up, it's due to the way that it was copied onto SA:MP's forum.