Jump to content
Ferdilanz

[SOLVED] Teleport Player + Group of Other Players onMapSingleClick

Recommended Posts

Hello,

A server owner has tasked me with creating a script to teleport him and his group of admins to a position on the map determined by a mouse click. We're doing this via "player addAction" and he already has a trigger set up to "removeAllActions player" when done. The owner needs the action to first open the map, where he will LeftAlt-LMB click on a position, and the script to teleport him and his group to that position without breaking formation. For the sake of simplicity, could the addAction possibly be put in the Init field of a playable character which execVM's a squiff?

I also found this elsewhere on the forum:

fnc_teleportGroup = 
{
    params ["_group", "_position"];

    private _leader = leader _group;
    
    {
        private _dir = _leader getDir _x;
        private _dist = _x distance2D _leader;
        _x setPos (_position getPos [_dist, _dir]);
    }
    forEach units _group - [_leader];
    
    _leader setPos (_position getPos [0, 0]);
};
[group player, [x,y,z]] call fnc_teleportGroup;

How can this be modified to both open the map on the addAction's activation and close it after the teleport is done? I want the xyz to be replaced with the leader's relative coords. Like a translation of a shape whose vertices are members of the group, except done with a script.

I used to be able to do this but in the years since 2015 I have lost my ability and patience to write scripts myself.

Big, ginormous thanks in advance.

Share this post


Link to post
Share on other sites
47 minutes ago, Adrien Remaz said:

Hello,

A server owner has tasked me with creating a script to teleport him and his group of admins to a position on the map determined by a mouse click.


Don't they have admin access to the debug console and camera?


 

59 minutes ago, Adrien Remaz said:

I want the xyz to be replaced with the leader's relative coords. Like a translation of a shape whose vertices are members of the group, except done with a script.


I'm getting a Star Trek vibe here. Nice!


 

49 minutes ago, Adrien Remaz said:

I used to be able to do this but in the years since 2015 I have lost my ability and patience to write scripts myself.


C'mon.
It's like riding a bike... Where the bike gets less and less squeaky by the mile.



Some help:
addActionopenMaponMapSingleClicksetPos.


🖖 

Share this post


Link to post
Share on other sites
2 minutes ago, Maff said:


Don't they have admin access to the debug console and camera?


 


I'm getting a Star Trek vibe here. Nice!


 


C'mon.
It's like riding a bike... Where the bike gets less and less squeaky by the mile.



Some help:
addActionopenMaponMapSingleClicksetPos.


🖖

1. Yes, but they want this done on a mission level for convenience as they are not just the operator but also boots on the ground.

2. Not intentional at all.

3. I'm sure.

4. Was kinda hoping someone with more knowledge would do this right because I don't want to get it wrong and cause some horrific mission failure because I'm 7 years out of practice.

Share this post


Link to post
Share on other sites
16 minutes ago, Adrien Remaz said:

4. Was kinda hoping someone with more knowledge would do this right because I don't want to get it wrong and cause some horrific mission failure because I'm 7 years out of practice.


You'll be fine.
Give it a go and use this post if / when you run into trouble.

From the example function, it looks like you're halfway there.

You'll only get it wrong and cause horrific failure if you don't test and test again.

Share this post


Link to post
Share on other sites
10 minutes ago, Maff said:


You'll be fine.
Give it a go and use this post if / when you run into trouble.

You'll only get it wrong and cause horrific failure if you don't test and test again.

 

fnc_teleportGroup = 
{
    params ["_group", "_position"];
	openMap [true,false]
    private _leader = leader _group;
    
    {
        private _dir = _leader getDir _x;
        private _dist = _x distance2D _leader;
        _x setPos (_position getPos [_dist, _dir]);
    }
    forEach units _group - [_leader];
    
    _leader setPos (_position getPos [0, 0]);
	openMap [false,false]
};
onMapSingleClick[group player, [getPos _leader, getPos _leader]] call fnc_teleportGroup;

Does this look right? In the last line, the brackets have the x and y of the group leader but not the z because I think the z is implied in the script anyway? Just autosnaps to the terrain? Don't know why the openMap commands are indented like that.

Share this post


Link to post
Share on other sites
2 minutes ago, Adrien Remaz said:

Does this look right? In the last line, the brackets have the x and y of the group leader but not the z because I think the z is implied in the script anyway? Just autosnaps to the terrain? Don't know why the openMap commands are indented like that.


Does it work?
You need to test it before you know if it works or not.

