I was browsing through the scripting help section reading some threads where people were struggling with creating teleports and whatnot.Information
Well, this should make it alot easier for you!
This include comes with 7 functions, 3 macros and 1 callback.Example script
NOTE: make sure to #define FILTERSCRIPT BEFORE including this script when you're creating a filterscript, or the auto_commands won't work properly, like this:
FunctionsPHP код:#define FILTERSCRIPT
#include <teleports>
MacrosPHP код:CreateTeleport( name[ ], Float:x, Float:y, Float:z, Float:angle, interiorid, worldid, cmdname[ ] = "\0" ); // returns the ID of the created teleport.
TeleportPlayer( playerid, telid, bool:allowvehicle = false, bool:loadenv = true ); // third parameter: allow a player to teleport with the vehicle he is currently using; fourth parameter: freeze the player for 2 seconds to load the environment
GetTeleportName( teleportid ); // get the teleport name
GetTeleportInterior( teleportid ); // get the interior of the teleport
GetTeleportWorld( teleportid ); // get the virtual world of the teleport
GetTeleportAngle( teleportid ); // get the facing angle of a teleport, not sure if it's that useful but wanted to add it anyway :p
ReturnTeleportCommands( ); // returns a string with all the teleport commands(the last parameter in CreateTeleport), you still have to make the command yourself though by using ZCMD or any command processor.
Callback(s)PHP код:#define ENVLOADING_MSG ("Loading environment...") // the gametext that's sent when the environment is loading
#define ENVLOADED_MSG ("Environment loaded!") // the gametext that's sent when the environment is loaded
#define USE_AUTO_COMMANDS true // set this to false if you don't want it to make a command automatically
PHP код:forward OnPlayerTeleport( playerid, teleportid ); // called whenever a player is teleported to one of the created teleports
For those who don't quite understand how this works, here's an example script using ZCMD!Download
PHP код:#include <a_samp>
// MAKE SURE TO DEFINE THIS WHEN USING THIS INCLUDE IN A FILTERSCRIPT!
#define FILTERSCRIPT
// define S_MAX_TELEPORTS BEFORE including the script to assign your own value to it.
// sets the max amount of teleports that can be created to 100.
#define S_MAX_TELEPORTS (100)
// define S_MAX_TEL_NAME BEFORE including the script to assign your own value to it.
// sets the max amount of characters a teleport name can have to 32.
#define S_MAX_TEL_NAME (32)
#include <zcmd>
#include <teleports>
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print("Smileys' Teleport example");
print("--------------------------------------\n");
// | leave the last parameter empty if you don't want it to create a command for you.
CreateTeleport( "Crack Den", 319.8009,1121.6636,1083.8828,274.9118, 5, 0 ); // creating the new teleport, the crack den interior in this case
CreateTeleport( "SF Hospital", -2655.7981, 638.7148, 14.4531, 179.9846, 0, 0, "/sfhosp" ); // hospital in SF teleport
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerTeleport( playerid, teleportid ) // this function is called whenever a player has teleported to one of the created teleports.
{
new str[ 128 ];
format( str, sizeof( str ), "[TELEPORT]{FFFFFF} You've been teleported to {FF0000}%s!", GetTeleportName( teleportid ) ); // sending a simple message to the player, including the teleport name.
SendClientMessage( playerid, COLOR_ORANGE, str );
return 1; // returning
}
CMD:teleports( playerid, params[ ] )
{
new str[ 128 + 20 ];
format( str, sizeof( str ), "Teleports:{FFFFFF} %s", ReturnTeleportCommands( ) );
SendClientMessage( playerid, COLOR_ORANGE, str );
return 1;
}
Creditsor GithubPHP код:#if !defined S_MAX_TELEPORTS
#define S_MAX_TELEPORTS (50)
#endif
#if !defined S_MAX_TEL_NAME
#define S_MAX_TEL_NAME (24)
#endif
#if !defined S_MAX_CMD_NAME
#define S_MAX_CMD_NAME (32)
#endif
#if !defined ENVLOADED_MSG
#define ENVLOADED_MSG ("Environment loaded!")
#endif
#if !defined ENVLOADING_MSG
#define ENVLOADING_MSG ("Loading environment...")
#if !defined USE_AUTO_COMMANDS
#define USE_AUTO_COMMANDS true
#endif
#if !defined COLOR_ORANGE
#define COLOR_ORANGE (0xFF8800FF)
#endif
#if !defined strcpy
#define strcpy(%0,%1) strcat((%0[0] = EOS,%0), %1)
#endif
enum S_TEL_DATA
{
NAME[ S_MAX_TEL_NAME ],
Float: X_POS,
Float: Y_POS,
Float: Z_POS,
Float: ANGLE,
INTERIOR,
VWORLD,
bool: CMD_ENABLED,
CMD_NAME[ S_MAX_CMD_NAME ]
};
new
s_Teleports[ S_MAX_TELEPORTS ][ S_TEL_DATA ];
static
s_count = 0;
#define GetTeleportName(%0) s_Teleports[%0][NAME]
#define GetTeleportInterior(%0) s_Teleports[%0][INTERIOR]
#define GetTeleportWorld(%0) s_Teleports[%0][VWORLD]
#define GetTeleportAngle(%0) s_Teleports[%0][ANGLE]
forward OnPlayerTeleport( playerid, teleportid );
stock CreateTeleport( name[ ], Float:x, Float:y, Float:z, Float:angle, interiorid, worldid, cmdname[ ] = "\0" )
{
if( s_count > S_MAX_TELEPORTS )
return printf( "[EXPLOIT] Teleport limit in teleports.inc has exceeded. please increase S_MAX_TELEPORTS or contact the developer!" );
strcpy( s_Teleports[ s_count ][ NAME ], name, S_MAX_TEL_NAME );
strcpy( s_Teleports[ s_count ][ CMD_NAME ], cmdname, S_MAX_CMD_NAME );
s_Teleports[ s_count ][ CMD_ENABLED ] = ( !strcmp( cmdname, "0", true ) ? false : true );
printf( "%b", s_Teleports[ s_count ][ CMD_ENABLED ] );
s_Teleports[ s_count ][ X_POS ] = x;
s_Teleports[ s_count ][ Y_POS ] = y;
s_Teleports[ s_count ][ Z_POS ] = z;
s_Teleports[ s_count ][ ANGLE ] = angle;
s_Teleports[ s_count ][ INTERIOR ] = interiorid;
s_Teleports[ s_count ][ VWORLD ] = worldid;
s_count++;
return ( s_count - 1 );
}
stock TeleportPlayer( playerid, telid, bool:allowvehicle = false, bool:loadenv = true )
{
SetPlayerInterior( playerid, s_Teleports[ telid ][ INTERIOR ] );
SetPlayerVirtualWorld( playerid, s_Teleports[ telid ][ VWORLD ] );
if( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER && allowvehicle )
{
new vehicleid = GetPlayerVehicleID( playerid );
SetVehiclePos( vehicleid, s_Teleports[ telid ][ X_POS ], s_Teleports[ telid ][ Y_POS ], s_Teleports[ telid ][ Z_POS ] );
SetVehicleZAngle( vehicleid, s_Teleports[ telid ][ ANGLE ] );
LinkVehicleToInterior( vehicleid, s_Teleports[ telid ][ INTERIOR ] );
SetVehicleVirtualWorld( vehicleid, s_Teleports[ telid ][ VWORLD ] );
}
else
{
SetPlayerPos( playerid, s_Teleports[ telid ][ X_POS ], s_Teleports[ telid ][ Y_POS ], s_Teleports[ telid ][ Z_POS ] );
SetPlayerFacingAngle( playerid, s_Teleports[ telid ][ ANGLE ] );
}
if( loadenv )
{
TogglePlayerControllable( playerid, false );
SetTimerEx( "s_Unfreeze", 2000, false, "i", playerid );
GameTextForPlayer( playerid, ENVLOADING_MSG, 2000, 3 );
}
CallLocalFunction( "OnPlayerTeleport", "ii", playerid, telid );
return 1;
}
forward s_Unfreeze( playerid );
public s_Unfreeze( playerid )
{
GameTextForPlayer( playerid, ENVLOADED_MSG, 1000, 3 );
TogglePlayerControllable( playerid, true );
return 1;
}
stock ReturnTeleportCommands( )
{
new result[ 128 ];
for( new i = 0; i < s_count; i++ )
{
strcat( result, s_Teleports[ i ][ CMD_NAME ] );
strcat( result, " " );
}
return result;
}
#if USE_AUTO_COMMANDS == true
// Thanks, Lordzy!
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if( !success )
{
for( new i = 0; i < s_count; i++)
{
if( !s_Teleports[ i ][ CMD_ENABLED ] )
continue;
if(!strcmp( cmdtext, s_Teleports[ i ][ CMD_NAME ], true, strlen( s_Teleports[ i ][ CMD_NAME ] ) ) )
{
TeleportPlayer( playerid, i );
return 1;
}
}
return 0;
}
return 1;
}
#endif
SA-MP Team for making all of this possiblePlease suggest any improvements if any can be made!
Lordzy for telling me how to make those commands, Thanks!
Konstantinos for strcpy
A ton of help from fellow scripters for helping me understand the pawn language back in the day

