[Tutorial] Base of GPS in Dialog
#1

Hello!
Hi Guys! I'm Brazilian!

I came to the American topic, to share a bit of my knowledge for you, and I came also to help some people who have a hard time producing this command, so I made that base for you. Thank you!

I am a beginner in programming pawno, This is my first tutorial, but I came to give you a GPS base in dialog, but I will also be teaching how I made this base.
I accept criticism and suggestions!
Includes Used: <a_samp> || <zcmd>

First Step:
Create a definition for your DIALOG with a numbering.
PHP код:
#define DIALOG_GPS    1
//#define DIALOG_NAME      DIALOG_NUMBER 
Second step:
Let's create a variable to be recognized when the player arrives at the location and the point is removed.
PHP код:
new GPSLocal[MAX_PLAYERS];
//new nome_of_variable[MAX_PLAYERS]; (Refers to the maximum number of players found on the server) 
Third step
Let's call OnPlayerEnterCheckPoint (playerid) and we'll do the checks inside the variable.
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
    if(
GPSLocal[playerid] == 1)
    {
        
GPSLocal[playerid] = 0;
        
DisablePlayerCheckpoint(playerid);
    }
    return 
1;

Explanation of the above actions:
Код:
public OnPlayerEnterCheckpoint(playerid) = Callback when the player is inside a created tag.
{ = Callback key opening
if(GPSLocal[playerid] == 1) = check, we check if the GPSLocal variable is created.
{ = Verification key opening
GPSLocal [playerid] = 0; = We are zeroing out any markup created by some function
DisablePlayerCheckpoint(playerid); = We are disabling all tags (disabling all tags that have been created at the moment)
} = Closing scan key
Return 1; = We returned Callback to 1 or made the true callback return
} = Closing the Callback key
Fourth step:
Let's create the command, in case to show the DIALOG of the locations. I made an example to go to a lottery house.
PHP код:
CMD:gps(playerid)
{
ShowPlayerDialog (playeridDIALOG_GPSDIALOG_STYLE_LIST"GPS""LOTTERY HOUSE""Select""Close");
return 
1;

Note: The only function used was the ShowPlayerDialog, which is to show a Dialog box for the player that typed the command.
Briefly, I'll bring you a tutorial explaining more about the function.
If you want to study: ShowPlayerDialog

Fifth step:
Let's go to the callback that is responsible for answering the dialogs, in this case the public OnDialogResponse.
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_GPS)
        {
            if(
response)
            {
                if(
listitem == 0)
                {
                    
SetPlayerCheckpoint(playerid,1289.8077,-1654.2590,13.5469,8.0);
                    
SendClientMessage(playerid,-1,"[INFO] - Lottery was marked on your map!");
                    
GPSLocal[playerid] = 1;
                }
            }
        }
    return 
1;

Explanation of the above action:
Код:
 public OnDialogResponse (playerid, dialogid, response, listitem, inputtext []) = Is responsible for starting the function.
{= Callback key opening
if (dialogid == DIALOG_GPS) = You are checking if the dialog exists, and the action against it is done.
{= Key Verification Opening
if (response) = Verification of the responsibilities of the columns.
{= Opening of the Liability Key
if (listitem == 0) = Check if the item quoted in the command lines. In pawno, everything starts from number zero (zero), zero is the first line.
{= Opening Items Check.
SetPlayerCheckPoint(playerid, 1289.8077, -1654.2590,13.5469,8.0); = Create a checkpoint on the game map. Playerid is the player that typed the command. These numbers are the coordinates X, Y, Z, Size
SendClientMessage (playerid, -1, "[INFO]: Lottery marked on Map, Go to the point"); = We send a message to the client. -1 is the color you want to appear in the message (white in pawn). Message.
GPSLocal[playerid] = 1; = We give a value for the GPSLocal variable, which was 1 when we clicked on the desired location, after we arrived, the location will be cleared.
} = Closes the verification of items.
} = Closing the responsibility key.
} = Closing the DIALOG setting check switch.
return 1; = We are finalizing or giving the final (or true) return of the function.
} = Closing callback function key.
Finally, the whole function will be as follows:

PHP код:
#include <a_samp>
#include <zcmd>
#define DIALOG_GPS      1
new GPSLocal[MAX_PLAYERS];
CMD:gps(playerid)
{
    
ShowPlayerDialog(playeridDIALOG_GPSDIALOG_STYLE_LIST"GPS""LOTTERY HOUSE""Select""Close");
    return 
1;
}
public 
OnPlayerEnterCheckpoint(playerid)
{
    if(
GPSLocal[playerid] == 1)
    {
        
GPSLocal[playerid] = 0;
        
DisablePlayerCheckpoint(playerid);
    }
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_GPS)
     {
          if(
response)
           {
             if(
listitem == 0)
               {
                 
SetPlayerCheckpoint(playerid,1289.8077,-1654.2590,13.5469,8.0);
                   
SendClientMessage(playerid,-1,"[INFO] - Lottery has been marked on your map!");
                 
GPSLocal[playerid] = 1;
               }
            }
      }
    return 
1;

@Extra:

If you want the command to turn off the gps:
Note:Just add the command

PHP код:
CMD:offgps(playerid)
{
    if(
GPSLocal[playerid] == 1)
    {
        
GPSLocal[playerid] = 0;
        
DisablePlayerCheckpoint(playerid);
        
SendClientMessage(playerid, -1"{00BFFF}[SERVER]{FFFFFF}: GPS Turn off");
     }
     else
     {
         
SendClientMessage(playerid, -1"{FF0000}ERROR: You are not on GPS");
     }
    return 
1;

Have the option to turn off GPS in Dialog:
Note:Necessary to add another line of the ShowPlayerDialog command "/gps"

PHP код:
CMD:gps(playerid)
{
    
ShowPlayerDialog(playeridDIALOG_GPSDIALOG_STYLE_LIST"GPS""TURN OFF GPS\nLOTERICA""Selecionar""Fechar");
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_GPS)
     {
          if(
response)
        {
            if(
listitem == 0)
            {
                if(
GPSLocal[playerid] == 1)
                {
                    
GPSLocal[playerid] = 0;
                    
DisablePlayerCheckpoint(playerid);
                    
SendClientMessage(playerid, -1"{00BFFF}[SERVER]{FFFFFF}: GPS Turn off!");
                }
                else
                {
                    
SendClientMessage(playerid, -1"{FF0000}ERROR: You are not on GPS");
                }
            }
             if(
listitem == 1)
               {
                 
SetPlayerCheckpoint(playerid1289.8077, -1654.259013.54698.0);
                   
SendClientMessage(playerid,-1,"[INFO] - Lottery has been marked on your map!");
                 
GPSLocal[playerid] = 1;
               }
           }
       }
    return 
1;

Thank You

Source: Pastebin
Reply
#2

Nyc explaination ,good for newbies like me ,thnx and +rep for teaching us sharing ur knowledge
Reply
#3

Thank You
Reply
#4

Good Base.
Reply
#5

Good Tutorial
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)