Jump to content

Recommended Posts

Hello.

 

I've found similar posts which describe how to change a flag based on triggers, however, I'm looking for a script that changes the flag with a simple clicking option, for example, while a tank range is not being used, a green flag is displayed at the enterance, when someone enters the range to begin using it, they go up to the flag and toggle the flag, changing it to red and when finished, they can re-toggle it back to green, but with an option displayed when looking at the flag post, similar to the flag post teleportation system. 

 

Any help is much appreciated!

 

Thanks!

Share this post


Link to post
Share on other sites

Just use and addAction

Share this post


Link to post
Share on other sites

Could you elaborate on how I would use this? Such as an example or a little more help?

Share this post


Link to post
Share on other sites
21 minutes ago, EAGLE__ said:

Could you elaborate on how I would use this? Such as an example or a little more help?

 

Something as simple as this might do:

_flag = yourFlag;
_flag setFlagTexture "\A3\Data_F\Flags\Flag_green_CO.paa";
_ID = _flag addAction ["Use Tank Range",{
	params ["_object","_caller","_ID"];
	_state = _object getVariable ["TAG_fnc_flagState",false];
	_texts = ["Clear Tank Range","Use Tank Range"];
	_textures = ["\A3\Data_F\Flags\Flag_red_CO.paa","\A3\Data_F\Flags\Flag_green_CO.paa"];
	_object setFlagTexture (_textures select _state);
	_object setUserActionText[_ID,_texts select _state];
	_object setVariable ["TAG_fnc_flagState",!_state];
},[],1,true,true,"","_target distance2D _this < 3"];

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Oh wow I thought this would be much more complicated! Where abouts would I put this, in my init.sqf or the init of the flag itself?

Share this post


Link to post
Share on other sites

I worked it out. Though I wonder if it's possible to execute multiple flags at once from one single flag? So Flag1 executes itself as well as Flag2 and Flag3 and vice versa, Flag2 executes itself and Flag1 and Flag3 etc.

Also how would I ensure this runs globally? The script works, but only for the client who presses the option, the texture remains the same for other clients unless they press it themselves.

Share this post


Link to post
Share on other sites
39 minutes ago, EAGLE__ said:

Bump

No need to bump stuff in these forums, at least not within a reasonable 48h, it's moving slow but stuff usually doesn't go unanswered.

 

For MP setFlagTexture has global effect, as long as the command is executed where the flag is local, a remoteExec comes in handy for this:

_flags = [yourFlag1,yourFlag2,yourFlag3];
{
	_x setVariable ["TAG_fnc_flags",_flags,true];
	_ID = _x addAction ["Use Tank Range",{

		params ["_object","_caller","_ID"];
		_state = _object getVariable ["TAG_fnc_flagState",false];
		_texts = ["Clear Tank Range","Use Tank Range"];
		_textures = ["\A3\Data_F\Flags\Flag_red_CO.paa","\A3\Data_F\Flags\Flag_green_CO.paa"];
		_flags = _object getVariable ["TAG_fnc_flags",[]];
		{
			[_x,(_textures select _state)] remoteExec ["setFlagTexture",_x];
			_x setUserActionText[_ID,_texts select _state];
			_x setVariable ["TAG_fnc_flagState",!_state,true];
		} forEach _flags;
	},[],1,true,true,"","_target distance2D _this < 3"];
	[_x,"\A3\Data_F\Flags\Flag_green_CO.paa"] remoteExec ["setFlagTexture",_x];
} forEach _flags;

Also changes textures and action names accordingly.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, Grumpy Old Man said:

No need to bump stuff in these forums, at least not within a reasonable 48h, it's moving slow but stuff usually doesn't go unanswered.

 

For MP setFlagTexture has global effect, as long as the command is executed where the flag is local, a remoteExec comes in handy for this:


_flags = [yourFlag1,yourFlag2,yourFlag3];
{
	_x setVariable ["TAG_fnc_flags",_flags,true];
	_ID = _x addAction ["Use Tank Range",{

		params ["_object","_caller","_ID"];
		_state = _object getVariable ["TAG_fnc_flagState",false];
		_texts = ["Clear Tank Range","Use Tank Range"];
		_textures = ["\A3\Data_F\Flags\Flag_red_CO.paa","\A3\Data_F\Flags\Flag_green_CO.paa"];
		_flags = _object getVariable ["TAG_fnc_flags",[]];
		{
			[_x,(_textures select _state)] remoteExec ["setFlagTexture",_x];
			_x setUserActionText[_ID,_texts select _state];
			_x setVariable ["TAG_fnc_flagState",!_state,true];
		} forEach _flags;
	},[],1,true,true,"","_target distance2D _this < 3"];
	[_x,"\A3\Data_F\Flags\Flag_green_CO.paa"] remoteExec ["setFlagTexture",_x];
} forEach _flags;