Going by your requirements you need to use addAction to openMap then onMapSingleClick ( check the parameters ) so you can fnc_teleportGroup / setPos.
 

 

Share this post


Link to post
Share on other sites
10 minutes ago, Maff said:


Does it work?
You need to test it before you know if it works or not.

Going by your requirements you need to use addAction to openMap then onMapSingleClick ( check the parameters ) so you can fnc_teleportGroup / setPos.
 

 

It doesn't work. And I don't know what to do to make it work. Think I'm just going to give up. I really can't do this.

Share this post


Link to post
Share on other sites
6 minutes ago, Adrien Remaz said:

It doesn't work. And I don't know what to do to make it work. Think I'm just going to give up. I really can't do this.


Sleep on it and don't give up on your task.

Did you want someone else to create the script for you?


 

Share this post


Link to post
Share on other sites
7 minutes ago, Maff said:


Sleep on it and don't give up on your task.

Did you want someone else to create the script for you?


 

I don't want to say yes because I don't want to look like some lazy begging noob who wont at least make the attempt to learn something, but the truth is that I did want someone to help me in such a fashion that I could take the missing elements (provided by a forum user) and put those elements into the established base I originally posted.

Share this post


Link to post
Share on other sites

just an example:


 

onMapSingleClick "
  params ['_pos','_units','_shift','_alt','_dir','_leader','_dist'];
  _units = units player;
  _leader = leader group player;
  _teleport = _units apply {[_x,[_leader distance _x,_leader getDir _x]]};
  {
    _x#0 setPos (_pos getpos (_x#1));
  } forEach _teleport;
";

 

  • Like 3

Share this post


Link to post
Share on other sites
10 hours ago, pierremgi said:

just an example:


 


onMapSingleClick "
  params ['_pos','_units','_shift','_alt','_dir','_leader','_dist'];
  _units = units player;
  _leader = leader group player;
  _teleport = _units apply {[_x,[_leader distance _x,_leader getDir _x]]};
  {
    _x#0 setPos (_pos getpos (_x#1));
  } forEach _teleport;
";

 

hmm, so assuming this works, I believe I can add an openMap at the beginning and end to force the map open when the Action in the context menu is triggered and closed after the TP is done. The server owner has a type of "SafeStart" when briefings are held in a Safe Area and players are generally safe from damage. The "player addAction" I plan to have the mission maker put into the player's init so it'll execVM the squiff (this line is found easily on the internet). When the SafeStart ends, the server owner says he already has a trigger for something else. I found another script for enablement and disablement here on the forums so I'm using that for the sake of reliability.

//(group leader Init field) this addAction ["<t color='#0000FF'>Group Teleport</t>","mission_pbo\addons\groupTeleport.sqf",[],6,false,true];
//mission.pbo\addons\groupTeleport.sqf
//framework from mrcurry on BIS forums
params ["_leader", "_caller", "_id", "_args"]; //don't know what to do with these params other than _leader

_leader setVariable ["tp1", true]; //_leader is the target I want this run on

while { _leader getVariable "tp1" } do {
	openMap [true,false];
//script from pierremgi on BIS forums
	onMapSingleClick "
  		params ['_pos','_units','_shift','_alt','_dir','_leader','_dist'];
  		_units = units player;
  		_leader = leader group player;
  		_teleport = _units apply {[_x,[_leader distance _x,_leader getDir _x]]};
  		{
    			_x#0 setPos (_pos getpos (_x#1));
  		} forEach _teleport;
";
openMap [false, false];
};

and we do 
object setVariable ["tp1", false];
when the server SafeStart ends, which will trigger a Trigger.

Not sure what to do with all those params at the top from mrcurry's script. Do I need to change anything?

Share this post


Link to post
Share on other sites
//groupTeleport.sqf 
//framework from mrcurry on BIS forums 
params ["_leader", "_caller", "_id", "_args"]; //don't know what to do with these params other than _leader 
 
_leader setVariable ["tp1", true]; //_leader is the target I want this run on 
openMap [true,false]; 
while { _leader getVariable "tp1" } do { 
//script from pierremgi on BIS forums
    onMapSingleClick " 
          params ['_pos','_units','_shift','_alt','_dir','_leader','_dist']; 
          _units = units player; 
          _leader = leader group player; 
          _teleport = _units apply {[_x,[_leader distance _x,_leader getDir _x]]}; 
          { 
                _x#0 setPos (_pos getpos (_x#1)); 
          } forEach _teleport; 
	";
};
_leader setVariable ["tp1", false];
openMap [false, false];

