PDA

View Full Version : [Tutorial] Checkpoint Dialogs



SergiuOfficial
28-05-17, 17:53
Checkpoint Dialogs

Hello guys, today I will be showing you how to use checkpoints with dialogs.

First, your going to want to define the include 'a_samp' at the top of your script, this include gets to access functions like SendClientMessage, SendClientMessageToAll, SetWeather, SetWorldTime, SetTimer, SetTimerEx, all those functions that are in 'a_samp' include, next your going to want to define 'ZCMD' under the include 'a_samp', this include is a fast command processor

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


Next, your going to want to add this variable somewhere not in public functions, as I recommend you to add this variable under your color defines:
Code:
new CP[MAX_PLAYERS];
This creates a variable, which we will use later.

Now, we're going to define the dialog for the weapon.
So this defines a dialog, and you can change the name 'DIALOG_WEAPON' to something else, but I prefer you to let it stay and don't change it.(Your choice)
You can put this define maybe under your color defines.
Code:
#define DIALOG_WEAPON 1

Now, we're going to create a command which will show up a dialog with list of weapons, and you'll have to click one item, and enter the checkpoint in order to get the weapon.

I'll place the code here, then I'll explain after.
Code:
CMD:weapons(playerid, params[])
{
ShowPlayerDialog(playerid, DIALOG_WEAPON, DIALOG_STYLE_LIST, "Weapons", "AK47\nM4\nSniper Rifle", "Yes", "No");
return 1;
}
So what this basically means is, it will show the player a dialog, the dialog ID is 'DIALOG_WEAPON' which we defined it recently, and the DIALOG_STYLE_LIST is a type of a dialog type, it's a list type, then when it says 'Weapons' it is the title at the top of the dialog, AK47 and M4 and Sniper Rifle is the weapon names, you change the weapon names if you want, and very important the '\n' that creates a new line.And the Yes is when the player clicks on one of the items, the no is when the player cancels it.You may change the yes to something else like Okay and the no to cancel something like that.

Parameters:
Code:
playerid The ID of the player to show the dialog to.
dialogid An ID to assign this dialog to, so responses can be processed. Max dialogid is 32767. Using negative values will close any open dialog.
style The style of the dialog.
caption[] The title at the top of the dialog. The length of the caption can not exceed more than 64 characters before it starts to cut off.
info[] The text to display in the dialog. Use \n to start a new line and \t to tabulate.
button1[] The text on the left button.
button2[] The text on the right button. Leave it blank to hide it.
You may refer here for more information about the function 'ShowPlayerDialog'.





Now, onto the function 'OnDialogResponse', this is when the player responds to the dialog.
You may refer here for more information about the function 'OnDialogResponse'.


Now, I will put the code here then after - Explain.
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_WEAPON) // This checks if the dialog equals to the dialog define 'DIALOG_WEAPON', You can use a switch aswell, but i just prefer just to see the whole line
{
if(!response) return 0; // If you press the second button (No), the dialog dissapears and nothing happens
if(response) // If there is a response (first button( Yes )) it continues
{
if(listitem == 0) // If you choose the first listitem, this happens
{
CP[playerid] = 1;
SetPlayerCheckpoint(playerid, 2745.6499,-2453.8032,13.8623, 1.0);
SendClientMessage(playerid, -1, "You have chosen the AK-47, follow the checkpoint to get the AK-47.");
return 1;
}
if(listitem == 1) // If you choose the second listitem
{
CP[playerid] = 2;
SetPlayerCheckpoint(playerid, 1579.4326,-1635.8755,13.5604, 1.0); // This creates a checkpoint at the coördinates: "-1051.4005,-655.8729,31.7361"
SendClientMessage(playerid, -1, "You have chosen the M4, follow the checkpoint to get the M4.");
return 1;
}
if(listitem == 2) // If you choose the third listitem
{
CP[playerid] = 3;
SetPlayerCheckpoint(playerid, 1544.9388,-1353.3195,329.4743, 1.0); // This creates a checkpoint at the coördinates: "-2286.7529,2282.9390,5.9015"
SendClientMessage(playerid, -1, "You have chosen the Sniper Rifle, follow the checkpoint to get the Sniper Rifle.");
return 1;
}
}
}
return 1;
}

So this code basically means that it will check if the dialog equals to 'DIALOG_WEAPON'.
Code:
if(dialogid == DIALOG_WEAPON) // This checks if the dialog equals to the dialog define 'DIALOG_WEAPON', You can use a switch aswell, but i just prefer just to see the whole line

