Jump to content
beako

How to setFlagTexture and control flag animation

Recommended Posts

HI All,

 

In the BIS_fnc_moduleSector under the parameter setting #6 it describes the following:

 

6: _onOwnerChange (String) - Code as STRING that runs when a sector is captured, code is passed [ _sector, _owner, _old Owner ] in _this, code is also run at sector initialisation _owner will be default owner and _oldOwner will be sideUnknown

 

I'm tried to insert the following code that lowers the _oldOwner  flags then raises the _owner flags but the module seems to override the setFlagTexture function, and I cannot raise the flag once it hits the bottom.

 

	//Code as STRING that is run when sector changes ownership

	[ "_onOwnerChange", "
	
		private _flagsArray = (_this select 0) getVariable 'flags';
		private ['_flagSideTexture'];
		_flagSideTexture = '';	
		switch (_this select 2) do {
			case EAST : {_flagSideTexture = '\A3\Data_F\Flags\Flag_CSAT_CO.paa'};
			case WEST : {_flagSideTexture = '\A3\Data_F\Flags\Flag_NATO_CO.paa'};
			default {_flagSideTexture = '\A3\Data_F\Flags\Flag_white_CO.paa'};			
		};	
	
		{_x setFlagTexture _flagSideTexture} forEach _flagsArray;
		{[_x, flagAnimationPhase _x - 1, 0.1] call BIS_fnc_animateFlag} forEach _flagsArray;
		
		switch (_this select 1) do {
			case EAST : {_flagSideTexture = '\A3\Data_F\Flags\Flag_CSAT_CO.paa'};
			case WEST : {_flagSideTexture = '\A3\Data_F\Flags\Flag_NATO_CO.paa'};
			default {_flagSideTexture = '\A3\Data_F\Flags\Flag_white_CO.paa'};			
		};	
		
		{_x setFlagTexture _flagSideTexture} forEach _flagsArray;	
		{[_x, flagAnimationPhase _x + 1, 0.1] call BIS_fnc_animateFlag} forEach _flagsArray;

	", [ "" ] ],

 

 

Any ideas on how I can do this?

 

Ideally I would like the old owner's flag to lower completely, then replace the texture with the new owner and raise to the top, to match the BIS_fnc_moduleSector vertical bar animation.

 

 

Share this post


Link to post
Share on other sites

I have a flag with a custom sector script which I animate the flag with 

[_area getVariable "flag", _sectorScore/100, 1] call BIS_fnc_animateFlag;

where I've already set the 'flag' variable.... and then change the texture of the flag with

 

 

 

I have spent quite a lot of time on the SectorModule but it didn't quite do what I wanted (can't lock and unlock areas depending on what they are connected to etc) so have made my own script.

 

Hope above may help somehow but to raise the flag I would use

[_area getVariable "flag", 1, 1] call BIS_fnc_animateFlag;

or something similar....

It works well in MP.

 

Atmo

Share this post


Link to post
Share on other sites

Quick example mission. Think that works out right, tried to lock the loops as much as possible and score loop is timed to every sector score update. Should give you something to go off of.

Spoiler


//initServer.sqf

//For all sectors in the mission
{
	[ _x ] spawn {
		params[ "_sector" ];

		//Wait for sector to initialise
		waitUntil { !isNil { _sector getVariable "finalized" } };

		//If it has no flags exit
		if ( _sector getVariable "flags" isEqualTo [] ) exitWith {};

		//Add ownerChnaged SEH
		[ _sector, "ownerChanged", {
			params[ "_sector", "_owner", "_ownerOld" ];

			//Create name for global var based off of sectors name
			_sectorVar = format[ "TAG_flagAnim_%1", _sector call BIS_fnc_objectVar ];

			//If we already have a script running
			if ( !isNil _sectorVar ) then {
				if !( isNull ( missionNamespace getVariable[ _sectorVar, scriptNull ] ) ) then {
					//Kill it
					terminate ( missionNamespace getVariable _sectorVar );
				};
				missionNamespace setVariable[ _sectorVar, nil ];
systemChat "terminating loop";
			};

			//Global var storing scriptHandle
			missionNamespace setVariable[ _sectorVar, ( [ _sector, _owner ] spawn {
				params[ "_sector", "_owner" ];

				_ownerSideID = _owner call BIS_fnc_sideID;
				waitUntil { _sector getVariable "sideScore" select _ownerSideID >= 0.5 };

systemChat "new loop";

				//While the sector is still owned by _owner and not finalised
				while {
					_sector getVariable "sideScore" select _ownerSideID >= 0.5 &&
					!( _sector getVariable[ "finalized", false ] )
				} do {

systemChat "main loop - awaiting contested";

					//Wait for contested
					waitUntil{
						_sector getVariable "sideScore" select _ownerSideID < 0.5 ||
						{ _sector getVariable[ "contested", false ] } ||
						{ _sector getVariable[ "finalized", false ] }
					};

systemChat "contested";

					//Get sector step count( update scores loop count )
					_step = _sector getVariable "step";

					//While the sector is still owned by _owner and contested
					while {
						_sector getVariable "sideScore" select _ownerSideID >= 0.5 &&
						{ _sector getVariable[ "contested", false ] } &&
						{ !( _sector getVariable[ "finalized", false ] ) }
					} do {

						//Get owner side score
						_ownerScore = _sector getVariable "sideScore" select _ownerSideID;

systemChat format[ "Score - %1", _ownerScore ];

						//For each of the sectors flags
						{
							//Update the flags position
							[ _x, linearConversion[ 0.5, 1, _ownerScore, 0, 1 ], true ] call BIS_fnc_animateFlag;
						}forEach ( _sector getVariable "flags" );

						//Wait for sector score update
						waitUntil{
							_sector getVariable "step" > _step ||
							{ _sector getVariable "sideScore" select _ownerSideID < 0.5 } ||
							{ !( _sector getVariable[ "contested", false ] ) } ||
							{ _sector getVariable[ "finalized", false ] }
						};

						_step = _sector getVariable "step";
					};
				};
			})];
		}] call BIS_fnc_addScriptedEventHandler;
	};
}forEach allMissionObjects "moduleSector_F";

You can remove all the systemChats they are only there for debug in editor preview.

TEST MISSION

Edit: Fixed phase and occasional script overlap. Posted code and test mission updated.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks everyone.

 

Larrow this does exactly what I want, I work with this to incorporate into my game.

 

Thanks again, this would have taken me weeks.

 

 

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

×