[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
#2

You didn't even use sscanf,you used isnull&strcmp,+ that there are thousand of teleport tutorials.Sorry...
Reply
#3

Removed sscanf, for some reason I just added it in without thinking about it. There's actually very few teleport tutorials, and most of them either use a dialogue or only teleport you to one place.
Reply
#4

Are you sure it will work? did you test it?
Reply
#5

i dont know how to make it and it dosent work...
Reply
#6

Thats because you dont know to script
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)