Jump to content
Northup

SOLVED: Detecting captured flag

Recommended Posts

Context:
I have mission that contains multiple flagpoles. Each is named (Flag_1, Flag_2)
Player captures a flagpole, it should change the marker color of TowerPost%1. Marker will stay the same until another team captures the flagpole.

I've tried this, and ultimately, I am unsure of what to use to determine if a flag has been captured, and returning it's name for a split string. 

Edit:
 

I just modified the aftercommand to get the flagside the same way the existing code did, then use that to set the markercolor. I wasn't able to figure out how to get the name of flag1, split the string, and format towerpost%1 based on that, but this really isn't that much more work.

_flag = this;
params ["_winSide"];
_afterCommand = {**_get = _flag getVariable ["TER_flagSide",civilian];**
_marker1 = "TowerPost1";
_mkrcolor = switch (_get) do {
case west: {
_marker1 setmarkerColor "ColorBLUFOR";
};
case east: {
_marker1 setmarkerColor "ColorOPFOR";
};
case independent: {
_marker1 setmarkerColor "ColorIndependent";
};
default {
_marker1 setmarkerColor "ColorGrey";
};
};
};

_fncOwnFlag = {
params ["_winSide"];
_flagPath = "\a3\data_f\flags\%1.paa";
_fileFlag = switch _winSide do {
case west: {"flag_nato_co"};
case east: {"flag_csat_co"};
case independent: {"flag_aaf_co"};
default {"flag_white_co"}
};
format [_flagPath,_fileFlag];
};
_actionParams = ["_flag", "_caller", "_actionId", "_arguments"];

_flag setflagAnimationPhase 1;
_flag setFlagTexture (civilian call _fncOwnFlag);

_flag setVariable ["TER_flagSide",civilian];
_icon = "\a3\ui_f\data\igui\cfg\holdactions\holdaction_takeoff2_ca.paa";
_duration = 10;
_addID = [_flag, "Capture Post", _icon, _icon,
"_target getVariable [""TER_flagSide"",civilian] != side _this",
"true",
{
},
{
params ["_flag", "_caller", "_actionId", "_arguments","_progress","_maxProgress"];
_arguments params ["_actionParams","_fncOwnFlag","_afterCommand"];
_relProgress = _progress/_maxProgress;
if (_relProgress < 0.5) then {
_flag setFlagAnimationPhase (1-(2*_relProgress));
} else {
if (_relProgress == 0.5) then {_flag setFlagTexture (side _caller call _fncOwnFlag)};
_flag setFlagAnimationPhase ((2*_relProgress)-1);
};
},
{
params ["_flag", "_caller", "_actionId", "_arguments"];
_arguments params ["_actionParams","_fncOwnFlag","_afterCommand"];
_flag setVariable ["TER_flagSide",side _caller];
[] call _afterCommand;
},
{
params ["_flag", "_caller", "_actionId", "_arguments"];
_arguments params ["_actionParams","_fncOwnFlag","_afterCommand"];
_flag setFlagAnimationPhase 1;
_side = _flag getVariable ["TER_flagSide",civilian];
_flag setFlagTexture (_side call _fncOwnFlag);
},
[_actionParams,_fncOwnFlag,_afterCommand], _duration, 1.5, false] call BIS_fnc_holdActionAdd;

_addID

 

Share this post


Link to post
Share on other sites
Spoiler

EDIT: Fixed some MP anomalies

Edited by Larrow
Fixed MP anomalies
  • Like 1

Share this post


Link to post
Share on other sites
22 hours ago, Larrow said:
  Hide contents


//Description.ext

class CfgFunctions {
	class NUP_flagCapture {
		tag = "NUP";
		class flagCapture {
			file = "NUP\NUP_flagCapture\functions";
			
			class initFlag {  };
			class captureFlag {  };
		};
	};
};


//NUP\NUP_flagCapture\functions\fn_initFlag.sqf

params[
	[ "_flag", objNull, [ objNull ] ],
	[ "_marker", "", [ "" ] ],
	[ "_side", civilian, [ sideUnknown ] ]
];

//Make sure parameters are valid
if ( isNull _flag || { !( _flag isKindOf "FlagCarrierCore" ) } ) exitWith{ [ "Invalid Flag given" ] call BIS_fnc_error };
if ( _marker == "" || { getMarkerPos _marker == [0,0,0] } ) exitWith{ [ "Invalid Flag Marker given" ] call BIS_fnc_error };
if !( _side in [ east, west, independent, civilian ] ) exitWith{ [ "Invalid Flag Side given" ] call BIS_fnc_error };


//Set defaults
_flag setVariable[ "NUP_flagMarker", _marker ];
[ _flag, civilian, true ] call NUP_fnc_captureFlag;

//Add flags holdAction
_icon = "\a3\ui_f\data\igui\cfg\holdactions\holdaction_takeoff2_ca.paa";
_duration = 10;