Also changes textures and action names accordingly.

 

Cheers


My apologies for bumping. 

It's so simple but in the words of Todd "it just works". Thank you a lot for this.

Would it be better to execute a remoteExec through init.sqf or can it remain in the flag init and still execute globally for all clients?

Thanks

Share this post


Link to post
Share on other sites
17 hours ago, EAGLE__ said:


My apologies for bumping. 

It's so simple but in the words of Todd "it just works". Thank you a lot for this.

Would it be better to execute a remoteExec through init.sqf or can it remain in the flag init and still execute globally for all clients?

Thanks

init.sqf will run for every player that joins, stuff like that is better kept in event scripts that fit the scope/functionality.

All depends on what you want and what gamemode it should be in (SP, local hosted MP, ded. MP), which is usually best stated in the first post.

 

For MP (should also work on dedi with JIP) it could look like this:

//initServer.sqf
_flagsTankRange1 = [yourFlag1,yourFlag2,yourFlag3];
missionNamespace setVariable ["TAG_fnc_flagsTankRange1",_flagsTankRange1,true];
{
	[_x,"\A3\Data_F\Flags\Flag_green_CO.paa"] remoteExec ["setFlagTexture",_x];

} forEach TAG_fnc_flagsTankRange1;

//initPlayerLocal.sqf
{
	_ID = _x addAction ["Use Tank Range",{
		params ["_object","_caller","_ID"];
		_state = _object getVariable ["TAG_fnc_flagState",false];
		_texts = ["Clear Tank Range","Use Tank Range"];
		_textures = ["\A3\Data_F\Flags\Flag_red_CO.paa","\A3\Data_F\Flags\Flag_green_CO.paa"];
		{
			[_x,(_textures select _state)] remoteExec ["setFlagTexture",_x];
			_x setUserActionText[_ID,_texts select _state];
			_x setVariable ["TAG_fnc_flagState",!_state,true];
		} forEach TAG_fnc_flagsTankRange1;
	},[],1,true,true,"","_target distance2D _this < 3"];
} forEach TAG_fnc_flagsTankRange1;

No guarantees though, quickly butchered this one together, should work fine at first glance, heh.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I've came up with a good system which works with multiple clients on a dedicated MP server. 
 

We placed the below code you provided us with inside the init of an invisible helipad. We then set the variable names of each flag we want to change to yourFlag1 etc. and made sure they were exactly the same inside the invisible helipad's init. The invisible helipad then executes the code and adds the option to "Use Tank Range" on each named flag. Using the option on yourFlag1 will also change yourFlag2 and yourFlag3, and vice versa. We've tested this on a dedicated MP client with other clients changing and it changes, and updates instantly for all of us. 

 

Thanks a bunch to @Grumpy Old Man for helping me with this!

_flags = [yourFlag1,yourFlag2,yourFlag3];
{
	_x setVariable ["TAG_fnc_flags",_flags,true];
	_ID = _x addAction ["Use Tank Range",{

		params ["_object","_caller","_ID"];
		_state = _object getVariable ["TAG_fnc_flagState",false];
		_texts = ["Clear Tank Range","Use Tank Range"];
		_textures = ["\A3\Data_F\Flags\Flag_red_CO.paa","\A3\Data_F\Flags\Flag_green_CO.paa"];
		_flags = _object getVariable ["TAG_fnc_flags",[]];
		{
			[_x,(_textures select _state)] remoteExec ["setFlagTexture",_x];
			_x setUserActionText[_ID,_texts select _state];
			_x setVariable ["TAG_fnc_flagState",!_state,true];
		} forEach _flags;
	},[],1,true,true,"","_target distance2D _this < 3"];
	[_x,"\A3\Data_F\Flags\Flag_green_CO.paa"] remoteExec ["setFlagTexture",_x];
} forEach _flags;

 

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

×