[Include] Teleports.inc - Easily create teleports with 1 line!
#1

Introduction
I was browsing through the scripting help section reading some threads where people were struggling with creating teleports and whatnot.

Well, this should make it alot easier for you!
Information
This include comes with 7 functions, 3 macros and 1 callback.
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:
PHP код:
#define FILTERSCRIPT
#include <teleports> 
Functions
PHP код:
CreateTeleportname[ ], Float:xFloat:yFloat:zFloat:angleinterioridworldidcmdname[ ] = "\0" ); // returns the ID of the created teleport.
TeleportPlayerplayeridtelidbool:allowvehicle falsebool: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
GetTeleportNameteleportid ); // get the teleport name
GetTeleportInteriorteleportid ); // get the interior of the teleport
GetTeleportWorldteleportid ); // get the virtual world of the teleport
GetTeleportAngleteleportid ); // 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. 
Macros
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 
Callback(s)
PHP код:
forward OnPlayerTeleportplayeridteleportid ); // called whenever a player is teleported to one of the created teleports 
Example script
For those who don't quite understand how this works, here's an example script using ZCMD!
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.91185); // creating the new teleport, the crack den interior in this case
    
CreateTeleport"SF Hospital", -2655.7981638.714814.4531179.984600"/sfhosp" ); // hospital in SF teleport
    
return 1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
public 
OnPlayerTeleportplayeridteleportid // this function is called whenever a player has teleported to one of the created teleports.
{
    new 
str128 ];
    
formatstrsizeofstr ), "[TELEPORT]{FFFFFF} You've been teleported to {FF0000}%s!"GetTeleportNameteleportid ) ); // sending a simple message to the player, including the teleport name.
    
SendClientMessageplayeridCOLOR_ORANGEstr );
    return 
1// returning
}
CMD:teleportsplayeridparams[ ] )
{
    new 
str128 20 ];
    
formatstrsizeofstr ), "Teleports:{FFFFFF} %s"ReturnTeleportCommands( ) );
    
SendClientMessageplayeridCOLOR_ORANGEstr );
    return 
1;

Download
PHP код:
#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 
{
    
NAMES_MAX_TEL_NAME ],
    
FloatX_POS,
    
FloatY_POS,
    
FloatZ_POS,
    
FloatANGLE,
    
INTERIOR,
    
VWORLD,
    
boolCMD_ENABLED,
    
CMD_NAMES_MAX_CMD_NAME ]
};
new 
    
s_TeleportsS_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 OnPlayerTeleportplayeridteleportid );
stock CreateTeleportname[ ], Float:xFloat:yFloat:zFloat:angleinterioridworldidcmdname[ ] = "\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!" );
    
strcpys_Teleportss_count ][ NAME ], nameS_MAX_TEL_NAME );  
    
strcpys_Teleportss_count ][ CMD_NAME ], cmdnameS_MAX_CMD_NAME );
    
s_Teleportss_count ][ CMD_ENABLED ] = ( !strcmpcmdname"0"true ) ? false true );
    
printf"%b"s_Teleportss_count ][ CMD_ENABLED ] );
    
s_Teleportss_count ][ X_POS ] = x;
    
s_Teleportss_count ][ Y_POS ] = y;
    
s_Teleportss_count ][ Z_POS ] = z;
    
s_Teleportss_count ][ ANGLE ] = angle;
    
s_Teleportss_count ][ INTERIOR ] = interiorid;
    
s_Teleportss_count ][ VWORLD ] = worldid;
    
s_count++;
    return ( 
s_count );
}
stock TeleportPlayerplayeridtelidbool:allowvehicle falsebool:loadenv true )
{
    
SetPlayerInteriorplayerids_Teleportstelid ][ INTERIOR ] );
    
SetPlayerVirtualWorldplayerids_Teleportstelid ][ VWORLD ] );
    if( 
GetPlayerStateplayerid ) == PLAYER_STATE_DRIVER && allowvehicle )
    {
        new 
vehicleid GetPlayerVehicleIDplayerid );
        
SetVehiclePosvehicleids_Teleportstelid ][ X_POS ], s_Teleportstelid ][ Y_POS ], s_Teleportstelid ][ Z_POS ] );
        
SetVehicleZAnglevehicleids_Teleportstelid ][ ANGLE ] );
        
LinkVehicleToInteriorvehicleids_Teleportstelid ][ INTERIOR ] );
        
SetVehicleVirtualWorldvehicleids_Teleportstelid ][ VWORLD ] );
    }
    else 
    {
        
SetPlayerPosplayerids_Teleportstelid ][ X_POS ], s_Teleportstelid ][ Y_POS ], s_Teleportstelid ][ Z_POS ] );
        
SetPlayerFacingAngleplayerids_Teleportstelid ][ ANGLE ] );
    }
    if( 
loadenv )
    {
        
TogglePlayerControllableplayeridfalse );
        
SetTimerEx"s_Unfreeze"2000false"i"playerid );
        
GameTextForPlayerplayeridENVLOADING_MSG2000);
    }
    
CallLocalFunction"OnPlayerTeleport""ii"playeridtelid );
    return 
1;
}
forward s_Unfreezeplayerid );
public 
s_Unfreezeplayerid )
{
    
GameTextForPlayerplayeridENVLOADED_MSG1000);
    
TogglePlayerControllableplayeridtrue );
    return 
1;
}
stock ReturnTeleportCommands( )
{
    new 
result128 ];
    for( new 
0s_counti++ )
    {
        
strcatresults_Teleports][ CMD_NAME ] );
        
strcatresult" " );
    }
    return 
