SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 25/07/2012, 06:57 PM   #1
JustinAn
Huge Clucker
 
JustinAn's Avatar
 
Join Date: Apr 2012
Location: Why?
Posts: 237
Reputation: 27
Default Checkpoint Dialogs

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

pawn 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:
pawn 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.
pawn 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.
pawn 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.
pawn 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'.
pawn 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.
pawn 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.
pawn 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.
pawn 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:
pawn 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.
__________________

Last edited by JustinAn; 02/09/2014 at 11:44 PM.
JustinAn is offline   Reply With Quote
Old 28/07/2012, 05:55 PM   #2
SomebodyAndMe
Huge Clucker
 
SomebodyAndMe's Avatar
 
Join Date: Feb 2010
Location: 52.511938,6.092434 find it.
Posts: 479
Reputation: 21
Default Re: Checkpoint Dialogs

Not really something you would use daily, but still comes in handy when you need it.

Great work!
SomebodyAndMe is offline   Reply With Quote
Old 07/08/2012, 07:11 PM   #3
JustinAn
Huge Clucker
 
JustinAn's Avatar
 
Join Date: Apr 2012
Location: Why?
Posts: 237
Reputation: 27
Default Re: Checkpoint Dialogs

Quote:
Originally Posted by SomebodyAndMe View Post
Not really something you would use daily, but still comes in handy when you need it.

Great work!
Thanks for the feed back!
__________________
JustinAn is offline   Reply With Quote
Old 13/06/2013, 07:37 AM   #4
xganyx
Gangsta
 
xganyx's Avatar
 
Join Date: May 2013
Posts: 690
Reputation: 7
Default Re: Checkpoint Dialogs

Hey ! When I Try To Complie My FS Is Like This :
Here My FS :
Code:
//Tim Viec Lam [FS] Made By DTD

#include <a_samp>
#include <zcmd>

new CP[MAX_PLAYERS];

#define DIALOG_WEAPON 1

cmd:findjobs(playerid, params[])
{
	ShowPlayerDialog{playerid, DIALOG_WEAPON, DIALOG_STYLE_LIST, "Viec Lam", "Trucker\nPizza\nTaxi", "Yes", "No");
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	if(CP[playerid] == 1)
	{
	    DisablePlayerCheckpoint(playerid);
	    CP[playerid] = 4;
		SendClientMessage(playerid, -1, "Here");
		return 1;
	}
	if(CP[playerid] == 2)
	{
	    DisablePlayerCheckpoint(playerid);
	    CP[playerid] = 5;
	    SendClientMessage(playerid, -1, "Here");
		return 1;
	}
	if(CP[playerid] == 3)
	{
	    DisablePlayerCheckpoint(playerid);
	    CP[playerid] = 6
	    SendClientMessage(playerid, -1, "Here");
	    return 1;
	}
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == DIALOG_WEAPON)
	{
	    if(!respon) return 0;
	    if(respon)
	    {
	        if(listitem == 0)
	        {
				CP[playerid] = 1;
				SetPlayerCheckponint(playerid, 2745.6499,-2453.8032,13.8623, 1.0);
                SendClientMessage(playerid, -1, "You Choose Trucker!");
                return 1;
			}
			if(listitem == 1)
			{
			    CP[playerid] = 2;
			    SetPlayerCheckpoint(playerid, 1579.4326,-1635.8755,13.5604, 1.0);
			    SendClientMessage(playerid, -1, "You Chosse Pizza!");
			    return 1;
			}
			if(listitem == 2)
			{
			    CP[playerid] = 3;
			    SetPlayerCheckpoint(playerid, 1544.9388,-1353.3195,329.4743, 1.0);
			    SendClientMessage(playerid, -1, "You Chosse Taxi!");
	           	return 1;
			}
		}
	}
	return 1;
}
And The Errors :
Code:
C:\Documents and Settings\hung\Desktop\Roleplay Base Script\filterscripts\FindJob.pwn(36) : error 001: expected token: ";", but found "-identifier-"
C:\Documents and Settings\hung\Desktop\Roleplay Base Script\filterscripts\FindJob.pwn(46) : error 017: undefined symbol "respon"
C:\Documents and Settings\hung\Desktop\Roleplay Base Script\filterscripts\FindJob.pwn(47) : error 017: undefined symbol "respon"
C:\Documents and Settings\hung\Desktop\Roleplay Base Script\filterscripts\FindJob.pwn(52) : error 017: undefined symbol "SetPlayerCheckponint"
C:\Documents and Settings\hung\Desktop\Roleplay Base Script\filterscripts\FindJob.pwn(75) : warning 203: symbol is never used: "findjobs"
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
xganyx is offline   Reply With Quote
Old 13/06/2013, 12:26 PM   #5
xganyx
Gangsta
 
xganyx's Avatar
 
Join Date: May 2013
Posts: 690
Reputation: 7
Default Re: Checkpoint Dialogs

help !!!
xganyx is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Named Dialogs - Give your dialogs names! Gamer_Z Includes 22 31/07/2012 11:46 PM
[FilterScript] Simple fighting system with dialogs (will do soon one with wasting cash and another without dialogs) Marsigne Filterscripts 20 24/05/2012 08:33 PM
[Include] Callback Dialogs (Faster processing dialogs) clavador Includes 2 06/07/2011 10:59 AM
[Include] Sasi-Dialogs - A new way to add dialogs! Sasino97 Includes 11 02/05/2011 02:20 PM
Dialogs Conflict with other Dialogs with different... HydraX Help Archive 33 02/01/2010 12:33 AM


All times are GMT. The time now is 01:25 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.