Next, these both codes means if they press the second button(No), the dialog dissapears and nothing happens, what makes it dissapears is the code 'return 0;', this returns it false, also the exclamation mark behind the word 'response' means no, if they don't response, it will do something like saying that they have canceled it or using return 0; which returns false.
The second code, with no exclamation mark behind the response means if they do response, it continues.
Code:
if(!response) return 0; // If you press the second button (No), the dialog dissapears and nothing happens
if(response) // If there is a response (first button( Yes )) it continues

This next code means if they clicked the first item, which is 0, which counts as number 1, it will set the CP variable to 1, and it will set a checkpoint for the player at the coordinates of '2745.6499,-2453.8032,13.8623', and the size will be 1.0, which is size 1.Then it will send the player a message with a color white AKA '-1', then saying that 'You have chosen the AK-47, follow the checkpoint to get the AK-47'.

The second one which is the listitem 1, which is counting as 2, it will set the CP variable to 2, then it will set a checkpoint for the player at the coordinates of '1579.4326,-1635.8755,13.5604', and the size of the checkpoint will be 1.0, which is size 1.Then it will send the player a message with a color white AKA '-1', then saying that 'You have chosen the M4, follow the checkpoint to get the M4'.

The third one which is listitem 2, which is counting as 3, it will set the CP variable to 3, then it will set a checkpoint for the player at the coordinates of '1544.9388,-1353.3195,329.4743', and the size of the checkpoint will be 1.0, which is size 1.Then it will send the player a message with a color white AKA '-1', then saying that 'You have chosen the Sniper Rifle, follow the checkpoint to get the Sniper Rifle', then all this will return true.
Code:
if(listitem == 0) // If you choose the first listitem, this happens
{
CP[playerid] = 1;
SetPlayerCheckpoint(playerid, 2745.6499,-2453.8032,13.8623, 1.0);
SendClientMessage(playerid, -1, "You have chosen the AK-47, follow the checkpoint to get the AK-47.");
return 1;
}
if(listitem == 1) // If you choose the second listitem
{
CP[playerid] = 2;
SetPlayerCheckpoint(playerid, 1579.4326,-1635.8755,13.5604, 1.0); // This creates a checkpoint at the coördinates: "-1051.4005,-655.8729,31.7361"
SendClientMessage(playerid, -1, "You have chosen the M4, follow the checkpoint to get the M4.");
return 1;
}
if(listitem == 2) // If you choose the third listitem
{
CP[playerid] = 3;
SetPlayerCheckpoint(playerid, 1544.9388,-1353.3195,329.4743, 1.0); // This creates a checkpoint at the coördinates: "-2286.7529,2282.9390,5.9015"
SendClientMessage(playerid, -1, "You have chosen the Sniper Rifle, follow the checkpoint to get the Sniper Rifle.");
return 1;
}

Now we will move onto the function 'OnPlayerEnterCheckpoint', this function is called when the player enters the checkpoint.
You may refer here for more information about the function 'OnPlayerEnterCheckpoint'

I will place the code here, then after I will explain it.
Code:
public OnPlayerEnterCheckpoint(playerid)
{
if(CP[playerid] == 1) // This checks if our variable equals to 1, if so: it continues
{
DisablePlayerCheckpoint(playerid); // This makes sure that there will be a new checkpoint
CP[playerid] = 4; // Changes the variable, so we can use it later again with OnPlayerEnterCheckpoint
GivePlayerWeapon(playerid, 30, 999999);
SendClientMessage(playerid, -1, "Enjoy your weapon!");
return 1;
}
if(CP[playerid] == 2) // This checks if our variable equals to 2, if so: it continues
{
DisablePlayerCheckpoint(playerid); // This makes sure that there will be a new checkpoint
CP[playerid] = 5; // Changes the variable, so we can use it later again with OnPlayerEnterCheckpoint
GivePlayerWeapon(playerid, 31, 999999);
SendClientMessage(playerid, -1, "Enjoy your weapon!");
}
if(CP[playerid] == 2) // This checks if our variable equals to 2, if so: it continues
{
DisablePlayerCheckpoint(playerid); // This makes sure that there will be a new checkpoint
CP[playerid] = 6; // Changes the variable, so we can use it later again with OnPlayerEnterCheckpoint
GivePlayerWeapon(playerid, 34, 999999);
SendClientMessage(playerid, -1, "Enjoy your weapon!");
}
return 1;
}
So this code basically means if the CheckPoint is equal the checkpoint number 1, it will disable the checkpoint, changes the variable to 4, then it will give the player a AK-47 which is the weapon id 30, and with infinite bullets. But you will still have to do the reload animation.Then it will send the player a message with the color white AKA '-1' saying Enjoy your new weapon!

