27.08.2012, 15:50
(
Последний раз редактировалось Luke_James; 27.08.2012 в 16:46.
)
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;
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;
- '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;
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);
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).
Let's dissect this, to give you a better understanding...
This tells the server that the player has included the "LS" parameter when the player typed the command.
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.
This line is used if the player isn't in a vehicle, and only sets the player's position.
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)
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
The 'return true;' goes under the final bracket at the very end of the command. This just closes the script up.
THE WHOLE COMMAND
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[])
---------------------------------------------------------------------------------------------------------------
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)
---------------------------------------------------------------------------------------------------------------
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))
---------------------------------------------------------------------------------------------------------------
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);
}
pawn Код:
if(!strcmp(params, "ls", true))
pawn Код:
if (GetPlayerState(playerid) == 2)
{
SetVehiclePos(GetPlayerVehicleID(playerid), 1529.6,-1691.2,13.3);
}
pawn Код:
SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
pawn Код:
SendClientMessage(playerid, RED, "You have been teleported.");
SetPlayerInterior(playerid,0);
SetPlayerVirtualWorld(playerid, 0);
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);
}
---------------------------------------------------------------------------------------------------------------
Finally, we'll add the lines that close up the script
pawn Код:
return true;
}
return 1;
}
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;
}