[Tutorial] How to make an advanced briefcase system!
#1

Hi guys, I'm back with a new tutorial, and I'm pretty sure this one doesn't exist anywhere, so this will be useful to you!
We will create an advanced briefcase which you can buy health, armour, and weapons from.
Let's get started!
First, let's add this on top of our script:
pawn Код:
new mybriefcase;
Just to be clear from the beginning, we will create a pickup, and we will use dialogs with this.
Now OnGameModeInIt, we must create the pickup, let's do something like this:
pawn Код:
mybriefcase = CreatePickup(1210, 1, X, Y, Z, -1);
Alright, let me explain this, according to the wiki, this is what it shows:
Код:
CreatePickup(model, type, Float:X, Float:Y, Float:Z, Virtualworld)
So we just created a pickup ID 1210 which is a briefcase(ID 1210, you can change it), type 1 which is the pickup spawn type, the coordinates X,Y,Z(Don't forget to change them, and the virtual world -1(Appears in all worlds!)

Alright, we're good!
Now let's move to our OnPlayerPickUpPickup, we will do the following:
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
if(pickupid == mybriefcase)
    {
    ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
    }
    return 1;
}
So, we checked if they picked up the pickup mybriefcase it will show them a dialog, which has Health as listitem 0, armour as 1, and weapons as 2.
Now this isn't enough, we need to continue our code so this dialog actually makes sense, we need to go to OnPlayerDialogResponse!