result;
}
#if USE_AUTO_COMMANDS == true
// Thanks, Lordzy!
public OnPlayerCommandPerformed(playeridcmdtext[], success
{
    if( !
success 
    { 
        for( new 
0s_counti++) 
        { 
            if( !
s_Teleports][ CMD_ENABLED ] )
                continue;
            if(!
strcmpcmdtexts_Teleports][ CMD_NAME ], truestrlens_Teleports][ CMD_NAME ] ) ) ) 
            {
                
TeleportPlayerplayerid);
                return 
1;
            }
        }
        return 
0;
    }
    return 
1;
}
#endif 
or Github
Credits
SA-MP Team for making all of this possible
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
Please suggest any improvements if any can be made!

- Smileys
Reply
#2

Or, instead of an include

pawn Код:
SetPlayerPos(playerid, X, Y, Z);
SetPlayerFacingAngle(playerid, A);
I find this completely useless and just a rename of the SetPlayer functions and just wasting memory
Reply
#3

Quote:
Originally Posted by sammp
Посмотреть сообщение
Or, instead of an include

pawn Код:
SetPlayerPos(playerid, X, Y, Z);
SetPlayerFacingAngle(playerid, A);

I find this completely useless and just a rename of the SetPlayer functions and just wasting memory
That's 2 lines

Nah but I created this to make it easier for newbs, besides I dont see any "OnPlayerPositionChange" callback linked to SetPlayerPos

Also, with 1 teleport command yea that'd be easier, but what if you'd have 50 or 100 teleport commands? Or enter/exits for interiors and whatnot. I'd rather use this than copy-paste the SetPlayer functions you've posted. Especially with the OnPlayerTeleport callback.
Reply
#4

pawn Код:
new  
    s_Teleports[ S_MAX_TELEPORTS ][ S_TEL_DATA ],
    s_count = 0
;
Use static instead of new!
Reply
#5

Quote:
Originally Posted by $$inSane
Посмотреть сообщение
pawn Код:
new  
    s_Teleports[ S_MAX_TELEPORTS ][ S_TEL_DATA ],
    s_count = 0
;
Use static instead of new!
Looked it up, edited the code and made a few additions for version 2.

Thanks for informing me!

EDIT: can't really make the s_Teleports array static as it fucks up with the macros, when I try to do this:

PHP код:
stock GetTeleportNametelid )
{
    return 
s_Teleportstelid ][ NAME ];

it gives me only the first letter of the name for some reason... when I use the macro it works fine.

if anyone knows what's wrong with that, please inform me so I can update it.
Reply
#6

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 Код:
PutPlayerInVehicle( playerid, vehicleid, 0 );
And lol, why would you ever create a callback if you have to handle teleports manually( from script)!
pawn Код:
OnPlayerTeleport( playerid, teleportid );
You don't require that if there is no deleting of a teleport;
pawn Код:
IsValidTeleport( telid )
No use of this anywhere in you script, except storing tele name!
pawn Код:
s_Teleports[ s_count ][ NAME ]
YOu could make an option of displaying teleport name through gametexts!
Reply
#7

Quote:
Originally Posted by Excel™
Посмотреть сообщение
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)
Well, I wanted this to be for commands and such, like for stunt servers, instead of pickups with labels and whatnot.

I might consider adding a few optional parameters to it in the future though which will contain labels and pickups, but not for now.

Quote:
Originally Posted by Excel™
Посмотреть сообщение
And you don't need this while teleporting the player with vehicle.
pawn Код:
PutPlayerInVehicle( playerid, vehicleid, 0 );
Removed.

Quote:
Originally Posted by Excel™
Посмотреть сообщение
And lol, why would you ever create a callback if you have to handle teleports manually( from script)!
pawn Код:
OnPlayerTeleport( playerid, teleportid );
Didn't quite understand you there..

Quote:
Originally Posted by Excel™
Посмотреть сообщение
You don't require that if there is no deleting of a teleport;
pawn Код:
IsValidTeleport( telid )
Removed.

Quote:
Originally Posted by Excel™
Посмотреть сообщение
No use of this anywhere in you script, except storing tele name!
pawn Код:
s_Teleports[ s_count ][ NAME ]
YOu could make an option of displaying teleport name through gametexts!
It sends the message with the name in the chat whenever you teleport, or atleast you can make that as I did in the example code.

Thanks for pointing out those things though, it's never too late to learn aye
Reply
#8

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) {

    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;
}
Reply
#9

It's quite useful as long as more stuff added to it (see below).

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
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) {

    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;
}
We had used the same idea (the callback of ZCMD)! I had also written in the past a (static though) system for teleports and with a line you could specify if the player will teleport on foot/vehicle, with/without weapons (if with weapons, which - useful for DM teleports too) and a friend of me had suggested a type of teleport (stunts, DMs, fun, Interiors etc).
Reply
#10

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
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) {

    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;
}
Well, tried to do it that way, but for some reason OnPlayerCommandPerformed isnt called, at all...

PHP код:
public OnPlayerCommandPerformed(playeridcmdtext[], success
{
    
printf"called with params: %i, %s, %i"playeridcmdtextsuccess );
    if( !
success 
    { 
        
printf"not success" );
        for( new 
0S_MAX_TELEPORTSi++) 
        { 
              
printf"%i");
            if(!
strcmpcmdtexts_Teleports][ CMD_NAME ], truestrlens_Teleports][ CMD_NAME ] ) ) ) 
            {
                
printf"found: %i" );
                
TeleportPlayerplayerid);
                break;
            }
        }
    }
    return 
1;

it doesn't print any of them, not when I enter a valid command, not when I enter an invalid command.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)