[
	_flag,
	"Capture Post",
	_icon,
	_icon,
	"_target getVariable[ ""TER_flagSide"", civilian ] != side _this",
	"true",
	//Start
	{
	},
	//Progress
	{
		params[ "_flag", "", "", "", "_progress", "_maxProgress" ];

		_relProgress = _progress/_maxProgress;

		_progress = if ( _relProgress <= 0.5 ) then {
			linearConversion[ 0, 0.5, _relProgress, 1, 0 ]
		}else{
			linearConversion[ 0.5, 1, _relProgress, 0, 1 ]
		};
		_flag setFlagAnimationPhase _progress;
	},
	//Completed
	{
		params["_flag", "_caller" ];
		
		[ _flag, side _caller ] call NUP_fnc_captureFlag;
	},
	//Interrupt
	{
		params[ "_flag", "_caller" ];
		
		_flag setFlagAnimationPhase 1;
	},
	[], 
	_duration,
	1.5,
	false
] call BIS_fnc_holdActionAdd;


//NUP\NUP_flagCapture\functions\fn_captureFlag.sqf

params[
	[ "_flag", objNull, [ objNull ] ],
	[ "_side", civilian, [ sideUnknown ] ],
	[ "_init", false, [ false ] ]
];

//Get flags marker
_marker = _flag getVariable "NUP_flagMarker";

//Set flags owner
_flag setVariable[ "TER_flagSide", _side ];

//Set flags texture	
_sideID = _side call BIS_fnc_sideID;
_fileFlag = [ "flag_csat_co", "flag_nato_co", "flag_aaf_co", "flag_white_co" ] select _sideID;
_flag setFlagTexture format[ "\a3\data_f\flags\%1.paa", _fileFlag ];

//Make sure flag is at full hoist
_flag setFlagAnimationPhase 1;

//Set flags marker color
_marker setMarkerColor ( [ "ColorOPFOR", "ColorBLUFOR", "ColorIndependent", "ColorGrey" ] select _sideID );

//Call SEH event that flag has changed
//So you can register to this for owner changed notifications
if !( _init ) then {
	[ missionNamespace, "NUP_onFlagOwnerChanged", [ _flag, _marker, _side ] ] remoteExec [ "BIS_fnc_callScriptedEventHandler" ];
};



//Each flags init in the editor

[ this, "flagsMarkerName" ] call NUP_fnc_initFlag;


//Register somewhere to OnFlagOwnerChanged event

[
	missionNamespace, 
	"NUP_onFlagOwnerChanged",
	{
		params[ "_flag", "_marker", "_side" ];
		
		//Do something
		systemChat format[ "Flag: %1, Marker: %2 changed to side %3", _flag, _marker, _side ];
	};
] call BIS_fnc_addScriptedEventHandler;

TEST_MISSION

 

I'll work on switching to this over the next couple days. This is good stuff. Thanks @Larrow

Share this post


Link to post
Share on other sites
2 hours ago, Northup said:

I'll work on switching to this over the next couple days.

See the download in the previous post. I fixed some things that were not quite working correctly in MP.

  • Like 1

Share this post


Link to post
Share on other sites
19 hours ago, Larrow said:

See the download in the previous post. I fixed some things that were not quite working correctly in MP.

Just got around to testing it.

Issue: Seems only one marker updates.

In the mission I have currently, I have anywhere between 1 and 7 such "capturable" flags. 

Reproduce:
Copy and paste the flag and marker in the 3d editor. Start the mission and capture both flags.
 

Context:
The flag (and everything else) is part of a larger mission. I was using attempting to  use capturable flags to change the color of a marker, then using the markercolor to act as a switch of sorts. 
Each flag (will) belong to a composition that spawns in via LARs. The composition is a simple "base" with 3 cargo houses (two military and one medical) and a numbered tower. The idea is that the flag can be captured by any side at any time, and recaptured by another side, ad infinitum, until the match ends. 

Each cargo house has an object. In the military houses, that object is a supply crate. In the medical it is also a supply crate. The supply crate will restore the players last arsenal loadout, presumably with a timed hold object counter like the flag capture has. The (object that I haven't decided) in the medical house would restore a player's health via addaction, presumably with a hold object counter like the flag capture has. Why a marker? A, to visually ID who owns a given post on the player map and gps, and B, to retrieve who owns the flag --> so that the addactions/hold actions can be restricted to only work with the side that currently "owns" the flag/marker. The post will also contain a respawn point, llso only available to the side holding the flag, which on mission start would ideally be empty (so no spawn at towerpost), instead of a white flag (I couldn't figure out out to default an empty flagpole in my original init). Both the medical and rearm features will have a 5 minute timeout for that player, to prevent pumping and dumping. In addition, there are 3 triggers, each with a veh repair script. Those will be side restricted as well.

I've gotten as far as getting my original solution to work with loadouts, but there is no timer yet. 


Mission File
 

Share this post


Link to post
Share on other sites
1 hour ago, Northup said:

Copy and paste the flag and marker in the 3d editor. Start the mission and capture both flags.

I presume you are talking about my test mission here. Check the FlagPoles init, have you updated the marker name in the call to NUP_fnc_initFlag for the copy and pasted flag?

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, Larrow said:

I presume you are talking about my test mission here. Check the FlagPoles init, have you updated the marker name in the call to NUP_fnc_initFlag for the copy and pasted flag?

I am an idiot. Works fine. I shouldn't stay up so late.

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

×