Jump to content

Recommended Posts

Hello again, community.

I'm trying to make persistent triggers using profileNamespace, so their state would be saved upon mission restart.

 

Here's what I've got to this minute:

private ["_debug","_resetTriggers","_persTriggers","_actTriggers","_triggersLoaded"];

_persTriggers = [trigger_01,trigger_02]; 
_resetTriggers = false;
_debug = true;

//Define variable if launched for the first time or reset
if ((isNil "triggers_var") || (_resetTriggers)) then {
  _actTriggers = [];
  profileNamespace setVariable ["triggers_var",[]];
  saveProfileNamespace;
};

//Loading activated triggers and activates them again
_actTriggers = profileNamespace getVariable "triggers_var";
{_x setTriggerActivation ["ANYPLAYER","NOT PRESENT",false]} forEach _actTriggers;
if (_debug) then {hint format ["Persistent triggers:\n%1\n\nActivated triggers:\n%2\n\ntriggers_var:\n%3",_persTriggers,_actTriggers,triggers_var];};

//Checking in any of the persitent triggers was activated
while {true} do {
  UIsleep 2;
  {
    if (triggerActivated _x && !(_x in _actTriggers)) then {
      _actTriggers pushBackUnique _x;
      profileNamespace setVariable ["triggers_var",_actTriggers];
      saveProfileNamespace;
      if (_debug) then {hint format ["Persistent triggers:\n%1\n\nActivated triggers:\n%2\n\ntriggers_var:\n%3\n\nLast activated:\n%4",_persTriggers,_actTriggers,triggers_var,_x];};
      
    };
  } forEach _persTriggers;
};

No matter what I do It returns undefined expression in "triggers_var".

If I change profileNamespace to missionNamespace - it works fine, so my guess is that I somehow cannot write to profileNamespace.

filePatching is on, BattleEye disabled - no changes.

 

Any help or ideas appreciated, I'm really stuck here.

Share this post


Link to post
Share on other sites

You cannot save an object by its object reference and expect it to be the same on mission reload.

Instead save them by their vehicleVarName.

#define DEBUG	true
#define RESET	false

//Only on server, do not want multiple clients setting persistance( possibly different states ) 
if !( isServer ) exitWith {};

private _persTriggers = ["trigger_01","trigger_02"]; 

//Reset triggers
if (RESET) then {
	profileNamespace setVariable ["actTriggers_var",nil];
	saveProfileNamespace;
};

//Get activated triggers
TAG_actTriggers = profileNamespace getVariable ["actTriggers_var",[]];

TAG_fnc_updateActivatedTriggers = {
	params[ "_trig" ];
	
	//Store the triggers vehicleVarName
	private _nul = TAG_actTriggers pushBackUnique vehicleVarName _trig;
	profileNamespace setVariable[ 'actTriggers_var', TAG_actTriggers ];
	saveProfileNamespace;
	
	if ( DEBUG ) then {
		hint format[ "Persistent trig: %1 was activated and stored", vehicleVarName _trig ];
	};
};

{
	//Get reference to trigger object from it vehicleVarName
	_trig = missionNamespace getVariable [ _x, objNull ];
	
	//If we found an object AND it is a trigger
	if ( !isNull _trig && { typeOf _trig isKindOf "EmptyDetector" } ) then {
		
		//Get the triggers statements
		_statements = triggerStatements _trig;
		
		//If the trigger was previously activated
		if ( _x in TAG_actTriggers ) then {
			//Set its condition to true( causing it to activate ) or whatever you need to do 
			_statements set[ 0, "true" ];
		}else{
			//Else, Add code to its onActivation to call TAG_fnc_updateActivatedTriggers
			_statements set[ 1, "[ thisTrigger ] call TAG_fnc_updateActivatedTriggers;" + ( _statements select 1 ) ];
		};
		
		//Update triggers statements
		//Remember this is only effecting the servers trigger statement, command is AG EL
		//If this needs to be done globally then you will need to either...
		//1. RemoteExec this command, with JIP
		//2. ( If statement has a lot of code )
		//	Think about remoteExec'ing a function to change a specific part of the statement, with JIP
		_trig setTriggerStatements _statements;
	};
}forEach _persTriggers;

if (DEBUG) then {
	hint format ["Persistent triggers:\n%1\n\nActivated triggers:\n%2",_persTriggers,TAG_actTriggers];
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Appreciate the help, Larrow.

 

For some reason code that you've posted doesn't work for me. Triggers are activating (there's a audio beep for that), but Activated triggers still shows []

I've added [ thisTrigger ] call TAG_fnc_updateActiveTriggers; to each trigger on Activation statement. Anything else I need for this to work?

Share this post


Link to post
Share on other sites
5 minutes ago, bl2ck dog said:

I've added [ thisTrigger ] call TAG_fnc_updateActiveTriggers; to each trigger on Activation statement. Anything else I need for this to work?

No need to add anything to your triggers activation code, the script already does that.

Recheck code, I noticed a mistake (function name in trigger statement) shortly after posting and updated code.

  • 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

×