Jump to content
boriz

How to auto-heal soldiers inside a trigger?

Recommended Posts

*SOLVED!*

 

Hello good people!

 

I consider myself to be an experienced scripter, but I still sometimes come up with some simple features which happen to be much more difficult to realize than they should be. This is one of them.

 

I want to create a trigger which reacts to BLUFOR units. When any such unit enters this trigger, it gets auto-healed. If this unit is a player, he gets notified about it through the TitleText [...] command.
When this unit stays inside of this trigger and receives damage, it also gets auto-healed.

After leaving this trigger, the unit stops being auto-healed.

All of this must work in multiplayer where I have multiple triggers like this.

What is the simplest way to achieve this?

Share this post


Link to post
Share on other sites

I would place in such locations an object,

medical hemt , medical tent or something like that

and execute on each  heal script.

if (isServer) then {
[this, 20, 0.05, 2] execVM "heal.sqf";
};

Where:

this - is object

20 -is radius

0.05 -is recovered heal

2 -is time in sec between heal recover runs

 

 

heal.sqf

params ["_obj","_radius","_healPerSleep","_sleepTime", "_damage"];

    while {alive _obj} do
    {
        {
            if (alive _x) then
            {
                _damage = damage _x;
                _damage = _damage - _healPerSleep;
                if (_damage < 0) then
                {
                    _damage = 0;
                };
                _x setDamage _damage;
            };
        }
        forEach ((getPos _obj) nearEntities [["Man"], _radius]);
        sleep _sleepTime;
    };

  • Like 1

Share this post


Link to post
Share on other sites

 

I would place in such locations an object, [...]

 

Thanks!

This is almost what I need. The problem is that I want to use a trigger to detect nearby objects. That way I can shape it just as I need and position it precisely in such way that its edges end where I want them to be.

Using an object with some invisible area of effect is very inconvenient for me in the Eden editor. Plus, it limits me to using the circular shape.

To achieve this, I am thinking about using thisList array in triggers. It should contain all compatible insiders who I can heal. However, AFAIK that array is accessible only in the On Activation event, and that is called only once when the first unit enters it. I think it would be best if this trigger would call On Activate event every second when someone is inside of it, but how do I achieve that?

Share this post


Link to post
Share on other sites

Finally I've found a simple way to hack this into what I want.

1) Insert this line somewhere in the Init.sqf: IsHealing = false;
2) Create a trigger and set it listen to the type of unit you want to
3) In the Condition field, add: this  &&  not IsHealing
4) In the On Activation field add: {_x spawn YourCustomHealUnitScript} forEach thisList;  IsHealing = true;
5) In the On Deactivation add: IsHealing = false;

Now the trigger activates every second when a desired unit type is inside of it. It is not a very flexible way of doing this feature, but it is just what I need right now. I have yet to test it in multiplayer, but it should work.

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

×