so the previous script didn't work. just kept opening and closing the map about every frame.

I put this addAction ["<t color='#0000FF'>Group Teleport</t>","groupTeleport.sqf",[],6,false,true]; in the leader's Init field.

I revised it slightly as seen above (moved openMap [true,false] from the while loop) and it's working properly for the most part, but the problem with this is that it doesn't even run the last 2 lines.

It grants the leader a permanent ability to teleport regardless the addAction's activation.

Now, I have an older mouse that sometimes de-clicks when my finger is still holding down the mouse button and re-clicks shortly after. This causes me to teleport while moving the map with my clicked mouse.

I just need the _leader's tp1 variable set to false after the teleport completes.

Share this post


Link to post
Share on other sites
//framework from mrcurry on BIS forums 
params ["_leader", "_caller", "_id", "_args"]; //don't know what to do with these params other than _leader 
_leader setVariable ["tp1",true]; //_leader is the target I want this run on 
openMap [true,false]; 
while { (_leader getVariable ["tp1",true]) && (call TMF_safestart_fnc_isActive) } do { 
//script from pierremgi on BIS forums
    onMapSingleClick " 
        params ['_pos','_units','_shift','_alt','_dir','_leader','_dist']; 
        _units = units player; 
        _leader = leader group player; 
		_teleport = _units apply {[_x,[_leader distance _x,_leader getDir _x]]}; 
		{ 
			_x#0 setPos (_pos getpos (_x#1)); 
			openMap [false, false];
		} forEach _teleport; 
	";
};
while { (_leader getVariable ["tp1",true]) && !(call TMF_safestart_fnc_isActive) } do {
	_leader setVariable ["tp1",false];
	//removeAllActions _leader;
};

I've refined the script even further including the SafeStart check but even when SafeStart is over, I can still teleport. This was a major problem in other mods that incorporate teleportation.

The testing I've done revealed:

  • I cannot teleport before the action in the contextMenu is activated.
  • I can teleport just fine while SafeStart is active.
  • I can teleport while SafeStart has ended and while not activating the contextMenu action, which is not an intended outcome

Share this post


Link to post
Share on other sites

Got this solved by artemoz on the Arma official discord. The server owner and I fixed the implementation and smaller oddities and expect to fully deploy this immediately.

//groupTeleport.sqf 
//teleports the group with the leader upon a click of the map only once and then disables itself
//removeAllActions _leader
//(group leader Init) this addAction ["<t color= '#FF0000'>Deploy Group</t>",{vehicle player setPos (getMarkerPos "marker_0"); [_this select 0,_this select 2] remoteExec ["removeAction", 0, true];},nil,1.5,false,true,"","true",1,false];
//framework from mrcurry on BIS forums 
params ["_leader", "_caller", "_id", "_args"]; //don't know what to do with these params other than _leader 
// commenting the line below because the intent seems to restrict the TP ability from outside 
// and setting "tp1" to true here defeats that purpose (?)
//_leader setVariable ["tp1",true]; //_leader is the target I want this run on 
//SOLUTION FROM artemoz ON ARMA DISCORD
// do nothing if teleport is not allowed
if !((_leader getVariable ["tp1",true]) && (call TMF_safestart_fnc_isActive)) exitWith {};
openMap [true,false]; 
//script from pierremgi on BIS forums
onMapSingleClick " 
    params ['_pos','_units','_shift','_alt','_dir','_leader','_dist']; 
    _units = units player; 
    _leader = leader group player;
    _teleport = _units apply {[_x, _pos getpos [_leader distance _x,_leader getDir _x]]}; 
    { 
        [_x#0, _x#1] remoteExec ['setPos', _x#0]; 
    } forEach _teleport; 
    openMap [false, false];
    onMapSingleClick '';
"; // moved calculation of the final position straight here 
//_x#0 setPos (_pos getpos (_x#1));
// To make it work with other players/non-local units. Effectively calls `_x#0 setPos _x#1` wherever _x#0 is local (in theory) 
// to clear the map click event handler if user closes the map some other way
waitUntil {sleep 1;!visibleMap};
onMapSingleClick ''; 

Moderators can mark this as SOLVED.

  • Like 1

Share this post


Link to post
Share on other sites
51 minutes ago, Ferdilanz said:

Moderators can mark this as SOLVED.

 

Edit your first post and you'll also have the option to edit the topic title.

  • Like 2

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

×