BREAKING NEWS

Welcome to File Townz | A TOWN Where you find all Files !

Search

Monday, 12 September 2016

How to create GPS system


How to create GPS system

Hello guys,

Today i'm going to show you how to create a simple GPS system.

So, let get started ! ^^

First of all, let define a dialog which we can select our emplacements :

PHP Code:
Code:
#define DIALOG_GPS 1

Done !

Now let create a command that will allows us to show that gps.

Under OnPlayerCommandText, do this :

PHP Code:
Code:
if(!strcmp(cmdtext, "/gps", true))
    {
        if(!IsPlayerInAnyVehicle(playerid)) // The player cannot use this command if he's not in a vehicle.
    {
        SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command right now.");
        return 1;
       }
        if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) // Check if the player's a driver.
       {
        SendClientMessage(playerid,COLOR_ERROR,"You have to be as a drive to use this command.");
        return 1;
    }
       ShowPlayerDialog(playerid, DIALOG_GPS, DIALOG_STYLE_LIST,"{A52A2A}YOUR GPS:","SFPD","Select","Close"); // Let show our DIALOG that we have defined (I have made an emplacement "SFPD"
    }
    return 0;
}

It's done for the command ! Now we have to define the response of our dialog,

So under OnDialogResponse we add :

PHP Code:
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_GPS) //
        {
         if (response == 1) Check if the player clicked "Select" or pressed "Enter"
         {
           if(listitem == 0) //Our first item on the dialog which is "SFPD"
            {
               SetPlayerRaceCheckpoint(playerid, 2,-1612.6688,722.8657,13.261, 0.0,0.0,0.0, 3.0);// Let set a RaceCheckpoint to be clear on the minimap !
               GameTextForPlayer(playerid,"~r~Go to the~b~Checkpoint.",3000,5); //Set a GameText For player !
            }
            return 1;
          }
         return 1;
       }
    return 0;
}

For the SetPlayerRaceCheckpoint, you can check how we use it over here : https://wiki.sa-mp.com/wiki/SetPlayerRaceCheckpoint

So now, we have done !

We've created a big checkpoint for the player, but what should we do as soon as he gets to it ?

Let do it !

Under OnPlayerEnterRaceCheckpoint we do :

PHP Code:
Code:
public OnPlayerEnterRaceCheckpoint(playerid)
{
    GameTextForPlayer(playerid,"~b~You have arrived to your ~w~destination",3000,5); //we set a Game Text For Player
    DisablePlayerRaceCheckpoint(playerid); //We disable our PlayerRaceCheckpoint
    return 1;
}

DONE !

[-]
Share/Bookmark (Show All)
Face-bookTwitterMySpace


Share this:

Post a Comment

 
Copyright © 2014 Filetownz. Designed by OddThemes | Distributed By Gooyaabi Templates