Jump to content
CptDezusa

If unit get damage then Execute script from trigger

Recommended Posts

Hi i want to start a script in my trigger, when unit from East get damage or hurt, the trigger start my script ?
This is what i got, but one shot they give up.

 

 

Opford - present - once

Condition: this

On Act.

{_x addEventHandler ["Dammaged", {if ((_this select 2) >= 0.9) then {(_this select 0) execVM "hostage\prisonner_ai.sqf"};}];} foreach thislist

 

Share this post


Link to post
Share on other sites

I'm not 100% sure, but I assume that the resulting damage is regarding the "selection" (body part) where the unit is hit. So, instead of checking the damage value returned by the handler, check the damage of the unit. The problem with that is that the unit's damage value is updated after the EH is done (I'm also not 100% sure on that). So a workaround would be to spawn a script inside the EH which does the job:

{
    _x addEventHandler
    [
        "Dammaged",
        {
            _this spawn
            {
                sleep 0.5;
                _unit = _this select 0;
                if (damage _unit >= 0.9) then
                {
                    _unit execVM "hostage\prisonner_ai.sqf"
                };
            };
        }
    ];
} foreach thislist

Also, instead of using the (old) "Dammaged" EH, try the (newer) "HandleDamage" or "Hit" EHs.

Share this post


Link to post
Share on other sites

So this is what i did with my friend. After he was looking at the original script i posted, we found out that it's higher than % of the hit. so we change this  <=  from the original >=

 

 

{_x addEventHandler ["Dammaged", {if ((_this select 2) <= 0.78) then {(_this select 0) execVM "hostage\prisonner_ai.sqf"};}];} foreach thislist

 

 

{
    _x addEventHandler
    
[
        "Dammaged",
        {
            _this spawn
            
{
                sleep 0.5;
                _unit = _this select 0;
                if (damage _unit <= 0.80) then
                {
                    _unit execVM "hostage\prisonner_ai.sqf"
                };
            };
        }
    ];
} foreach thislist

So now this work very good. Thanks :)

 

Share this post


Link to post
Share on other sites

I'm confused. So you execute your prisonner_ai.sqf script IF the units damage is lower than 0.8. But that means, the script is always executed unless you manage to create a damage of 0.8 or more with one shot without killing him, did I get that right?

Share this post


Link to post
Share on other sites

I will try out the: HandleDamage and Hit.

 

 

{
    _x addEventHandler
    
[
        "HandleDamage",
        {
            _this spawn
            
{
                sleep 0.5;
                _unit = _this select 0;
                if (damage _unit <= 0.80) then
                {
                    _unit execVM "hostage\prisonner_ai.sqf"
                };
            };
        }
    ];
} foreach thislist


so then i will change the Dammaged with HandleDamage or Hit ?

Share this post


Link to post
Share on other sites

I'm confused. So you execute your prisonner_ai.sqf script IF the units damage is lower than 0.8. But that means, the script is always executed unless you manage to create a damage of 0.8 or more with one shot without killing him, did I get that right?

As we was looking at it, before the trigger was telling that he got hit than it was over the % that was showing, so can look at the AI started with low life >= 0.85 in life. Now its normal life <= 100% start life,  than get hit, 0.85 the script start.

So to your question, i think so. Higher up more damage he can take, but i'm still trying it out. I am also confused with that.

no it will not execute the script when the mission start, only when the soldier get hit.

 

Share this post


Link to post
Share on other sites

I will try out the: HandleDamage and Hit.

 

so then i will change the Dammaged with HandleDamage or Hit ?

 

You can use the code like that, yes. But you need to be aware of two things:

 

1) The event handler should be executed server side (in a multiplayer mission), because it will only work on the machine where the event handler was added.

2) "HandleDamage" will be executed for every damaged part of the unit. That means, if a granade causes the damage, your prisonner_ai.sqf will be executed many times.

3) "HandleDamage" will continue to trigger even if the unit is already dead.

 

You can read the details here: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage

Share this post


Link to post
Share on other sites

So you're saying that, the event handler will only work in the computer of the gamer who has start the mission, and the other players in the server won't be able to start the script.

 

 

{_x addEventHandler ["Dammaged", {if ((_this select 2) <= 0.78) then {(_this select 0) execVM "hostage\prisonner_ai.sqf"};}];} foreach thislist

This will only be triggered by the game starter of the server. Please don't be that, because i have been on day and night trying to figure this out.

Share this post


Link to post
Share on other sites

Well, in your case, you are lucky, because code inside the trigger statements is always executed on every client connected to the server (including the server itself). Nevertheless, once your trigger is done, any player connecting to the server after the mission has started will not have that event handler. But if no player connects to the server after mission start, it's fine.

Share this post


Link to post
Share on other sites

well that oki. Do you have any other id haw my hostage script, will be activated good under my mission.

My mission is when you are in Afghanistan, and you are looking for over lost brother ho has been taken from the taliban, and on the way in to the mission some soldiers will surrender when the pressure is too high up.

its a coop 30. so need some help, if the trigger only works when all player is starting, need it to be wen players also join the game.

 

Share this post


Link to post
Share on other sites

As we was looking at it, before the trigger was telling that he got hit than it was over the % that was showing, so can look at the AI started with low life >= 0.85 in life. Now its normal life <= 100% start life,  than get hit, 0.85 the script start.

So to your question, i think so. Higher up more damage he can take, but i'm still trying it out. I am also confused with that.

 

So i been trying out this, it's not higher up more damage he can take. So if you love them % to 0.67 he get hit more, but if you shot the AI with a rifle in close range hi will get killed. Shooting him with a pistol close range, hi take 2 till 3 hit then the script start.

 

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

×