Next, if the CheckPoint is equal the checkpoint number 2, it will disable the checkpoint, changes the variable to 5, then it will give the player a M4 which is the weapon id 31, and with infinite bullets. But you will still have to do the reload animation.Then it will send the player a message with the color white AKA '-1' saying Enjoy your new weapon!

Next, if the CheckPoint is equal the checkpoint number 3, it will disable the checkpoint, changes the variable to 6, then it will give the player a M4 which is the weapon id 34, and with infinite bullets. But you will still have to do the reload animation.Then it will send the player a message with the color white AKA '-1' saying Enjoy your new weapon!
________________________________________
Full code:
Code:
#include <a_samp>
#include <zcmd>

#define DIALOG_WEAPON 1

new CP[MAX_PLAYERS];

public OnPlayerEnterCheckpoint(playerid)
{
if(CP[playerid] == 1) // This checks if our variable equals to 1, if so: it continues
{
DisablePlayerCheckpoint(playerid); // This makes sure that there will be a new checkpoint
CP[playerid] = 4; // Changes the variable, so we can use it later again with OnPlayerEnterCheckpoint
GivePlayerWeapon(playerid, 30, 999999);
SendClientMessage(playerid, -1, "Enjoy your weapon!");
return 1;
}
if(CP[playerid] == 2) // This checks if our variable equals to 2, if so: it continues
{
DisablePlayerCheckpoint(playerid); // This makes sure that there will be a new checkpoint
CP[playerid] = 5; // Changes the variable, so we can use it later again with OnPlayerEnterCheckpoint
GivePlayerWeapon(playerid, 31, 999999);
SendClientMessage(playerid, -1, "Enjoy your weapon!");
}
if(CP[playerid] == 2) // This checks if our variable equals to 2, if so: it continues
{
DisablePlayerCheckpoint(playerid); // This makes sure that there will be a new checkpoint
CP[playerid] = 6; // Changes the variable, so we can use it later again with OnPlayerEnterCheckpoint
GivePlayerWeapon(playerid, 34, 999999);
SendClientMessage(playerid, -1, "Enjoy your weapon!");
}
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_WEAPON) // This checks if the dialog equals to the dialog define 'DIALOG_WEAPON', You can use a switch aswell, but i just prefer just to see the whole line
{
if(!response) return 0; // If you press the second button (No), the dialog dissapears and nothing happens
if(response) // If there is a response (first button( Yes )) it continues
{
if(listitem == 0) // If you choose the first listitem, this happens
{
CP[playerid] = 1;
SetPlayerCheckpoint(playerid, 2745.6499,-2453.8032,13.8623, 1.0);
SendClientMessage(playerid, -1, "You have chosen the AK-47, follow the checkpoint to get the AK-47.");
return 1;
}
if(listitem == 1) // If you choose the second listitem
{
CP[playerid] = 2;
SetPlayerCheckpoint(playerid, 1579.4326,-1635.8755,13.5604, 1.0); // This creates a checkpoint at the coördinates: "-1051.4005,-655.8729,31.7361"
SendClientMessage(playerid, -1, "You have chosen the M4, follow the checkpoint to get the M4.");
return 1;
}
if(listitem == 2) // If you choose the third listitem
{
CP[playerid] = 3;
SetPlayerCheckpoint(playerid, 1544.9388,-1353.3195,329.4743, 1.0); // This creates a checkpoint at the coördinates: "-2286.7529,2282.9390,5.9015"
SendClientMessage(playerid, -1, "You have chosen the Sniper Rifle, follow the checkpoint to get the Sniper Rifle.");
return 1;
}
}
}
return 1;
}

CMD:weapons(playerid, params[])
{
ShowPlayerDialog(playerid, DIALOG_WEAPON, DIALOG_STYLE_LIST, "Weapons", "AK47\nM4\nSniper Rifle", "Yes", "No");
return 1;
}

Downloads and pastebin:
Solidfiles .pwn
Solidfiles .amx
ZCMD
Pastebin

Special thanks to:
To JustinAn for creating this tutorial.
To Zeex for creating the include ZCMD.