SetPlayerPos(playerid, X, Y, Z);
SetPlayerFacingAngle(playerid, A);
|
Or, instead of an include
pawn Код:
I find this completely useless and just a rename of the SetPlayer functions and just wasting memory |


new
s_Teleports[ S_MAX_TELEPORTS ][ S_TEL_DATA ],
s_count = 0
;
|
pawn Код:
|

stock GetTeleportName( telid )
{
return s_Teleports[ telid ][ NAME ];
}
PutPlayerInVehicle( playerid, vehicleid, 0 );
OnPlayerTeleport( playerid, teleportid );
IsValidTeleport( telid )
s_Teleports[ s_count ][ NAME ]
|
This is pretty useless until and unless you add some bonus into it. I mean it would have been better if you were able to create teleport in one line with pickups and 3DTextlabels on the teleport position.(just an idea)
|
|
And you don't need this while teleporting the player with vehicle.
pawn Код:
|
|
And lol, why would you ever create a callback if you have to handle teleports manually( from script)!
pawn Код:
|
|
You don't require that if there is no deleting of a teleport;
pawn Код:
|
|
No use of this anywhere in you script, except storing tele name!
pawn Код:
|
public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
if(!success) { //In case if it's not present in the script, only then we've to check.
for(new i = 0; i< MAX_TELEPORTS; i++) { //Loop through teleport data
if(!strcmp(cmdtext, TeleportData[i][CMD_NAME], true, strlen(TeleportData[i][CMD_NAME]]) {
//Teleport
}
}
}
return 1;
}
|
I had been developing an include similar to this but discontinued due to lack of interest. Seeing this, I remember few features that I had planned earlier. You've included a command argument but I don't see a good use of it. I suggest you to use the "CMD_NAME" array along with "OnPlayerCommandPerformed" (since zcmd and y_cmd are used frequently) so that the ones using this include don't require to create commands for teleport. It could be done completely in single line.
I had also planned to provide complete vehicle support and pedestrian support while teleporting, which also ensures that they teleport safe in case of streamer objects. Teleportation over an area could also improve this include where players could teleport to a random solid point in an area. These were few of them I planned earlier but I strongly suggest you to consider creating automatic commands. Here's an example of it: pawn Код:
|
|
I had been developing an include similar to this but discontinued due to lack of interest. Seeing this, I remember few features that I had planned earlier. You've included a command argument but I don't see a good use of it. I suggest you to use the "CMD_NAME" array along with "OnPlayerCommandPerformed" (since zcmd and y_cmd are used frequently) so that the ones using this include don't require to create commands for teleport. It could be done completely in single line.
I had also planned to provide complete vehicle support and pedestrian support while teleporting, which also ensures that they teleport safe in case of streamer objects. Teleportation over an area could also improve this include where players could teleport to a random solid point in an area. These were few of them I planned earlier but I strongly suggest you to consider creating automatic commands. Here's an example of it: pawn Код:
|
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
printf( "called with params: %i, %s, %i", playerid, cmdtext, success );
if( !success )
{
printf( "not success" );
for( new i = 0; i < S_MAX_TELEPORTS; i++)
{
printf( "%i", i );
if(!strcmp( cmdtext, s_Teleports[ i ][ CMD_NAME ], true, strlen( s_Teleports[ i ][ CMD_NAME ] ) ) )
{
printf( "found: %i" );
TeleportPlayer( playerid, i );
break;
}
}
}
return 1;
}