r/armadev • u/commandercasserole • 3h ago
Arma 3 Help with an almost functioning radiation zone script
I feel like I'm so close to this and yet a million miles away. I'm deep in the sunk cost fallacy and don't want to give up unless I can't get help...
I've made a single-player script for my scenario that works as a type of radiation/toxic/hazardous zone. I'm not a programmer and it was mostly cobbled together from other people's ideas.
It runs via script (technically a function now) in a trigger area, whilst the player is in the area they take damage over time, there are two types of screen effects, and a geiger counter noise plays. When they leave the trigger area, it stops.
There's a second aspect that I managed to get working as well. The the player's goggles are of certain types (i.e. they're wearing a gas mask) they take no damage, the geiger counter noise stops, one of the screen effects stops but the other one keeps going to let they player know they are in a dangerous area, but they are not being affected right now. Also, a timer runs, and if it reaches a certain number, their gas mask is destroyed and all the other effects kick in.
I found a thing from Alias scripts rad zone about having unprotected AI flee the area, which works too!
All runs perfectly great... or at least functional. Now the problem is I can only get this to affect the player. I want it to damage ai units when they enter the trigger area as well but everything I try doesn't work.
I can get it to damage everyone depending on whether they are wearing a mask, but I can't get any of the other effects to trigger ONLY for the player. If anyone enters the area, the screen effects play for the player, or I can take the effects out (where I currently am).
It runs on a while loop, and it's my understanding I can't have two while loops running simultaneously in a script. So, I'm trying to incorporate it all into one loop, which means I need to enter some form of sub-check within the existing checks. I tried this using an IF statement within the while loop to check if the unit is player, that hasn't worked so I removed it.
This is currently where I'm at after separating it back out (two while loops, 2nd one doesn't work, only damages units but does not do other effects, note I've added comments but incorrectly, they're not in the script):
params ["_unit", "_trigger"];
_colourEffect = ppEffectCreate ["ColorCorrections",1];
_filmEffect = ppEffectCreate ["FilmGrain", 2];
_dangerAI = allUnits inAreaArray _Trigger;
Pdamage = 0;
Pstamina = 60;
radtime = 0;
while { triggeractivated _Trigger } do { _dangerAI apply {
\\gasmask check\\ {if (goggles _x in headband) then {} else {
\\no gasmask damage\\ _x setdamage ( damage _x ) + 0.01;
\\ai flee area code\\ //[str _dangerAI] remoteExec ["hint",0,true];
_reldir = [_x, getpos _trigger] call BIS_fnc_dirTo;
_fct = [30,-30] call BIS_fnc_selectRandom;
if (_reldir<180) then {_op_dir=_reldir+180 +_fct} else {_op_dir=_reldir-180+_fct};
_x setSkill ["commanding", 1];
_x doMove ([getposATL _x,250, 225] call BIS_fnc_relPos);
};
\\apply to everone in area\\ } foreach _dangerAI;
}; sleep (1 + random 1.2); };
\\2nd while loop, player only effects that do not work with the above\\
\\check if player\\ while { _unit inArea _Trigger} do {
if (goggles _unit in headband) then
{
irad = false; publicVariable "irad";
radtime = radtime + 1;
_filmEffect ppEffectAdjust \[0.1, -1, 0.1, 0.05, 2, false\];
_filmEffect ppEffectCommit 1;
_filmEffect ppEffectEnable TRUE;
}
else
{
irad = true; publicVariable "irad";
radtime = radtime + 1;
_unit setStamina Pstamina;
Pstamina = Pstamina - 2;
playsound \["geiger", false, (0 + random 0.4)\];
_colourEffect ppEffectAdjust \[1, 0.4, 0, \[0, 0, 0, 0\], \[1, 1, 1, 0\], \[1, 1, 1, 0\]\];
_colourEffect ppEffectCommit 1;
_colourEffect ppEffectEnable TRUE;
_filmEffect ppEffectAdjust \[0.1, -1, 0.1, 0.05, 2, false\];
_filmEffect ppEffectCommit 1;
_filmEffect ppEffectEnable TRUE;
};
sleep (1 + random 1.2);
if (radtime >= 45) then { removeGoggles _unit };
};\\things that happen at the end, end screen effects, reset timer\\
ppEffectDestroy _colourEffect;
ppEffectDestroy _filmEffect;
radtime = 0;
NOTE: headband is variable defined elsewhere (list of gasmasks), _unit and _trigger are fed in from the Eden trigger [player, thisTrigger]