Moving on to our OnPlayerDialogResponse!
We will put the following: ((Gonna add comments))
pawn Код:
if(dialogid == 777) // We checked if this is dialog 777 which was opened when we took the pickup(briefcase)
{
            if(response) // if they respond to the dialog
            {
            if(listitem ==0) // first list item which is the health
            {
            if (GetPlayerMoney(playerid) < 5000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");// as u can see, if they don't have enough to buy it, we sended them a message also reshowed the dialog
            GivePlayerMoney(playerid, -5000); // now if he has more than 5k, it will remove 5k to buy the health
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel"); //showing them the dialog again after they buy
            SetPlayerHealth(playerid, 100.0);//since they bought health, we're setting theirs to 100.
            SendClientMessage(playerid, COLOR_WHITE, "You bought Health for $5000!"); //a client message informing them they made the purchase
            }
            if(listitem ==1) // same goes for the armour
            {
            if(GetPlayerMoney(playerid) < 5000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel"); // same as above
            GivePlayerMoney(playerid, -5000); // else it buys it for 5k
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel"); // showing dialog again
            SetPlayerArmour(playerid, 100.0); // armour to 100 since they bought
            SendClientMessage(playerid, COLOR_WHITE, "You bought Armour for $5000!"); // message informing them about purchase
            }
            if(listitem ==2) //Now here it changes, we have Weapons as listitem == 2
            {
            ShowPlayerDialog(playerid, 888, DIALOG_STYLE_LIST, "Weapons", "M4 - 6000$\nAK47 - 6000$\nMP5 - 5000$\nUZI - 10000$\nCombat Shotgun - 10000$\nShotgun - 5000$\nDesert Eagle - 7000$\nSilent Pistol - 3000$\nSniper-8000$\nTec 9 - 3000$\nSawn-Off Shotgun - 8000$\nRPG - 10000$", "Buy", "Exit");
            }// as u can see, if they chose the Weapons from the briefcase, we will show them this dialog with all these weapons, which will need a new dialogresponse which we will make now.
            }
}
So as you can see above, for the health and armour it directly buys if they have the price, but for the weapons, we're opening a new dialog, which will need a dialog response of course.
We got 12 items on the list, I will explain some of them on what we did, then you will know the rest.
I will add comments to the code to make it easier for you.
pawn Код:
if(dialogid ==888) // if the dialog id is 888(as defined above)
            {
            if(response)// if they respond to the dialog
            {
            if(listitem==0) // first list item, which is the M4
            {
            if(GetPlayerMoney(playerid) < 6000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -6000); // ^^ exactly like above, a message telling them they dont have enough
            GivePlayerWeapon(playerid, 31, 300); // if they do, it will give -6k and buy weapon 31(M4) with 300 ammo.
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel"); // we're showing them the same menu again of the briefcase
            SendClientMessage(playerid,COLOR_WHITE, "You bought M4 with 300 Ammo."); // client message to inform them on the purchase
            }
            if(listitem==1) // Now the AK, second list item
            {
            if(GetPlayerMoney(playerid) < 6000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel"); // same thing, telling them they dont have enough and showing dialog again
            GivePlayerMoney(playerid, -6000); // if they have enough, it will give -6k
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel"); // and show dialog again
            GivePlayerWeapon(playerid, 30, 300); // it will give weapon ID 30(AK) with 300 ammo
            SendClientMessage(playerid, COLOR_WHITE, "You bought AK 47 with 300 Ammo.");//client message informing him that he bought..
            }
            if(listitem==2)
            {
            if(GetPlayerMoney(playerid) < 5000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -5000);
            GivePlayerWeapon(playerid, 29, 300);
            SendClientMessage(playerid, COLOR_WHITE, "You bought MP5 with 300 Ammo.");
            }
            if(listitem==3)
            {
            if(GetPlayerMoney(playerid) < 10000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -10000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 28, 500);
            SendClientMessage(playerid, COLOR_WHITE, "You bought UZI with 300 Ammo.");
            }
            if(listitem==4)
            {
            if(GetPlayerMoney(playerid) < 10000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -10000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 27, 300);
            SendClientMessage(playerid, COLOR_WHITE, "You bought SPAZ12 with 300 Ammo.");
            }
            if(listitem==5)
            {
            if(GetPlayerMoney(playerid) < 5000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -5000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 25, 300);
            SendClientMessage(playerid, COLOR_WHITE, "You bought Shotgun with 300 Ammo.");
            }
            if(listitem==6)
            {
            if(GetPlayerMoney(playerid) < 7000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -7000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 24, 100);
            SendClientMessage(playerid, COLOR_WHITE, "You bought Desert Eagle with 100 Ammo.");
            }
            if(listitem==7)
            {
            if(GetPlayerMoney(playerid) < 3000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -3000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 23, 300);
            SendClientMessage(playerid, COLOR_WHITE, "You bought Silencer with 300 Ammo.");
            }
            if(listitem==8)
            {
            if(GetPlayerMoney(playerid) < 8000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -8000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 34,100);
            SendClientMessage(playerid, COLOR_WHITE, "You bought Sniper with 100 Ammo.");
            }
            if(listitem==9)
            {
            if(GetPlayerMoney(playerid) < 3000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -3000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 32, 300);
            SendClientMessage(playerid, COLOR_WHITE, "You bought Tec 9 with 300 Ammo.");
            }
            if(listitem==10)
            {
            if(GetPlayerMoney(playerid) < 8000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -8000);
            GivePlayerWeapon(playerid, 26, 100);
            SendClientMessage(playerid, COLOR_WHITE, "You bought Sawn off Shotgun with 100 Ammo.");
            }
            if(listitem==11)
            {
            if(GetPlayerMoney(playerid) < 10000) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You don't have enough cash.") && ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerMoney(playerid, -10000);
            ShowPlayerDialog(playerid, 777, DIALOG_STYLE_LIST, "Briefcase", "Health - 5000$\nArmour - 5000$\n\nWeapons", "Select", "Cancel");
            GivePlayerWeapon(playerid, 35, 1);
            SendClientMessage(playerid, COLOR_WHITE, "You bought RPG with 1 Ammo.");
            }
            }
}
The same goes for all of them, and this is the end of the tutorial.
As you can see, the script above is for TDM mostly, so if you're creating some other GM and want to use it, you can, of course, change it/modify it to your needs!
I hope I helped guys, and good luck scripting!
Reply
#2

Nice tut really helpful +REP
Reply
#3

Nice Tutorial bro, keep up the good work.
Reply
#4

Thank you Nirzor
Reply
#5

Nice tutorial Bro Jimmy, Please add me on skype pirs.nivans

thanks
Reply
#6

Please explain why this is "advanced". You have a static pickup and a standard - poorly indented - dialog response. You might also want to use a switch for dialogids and listitems alike.

This tutorial isn't all that bad, but there is certainly room for improvement.
Reply
#7

Thank you Vince for your comment.
Well you see, the pickup tutorials that were made before me just give you one simple example on stuff.
But here, I made a decent explanation with many examples, many scripters can use this on their gamemodes to improve their script.
If you want anything to be modified in the tutorial, feel free to tell me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)