Public feed
#380348
if((strcmp(cmd, "/tp", true) == 0) || (strcmp(cmd, "/teleport", true) == 0))
{
new tmp[256];
new destinationid;
tmp = strtok(cmdtext, idx);
// Check whether "tmp" is an empty string
if(!strlen(tmp))
{
SendClientMessage(playerid,COLOUR_RED,"Usage: /tp playerid or /teleport playerid");
}
// Not empty so check the contents
else
{
// Check is the player is connected
if(!IsPlayerConnected(destinationid))
{
// Not connected
SendClientMessage(playerid,COLOUR_RED,"Invalid player ID.");
return 1;
}
else
{
destinationid = strval(tmp);
new destination_player[MAX_PLAYER_NAME];
new teleporting_player[MAX_PLAYER_NAME];
new Float:x, Float:y, Float:z;
new string[256];
// Get the name of the player you are teleporting to
GetPlayerName(destinationid, destination_player, sizeof(destination_player));
// Get the name of player that is teleporting
GetPlayerName(playerid, teleporting_player, sizeof(teleporting_player));
// Get position of the player you are teleporting to
GetPlayerPos(destinationid, Float:x, Float:y, Float:z);
// Set your new position to the destination players coordinates
SetPlayerPos(playerid, Float:x, Float:y, Float:z);
// Display messages players
format(string, sizeof(string), "%s has been teleported to you.", teleporting_player);
SendClientMessage(destinationid, COLOUR_YELLOW, string);
format(string, sizeof(string), "You have been teleported to %s.", destination_player);
SendClientMessage(playerid, COLOUR_YELLOW, string);
}
}
return 1;
}