Jump to content
Jonssonsson

Script of infantry units to take damage inside an area?

Recommended Posts

Hi!

I've been making missions for Arma 3 for a couple of years now and I can usually find answers to my scripting questions by searching this forum or googling. However, I have not yet found a solution to my current problem yet.

 

I'm trying to create an area which would make any infantry unit take 0.1 damage every 5 seconds if the unit stays inside the area. If the unit leaves the area they should stop taking damage. This should apply to ALL infantry units (including but not limited to players) in my MP mission.

 

I think I managed to make mrcurry's script posted in this old thread work for player controlled units using a trigger with my specified area size and "Any Player" activation, and setting the trigger as repeatable. However, I cannot seem to be able to make this work for AI units. I'm just not good enough at scripting. Any idea how I might do that? And to make it even more complex, how can I make the trigger activate for only units that are on foot (i.e., not in any vehicle)?

Share this post


Link to post
Share on other sites

You just have to use the trigger as an area (and that works also with a marker area).

So for a trigger, set to: none,  none,   NOT server only, not Repeatable (useless),   condition : TRUE (so the on activation code fires at start):
on act. field:
 

thisTrigger spawn {
  params ["_trig","_allUnits"];
  while {true} do {
    _allUnits = (entities [["caManbase"],[],true,true] select {_x inArea _trig && local _x});
    {_x setDamage (damage _x + 0.1)} count _allUnits;
    sleep 5;
  };
};

 

entities [["caManbase"],[],true,true]  works also for units in vehicle.
For on foot only, just:

entities [["caManbase"],[],false,true]
 

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks pierremgi! You are a godsend!

 

The script seems to work like I wanted. I realized that I would also like to add a sound effect coming from the object each time it takes damage while in the area. I tried the following:

thisTrigger spawn {
  params ["_trig","_allUnits"];
  while {true} do {
    _allUnits = (entities [["caManbase"],[],true,true] select {_x inArea _trig && local _x});
    {_x setDamage (damage _x + 0.1)} count _allUnits;
    {_x say3D "Sound8"} count _allUnits;
    sleep 5;
  };
};

The script seems to work despite giving a script error in game:

 

...{_x |#|say3D "Sound8"} count _allunits;

sle....

Error tybe object, expected Bool

 

Any idea what is the problem?

Share this post


Link to post
Share on other sites

{_x say3D "Sound8"} forEach _allunits;

 

say3D returns a value since v2.00  so count is not adapted here. Use forEach  instead.

NOTE: Not sure it's a great idea, applying a say3D on each wounded units at the time time...

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks again!

 

I think this works just fine for the intended purpose, at least what I was able to test just by myself. I have a poisonous area in my mission which is to be avoided and if you go in on foot, you start taking damage and the units make a small coughing sound. If there are multiple units inside the area the coughing sounds are all played at the same time, which might not be ideal, but the the volume of the sound is quite low and I set the maxDistance to 20m, so it works well enough in my opinion.

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

×