[Tutorial] Making a Simple Teleport Command [ZCMD]
#1

Okay, so this is my first tutorial. I'll show you how to make a simple, yet different, teleport command. Unlike other commands this one allows you to have multiple locations used on one command, without the need for complicated dialogs.

INCLUDES
This command requires the use of a_samp (as all scripts do) and ZCMD

First of all, ensure you have the following included at the top of your script;

pawn Код:
#include <a_samp>
#include <zcmd>

THE COMMAND
As aforementioned, this command is a command that teleports you (on foot or in a vehicle) to co-ordinates defined in the command, which can be edited by you. So, first of all, we'll start with the actual command;

pawn Код:
command(teleport, playerid, params[])
- 'command(teleport' tells the server that you need to type /teleport for the command to work, 'playerid' is the ID of the player typing the command and 'params' are the parameters (locations) that you can teleport to.

---------------------------------------------------------------------------------------------------------------

Now, we'll obviously want this command to be available for administrators, so we add the line;
pawn Код:
command(teleport, playerid, params[])
{
    if(Player[playerid][AdminLevel] >= 1)
This tells the server that you need the AdminLevel of 1 to use the command (other scripts use other ways of defining admin levels, such as [pAdmin] or [aLevel], you'll need to change this according to your script).

---------------------------------------------------------------------------------------------------------------

Now we'll add the line that will display the teleport options (by typing /teleport);

pawn Код:
command(teleport, playerid, params[])
{
    if(Player[playerid][AdminLevel] >= 1)
    {
        if(isnull(params))
        {
            SendClientMessage(playerid, WHITE, "SERVER: /teleport <location>");
            SendClientMessage(playerid, WHITE, "LS | SF"); // these are the parameters.
        }
pawn Код:
if(isnull(params))
This line tells the server to display the 'SendClientMessage' lines if you haven't included any parameters in your command (when you typed it). Parameters (in this command) are the locations at which you will teleport to. In this tutorial, the paramaters are ls and sf. This is a useful way to display all the different options (parameters) that can be used in a command.

---------------------------------------------------------------------------------------------------------------

Now we will add our first location, LS (Los Santos).

pawn Код:
command(teleport, playerid, params[])
{
    if(Player[playerid][AdminLevel] >= 1)
    {
        if(isnull(params))
        {
            SendClientMessage(playerid, WHITE, "SERVER: /teleport <location>");
            SendClientMessage(playerid, WHITE, "LS | SF");
        }
        if(!strcmp(params, "ls", true)) // Los Santos
        {
            if (GetPlayerState(playerid) == 2)
            {
                SetVehiclePos(GetPlayerVehicleID(playerid), 1529.6,-1691.2,13.3);
            }
            else
            {
                SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
            }
            SendClientMessage(playerid, RED, "You have been teleported.");
            SetPlayerInterior(playerid,0);
            SetPlayerVirtualWorld(playerid, 0);
        }
Let's dissect this, to give you a better understanding...

pawn Код:
if(!strcmp(params, "ls", true))
This tells the server that the player has included the "LS" parameter when the player typed the command.

pawn Код:
if (GetPlayerState(playerid) == 2)
{
SetVehiclePos(GetPlayerVehicleID(playerid), 1529.6,-1691.2,13.3);
}
The first line checks if the player is in a vehicle, and if he/she is, it sets the vehicle position along with the player position so both the player and the vehicle are teleported.

pawn Код:
SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
This line is used if the player isn't in a vehicle, and only sets the player's position.

pawn Код:
SendClientMessage(playerid, RED, "You have been teleported.");
SetPlayerInterior(playerid,0);
SetPlayerVirtualWorld(playerid, 0);
The first line sends a message to the player in red, saying "You have been teleported.".
The second line sets the players interior, 0, as this teleports you to a location that is outside.
The third line sets your virtual world to 0 also, as you're not teleporting to inside a building.

---------------------------------------------------------------------------------------------------------------

Now we'll add our second location (San Fierro)

pawn Код:
if(!strcmp(params, "sf", true)) // San Fierro
        {
            if (GetPlayerState(playerid) == 2)
            {
                SetVehiclePos(GetPlayerVehicleID(playerid), -1998.5625, 133.1094, 26.8047);
            }
            else
            {
                SetPlayerPos(playerid, -1998.5625, 133.1094, 26.8047);
            }
            SendClientMessage(playerid, RED, "You have been teleported.");
            SetPlayerInterior(playerid,0);
            SetPlayerVirtualWorld(playerid, 0);
        }
This is quite simply a case of copying and pasting, except you need to edit the co-ordinates or you'll teleport to the same place. Just edit the top line in the quotations for your new parameter, change the co-ordinates and you're done. If you're teleporting to an interior you'll also need to edit the SetPlayerInterior and SetPlayerVirtualWorld values, but information about these functions can be found on the SA-MP Wiki.

---------------------------------------------------------------------------------------------------------------
Finally, we'll add the lines that close up the script
pawn Код:
return true;
    }
    return 1;
}
The 'return true;' goes under the final bracket at the very end of the command. This just closes the script up.

THE WHOLE COMMAND

pawn Код:
command(teleport, playerid, params[])
{
    if(Player[playerid][AdminLevel] >= 1)
    {
        if(isnull(params))
        {
            SendClientMessage(playerid, WHITE, "SERVER: /teleport <location>");
            SendClientMessage(playerid, WHITE, "LS | SF");
        }
        if(!strcmp(params, "ls", true)) // Los Santos
        {
            if (GetPlayerState(playerid) == 2)
            {
                SetVehiclePos(GetPlayerVehicleID(playerid), 1529.6,-1691.2,13.3);
            }
            else
            {
                SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
            }
            SendClientMessage(playerid, RED, "You have been teleported.");
            SetPlayerInterior(playerid,0);
            SetPlayerVirtualWorld(playerid, 0);
        }
        if(!strcmp(params, "sf", true)) // San Fierro
        {
            if (GetPlayerState(playerid) == 2)
            {
                SetVehiclePos(GetPlayerVehicleID(playerid), -1998.5625, 133.1094, 26.8047);
            }
            else
            {
                SetPlayerPos(playerid, -1998.5625, 133.1094, 26.8047);
            }
            SendClientMessage(playerid, RED, "You have been teleported.");
            SetPlayerInterior(playerid,0);
            SetPlayerVirtualWorld(playerid, 0);
        }
        return true;
    }
    return 1;
}
Reply


Messages In This Thread
Making a Simple Teleport Command [ZCMD] - by Luke_James - 27.08.2012, 15:50
Re: Making a Simple Teleport Command [ZCMD] - by Cjgogo - 27.08.2012, 16:31
Re: Making a Simple Teleport Command [ZCMD] - by Luke_James - 27.08.2012, 16:45
Re: Making a Simple Teleport Command [ZCMD] - by Arastair - 19.07.2014, 11:12
Re: Making a Simple Teleport Command [ZCMD] - by elhanan - 23.04.2016, 18:34
Re: Making a Simple Teleport Command [ZCMD] - by GhostHacker - 24.04.2016, 06:18

Forum Jump:


Users browsing this thread: 1 Guest(s)