30.11.2012, 10:18
So, did you ever wanted to create a command where every player wants to buy a gun anywhere in a DM/TDM/Freeroam/etc. server? It's very simple, error-less and fun to make one!
STEP 1
Add the normal include
pawn Код:
#include <a_samp>
STEP 2
Add
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
below the includes
STEP 3
Now, we have to add the command ( /weaponlist ) below OnPlayerCommandText so that the script shows what weapon the player can buy
pawn Код:
{
if(!strcmp(cmdtext, "/weaponlist"))
{
ShowPlayerDialog(playerid, 67, DIALOG_STYLE_LIST, "Weapon shop", "Knife - 100$\nChainsaw - 100$\nGrenade - 1500$\nMolotov Cocktail - 2000$\nDesert Eagle - 1150$\nSawnoff Shotgun - 1000$\nMicro SMG - 1000$/Uzi - 500$\nMP5 - 500$\nSniper Rifle - 1000$\nFlamethower - 2000$\nSatchel Charge - 5000$\nFire Extinguisher - 5000$\nNight Vis Goggles - 1050$\nThermal Goggles - 1200$\nParachute - 100$", "Buy", "Cancel");
return 1;
}
return 0;
}
Note - You can also edit this line.
STEP 4
This is a code which responds to the dialog, when you click on the weapon you want to buy. Without this code, the dialog would be a waste of time
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 67)
{
if(!response)
return 1;
switch(listitem)
{
Note - You saw there isn't 3 } to complete the dialog response code, it will come in the end.
STEP 4 - Final step
Now, you add the weapon to be given to the player if player has bought it, and the required money is gone from him
pawn Код:
{
case 0:
{
if(GetPlayerMoney(playerid) < 100)
return SendClientMessage(playerid, 0x0000FFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -100);
GivePlayerWeapon(playerid, 4, 1);
SendClientMessage(playerid, 0x0000FFAA, "You have succesfully buyed your weapon.");
}
case 1:
{
if(GetPlayerMoney(playerid) < 100)
return SendClientMessage(playerid, 0x33FF00AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -100);
GivePlayerWeapon(playerid, 9, 1);
SendClientMessage(playerid, 0x33FF00AA, "You have succesfully buyed your weapon.");
}
case 2:
{
if(GetPlayerMoney(playerid) < 1500)
return SendClientMessage(playerid, 0x00FFFFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -1500);
GivePlayerWeapon(playerid, 16, 100);
SendClientMessage(playerid, 0x00FFFFAA, "You have succesfully buyed your weapon.");
}
case 3:
{
if(GetPlayerMoney(playerid) < 2000)
return SendClientMessage(playerid, 0x6600FFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -2000);
GivePlayerWeapon(playerid, 18, 20);
SendClientMessage(playerid, 0x6600FFAA, "You have succesfully buyed your weapon.");
}
case 4:
{
if(GetPlayerMoney(playerid) < 1150)
return SendClientMessage(playerid, 0x99FF00AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -1150);
GivePlayerWeapon(playerid, 24, 100);
SendClientMessage(playerid, 0x99FF00AA, "You have succesfully buyed your weapon.");
}
case 5:
{
if(GetPlayerMoney(playerid) < 1000)
return SendClientMessage(playerid, 0x999999AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -1000);
GivePlayerWeapon(playerid, 26, 3000);
SendClientMessage(playerid, 0x999999AA, "You have succesfully buyed your weapon.");
}
case 6:
{
if(GetPlayerMoney(playerid) < 1000)
return SendClientMessage(playerid, 0xCC0000AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -1000);
GivePlayerWeapon(playerid, 28, 7000);
SendClientMessage(playerid, 0xCC0000AA, "You have succesfully buyed your weapon.");
}
case 7:
{
if(GetPlayerMoney(playerid) < 500)
return SendClientMessage(playerid, 0xFF00FFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -500);
GivePlayerWeapon(playerid, 29, 1050);
SendClientMessage(playerid, 0xFF00FFAA, "You have succesfully buyed your weapon.");
}
case 8:
{
if(GetPlayerMoney(playerid) < 1000)
return SendClientMessage(playerid, 0xCCFF00AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -1000);
GivePlayerWeapon(playerid, 34, 500);
SendClientMessage(playerid, 0xCCFF00AA, "You have succesfully buyed your weapon.");
}
case 9:
{
if(GetPlayerMoney(playerid) < 2000)
return SendClientMessage(playerid, 0xFFFFFFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -2000);
GivePlayerWeapon(playerid, 37, 9000);
SendClientMessage(playerid, 0xFFFFFFAA, "You have succesfully buyed your weapon.");
}
case 10:
{
if(GetPlayerMoney(playerid) < 5000)
return SendClientMessage(playerid, 0xCC3300AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -5000);
GivePlayerWeapon(playerid, 39, 20);
SendClientMessage(playerid, 0xCC3300AA, "You have succesfully buyed your weapon.");
}
case 11:
{
if(GetPlayerMoney(playerid) < 5000)
return SendClientMessage(playerid, 0x66FF99AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -5000);
GivePlayerWeapon(playerid, 42, 5050);
SendClientMessage(playerid, 0x66FF99AA, "You have succesfully buyed your weapon.");
}
case 12:
{
if(GetPlayerMoney(playerid) < 1050)
return SendClientMessage(playerid, 0xFF9966AA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -1050);
GivePlayerWeapon(playerid, 44, 1);
SendClientMessage(playerid, 0xFF9966AA, "You have succesfully buyed your weapon.");
}
case 13:
{
if(GetPlayerMoney(playerid) < 1200)
return SendClientMessage(playerid, 0x9900FFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -1200);
GivePlayerWeapon(playerid, 45, 1);
SendClientMessage(playerid, 0x9900FFAA, "You have succesfully buyed your weapon.");
}
case 14:
{
if(GetPlayerMoney(playerid) < 100)
return SendClientMessage(playerid, 0x33CCFFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -100);
GivePlayerWeapon(playerid, 46, 1);
SendClientMessage(playerid, 0x33CCFFAA, "You have succesfully buyed your weapon.");
}
}
}
return 1;
}
GivePlayerMoney gives/takes the money from the player away. If take away, it must be -100. If it to give, it must be 100
GivePlayerWeapon is to give a player the money. It will give the weapon ID and the ammunition for the weapon
After all, SendClientMessage gives a message that the player has successfully bought the weapon
Note - As i didn't do the 3 } in Step 3, it will be present here
That's the end of this tutorial!
This is a simple tutorial for beginners, hope you learned something from this!
IMPORTANT NOTES
-- If you want to add more weapons, you just
Add the same thing on the code in Step 3, with
pawn Код:
\n\\Your weapon - \\Weapon price$
pawn Код:
{
if(GetPlayerMoney(playerid) < //The weapon price)
return SendClientMessage(playerid, 0x9900FFAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, //The same in GetPlayerMoney(playerid)'s money, just with a - behind each number, like -1200);
GivePlayerWeapon(playerid, //Weapon ID, //Ammos ( can be edited ));
SendClientMessage(playerid, 0x9900FFAA, "You have succesfully buyed your weapon.");
}
Done! It's as simple as it is!
If you have any troubles, please reply back.