Jump to content
kgino1045

How to Teleport script??

Recommended Posts

Why not doing setPos all the time and ride on the cannonball ?

:D

  • Like 1

Share this post


Link to post
Share on other sites

Why not doing setPos all the time and ride on the cannonball ?

:D

 

attachTo works nicely too for those wild rides.

  • Like 1

Share this post


Link to post
Share on other sites

Fugg, I have all this down, right code on ingame objects, and a correct teleport.sqf and I get all the correct options ingame, yet once I select them nothing happens

 

this addAction ["Teleport - Savage","teleport.sqf",["Savage"]];
this addAction ["Teleport - Vandergrift","teleport.sqf",["Vandergrift"]];
this addAction ["Teleport - Sarge","teleport.sqf",["Sarge"]];
this addAction ["Teleport - Runway End","teleport.sqf",["End"]];
 
_dest = (_this select 3) select 0;
 
_dir = random 359;
 
player SetPos [(getPos _dest select 0)-10*sin(_dir),(getPos _dest select 1)-10*cos(_dir)];
 
Thats my teleport.sqf
 
I have this on all my ingame objects that im using as a teleport item
 
this addAction ["Teleport - Savage","teleport.sqf",["Savage"]];
this addAction ["Teleport - Vandergrift","teleport.sqf",["Vandergrift"]];
this addAction ["Teleport - Sarge","teleport.sqf",["Sarge"]];
this addAction ["Teleport - Runway End","teleport.sqf",["End"]];

 

EX. Lets say your at savage, and want to go to vandergrift, the object your teleporting from have this in its INT

 

this addAction ["Teleport - Savage","teleport.sqf",["Savage"]];
this addAction ["Teleport - Vandergrift","teleport.sqf",["Vandergrift"]];
this addAction ["Teleport - Sarge","teleport.sqf",["Sarge"]];
this addAction ["Teleport - Runway End","teleport.sqf",["End"]];
 
I have the Savage crossed out so you dont get the option to tele to your own POS.
 
 
Thats how I have it setup, now do you guys know why it aint working? Very much apriciated, Thanks

Share this post


Link to post
Share on other sites
On 2015-10-01 at 10:54 PM, Von Quest said:

Note: if just using Editor/Preview. You can hold LAlt when left-click mouse to teleport as well.

Even years later, this is still very useful.

Share this post


Link to post
Share on other sites

Does anyone have the code for producing that LAlt+Left Click teleport option in multiplayer for admins?

Share this post


Link to post
Share on other sites

I know this is an old topic. I already use the below teleport script:

 

// this addAction ["Teleport -destinationName","teleport.sqf",[objectName]];

 

// Get the destination.

_dest = (_this select 3) select 0;

 

// Get a random direction

_dir = random 359;

 

// Move the person a few meters away from the destination (in the direction of _dir)

player SetPos [(getPos _dest select 0)-10*sin(_dir),(getPos _dest select 1)-10*cos(_dir)];

 

But, I am trying to understand it better. In the above line for (// Get the destination) i have a question for those who have a better understanding of the script language.

Say for example I am using an empty marker on the map. I make the variable name in the marker hq. Using the addAction script line above in a flagpole, i make the [objectName] hq.

I know that this sends the argument hq to the teleport.sqf script.

In the     _dest = (_this select 3) select 0;     line, I would like to understand better what is happening here. _this represents the passed argument of hq i take it. But it is the select functions that are confusing me.

The (select 3) select 0  I understand that select is pulling in array elements. I just don't understand the 3 and then 0. What is actually happening here which then becomes _dest?

 

Thanks for any clarity anyone can provide.

Share this post


Link to post
Share on other sites
this addAction 
[
	"Teleport -destinationName",
	"teleport.sqf",
	[objectName]
];

 

A script called by addAction in this way has an array of parameters passed to it by default:

//teleport.sqf

params ["_target", "_caller", "_actionId", "_arguments"];

The old way of writing this would be:

//teleport.sqf

private ["_target", "_caller", "_actionId", "_arguments"];

_target = _this select 0;
_caller = _this select 1;
_actionId = _this select 2;
_arguments = _this select 3;

OR:

//teleport.sqf

private _target = _this select 0;
private _caller = _this select 1;
private _actionId = _this select 2;
private _arguments = _this select 3;

 

Those params are:

Quote
  • target: Object - the object which the action is assigned to
  • caller: Object - the unit that activated the action
  • actionID: Number - activated action's ID (same as addAction's return value)
  • arguments: Anything - arguments given to the script if you are using the extended syntax

 

The fourth element "_arguments" is the relevant one. 

 

In sqf, arrays are zero-indexed, so an array with four elements will be indexed as 0,1,2,3. You can see in the second and third examples above where they are declared as such.

 

[objectName] is an array of arguments to be sent to the script, which is then accessed via _arguments (also known as _this select 3).

 

So:

_dest = (_this select 3) select 0;

_dest is being defined as whatever is held in _arguments. _arguments is itself an array (it's whatever you put in [objectName] in the addAction), so we need to select an element from it. Since it only has one element, we'll use that.

 

Hence (_this select 3) select 0.

 

A cleaner way of writing it would be:

//teleport.sqf

params ["_target", "_caller", "_actionId", "_arguments"];

private _dest = _arguments#0;  // "#" is another way to write "select" that runs slightly faster
private _dir = random 359;
_caller setPos [(getPos _dest#0)-10*sin(_dir),(getPos _dest#1)-10*cos(_dir)];

 

  • Like 4

Share this post


Link to post
Share on other sites

arguments in addAction don't have any interest if you can use global variables or marker names. It's fine for passing local variables from a scope to the addAction, inside a script.

In other word, don't use argument if marker's name / object's name is already defined by a string  / global variable.

Furthermore, it's also possible to set a variable on the caller or the target  (player setVariable ["someThing", _toBePassed]),  then use it inside addAction (in accordance with locality here).

  • Like 1

Share this post


Link to post
Share on other sites

Wow... thanks for that.. I've been searching for that information for quite a while.

Thank you ... it is already more clear to me now.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×