Jump to content
Sign in to follow this  
Enigx

Addaction for spawned teleport flag poles for all players

Recommended Posts

Hi guys,

I've an user interface that allows to launch scripts when I'm in MP game, by dedicated scripts calling buttons. For training server I would like to use it to spawn two (or more) flag poles, by clicking their position on map, and add an addAction for all players to teleport them between the flags position.

No problem to create flags and so on. The problem is the addaction. Of course I'm in game and I cannot insert it in the spawned flags init. So I have to use a remoteexec to create the addaction.

It is visible to all but only me (that launched the script) can use the action. The other clients cannot.

I have this for the addaction strings:

// flag 1 to flag 2
[arrayFlags select 0, [_arrayTextFlag select 1, {player setPos (getPos (arrayFlags select 1))}]] remoteExec ["addAction",0,false];

// flag 2 to flag 1
[arrayFlags select 1, [_arrayTextFlag select 0, {player setPos (getPos (arrayFlags select 0))}]] remoteExec ["addAction",0,false];

Note: I have arrays of flags (with text and colors) because I can create more than 2 flags.

I run the addaction globally, but only me can use the action. Why? They see the action but cannot use it.

Maybe is "player" the problem? Is it always "me" and not the client, where the the addaction is created by the remoteexec with global "0"?

Thank you in advance for support

 

Share this post


Link to post
Share on other sites

The problem is the arrayFlags variable. That global variable only exists on the client that created the flags (your PC), not on everybody elses.

Let's restructure your code by passing along the teleport target flag as an argument in the addAction parameters.

 

_actionCode = {
	params ["_actionObject","_actionCaller","_actionID","_teleportTarget"];
	_actionCaller setPos getPos _teleportTarget;
};

// flag 1 to flag 2
[arrayFlags # 0, [_arrayTextFlag # 1, _actionCode, arrayFlags # 1]] remoteExec ["addAction",0,false]; // "#" is the same as a simple "select"

// flag 2 to flag 1
[arrayFlags # 1, [_arrayTextFlag # 0, _actionCode, arrayFlags # 0]] remoteExec ["addAction",0,false];

And beyond the scope of your question just for fun, let's make it so you can have many flags instead of 2, all allowing teleportation to every other one:

arrayFlags = [flag1,flag2,flag3,flag4];
_arrayTextFlag = ["flag 1","flag 2","flag 3","flag 4"];

_actionCode = {
	params ["_actionObject","_actionCaller","_actionID","_teleportTarget"];
	_actionCaller setPos getPos _teleportTarget;
};

{
	_currentFlag = _x;
	{
		_targetFlag = _x;
		if (_targetFlag != _currentFlag) then {
			[_currentFlag, [_arrayTextFlag # _forEachIndex, _actionCode, _targetFlag]] remoteExec ["addAction",0,false];
		};
	} forEach arrayFlags;
} forEach arrayFlags;

You could also make this entire thing a function that is called locally to reduce network traffic (not really important for this tbh), but to cleanly do that you need some knowledge of the Functions Library.

Share this post


Link to post
Share on other sites

Thank you Dennenboom,

I mistakenly thought that the global variable was for everyone. I read its definition better on wiki and I understood.
I will try your solution.
But I have another question. We are two administrators who can create teleport flags via the graphical interface. If we both create them do we have two distinct sets of flag teleports?
How do we do if we want to create only one set of flags at a time?

Thanks again

Share this post


Link to post
Share on other sites

I'm not sure how your graphical interface works, but I guess if both admins place flags there will be two pairs of flags.

 

You could either make it so the other admin cannot place flags when they already exist, or so that the new pair of flags replace the old pair.

Determining the best solution would require your interface I guess.

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
Sign in to follow this  

×