Jump to content
mcnools

Making an enemy unit go unconsious when hit (ACE 3)

Recommended Posts

Hello, I'm working on a little mission for my group where we are supposed to bring in a very hostile enemy leader, I don't want him to be the kind of guy that surrenders so the idea is to force us to shoot him and then stabilize him and bring him back to our base alive for more medical attention.  Now to my problem: Is there any way to enable "prevent instant death" and the whole unconsiousness etc. for a specific opfor non-player unit?

to be more specific, right now ace medical is just enabled for players and I'd prefer to keep it that way except for that one unit.

 

One piece of advice I got was to make a script that activates when the unit is hit while having "this setdamage false" in the units init so it doesn't die, and then when it gets hit use the "ace_medical_fnc_setUnconscious" function to make him unconsious, but unfortunately I have no idea how to do this. Any advice?

 

 

Edit:  Cyrus over at the ace public slack helped me out a bit, this code in init.sqf or initserver.sqf if dedicated seems to do the trick (if the unit is named bob):

 

Quote

dontdieEH = bob addEventHandler ["Hit", {

   params ["_unit"];

   [_unit, true, 900,true] call ace_medical_fnc_setUnconscious;

   _unit allowDamage true;

}];

 

Share this post


Link to post
Share on other sites
HIV addEventHandler ["Hit", 
                     	{execVM "hivHit.sqf"}
                    ]
};

Maybe try that and then in "hivHit.sqf" add 

[hiv, 100, true] call ace_medical_fnc_setUnconscious;

I haven't tested but I think it'd work? 

  • Like 1

Share this post


Link to post
Share on other sites

You can limit the damage and make the unit falls unconscious (like I did here in broader scale).

 

The EH handleDamage can help you:

 

Basically, say bob is your unit:

 

bob addEventHandler ["handleDamage", {
    params ["_unit","","_dam"];
    if !(_unit getVariable ["uncsious",false]) then {
          _unit setVariable ["uncsious",true,true];
          [_unit,''] remoteExec ['playMoveNow'];
          _unit setUnconscious true;
      };
      _dam min 0.86;
  }];

 

No clue if ACE compatible. I don't use it.

You can have some extra lines to add for covering all situations (bob in car, plane...)

  • Like 3

Share this post


Link to post
Share on other sites

I will give it a try! thanks guys

Share this post


Link to post
Share on other sites
4 hours ago, Spatsiba said:

HIV addEventHandler ["Hit", 
                     	{execVM "hivHit.sqf"}
                    ]
};

 

Where should I put this part? When I put it in the init.sqf I get this error message:

 

Vez4qE8.jpg

 

Also, if I try to just execute the script with a radio trigger I get this:

 

oNrzAvS.jpg

 

so I suppose it doesn't really work either way :(

 

 

 

pierremgi's script made him fall down and sqiqqle around right away when I put it into the init.sqf, unfortunately it's not ace-compatible so we can't drag him around etc. in that position.

Share this post


Link to post
Share on other sites
1 hour ago, mcnools said:

I get this error message

"Missing semicolon" yeah.. How about you add the semicolon then?

 

HIV addEventHandler ["Hit", {execVM "hivHit.sqf"}];

 

6 hours ago, Spatsiba said:

[hiv, 100, true] call ace_medical_fnc_setUnconscious;

That won't work. Second parameter is a boolean, not a number.
https://github.com/acemod/ACE3/blob/44912253af6350fefb8755c5e34fd89fcc48c541/addons/medical/functions/fnc_setUnconscious.sqf

 

  • Haha 1

Share this post


Link to post
Share on other sites

If you want the unit to surrender when a player is close I made a function that does that, players have to get close enough but in the meantime the unit stays alive and kicking, it's not exactly what you are trying to achieve but it might interest you in that situation:
 

/*
Function name:MRH_fnc_VipSurrender
Author: Mr H.
Description: This function makes a unit surrender when a player comes near enough. Trigger is attached to the unit so this will work even on moving units, trigger is 2 meters high, so if the unit is on the upper floor of a building players will need to reach the same height. Triggers are created globaly, therefore the code will be called globally. Unit (parameter 0) is passed to the code.
Return value: None
Public: Yes
Parameters:
0 - <OBJECT> - Unit that will surrender
1 - <NUMBER> - Distance from the unit under which they will surrender
3 - <STRING> - Message to display when unit is captured, will be displayed in global chat, said by the unit.
4 - <CODE> -Optional code to execute, _unit is passed as a parameter, code must be stated between {}
Example(s):
[this,5,"I surrender!"] call MRH_fnc_VipSurrender;
or
[this,10,"I will never surrender!", {(_this select 0) setDamage 1; hint str _this;}] call MRH_fnc_VipSurrender;
*/


params ["_unit","_diameter","_message","_code"];
_diameter = _diameter /2;

_trg = createTrigger ["EmptyDetector", getPosASL _unit];
if (isNil "_code") then {_code ={};};
missionNamespace setVariable ["MRH_Strigger_" + (str _trg),[_unit,_message, _code], true];


_trg setTriggerArea [_diameter, _diameter, 0, false,2];
_trg setTriggerActivation ["ANYPLAYER", "PRESENT", false];
_trg attachTo [_unit,[0,0,0]];
_trg setTriggerStatements ["this", 
"
_data = missionNameSpace getVariable ('MRH_Strigger_' + str thisTrigger);
_unit = _data select 0;
_message = _data select 1;
_code = _data select 2;
_unit setCaptive true;
_unit playMove 'ApanPknlMstpSnonWnonDnon_G03';
_unit globalChat _message;
[_unit] spawn _code;
"
, ""];

 

  • Like 3

Share this post


Link to post
Share on other sites

Thank you very much Mr H.!  While it's not what I'm looking for in this particular mission I do have another mission further into the campaign where I need a script exactly like this. :)

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

×