Comrades in Arms Discussion Board

Full Version: setUnconscious for ai
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
im working on a simple script which when ai get shoot , there is a chance they move to Unconscious state, however its fine with single playerand server but  Unconscious animation not showing animation on server, dedicated.
here is demo mission
https://www.mediafire.com/?7d8cx9oxlhhxisa

singleplayer
[Image: w1u4jb1n2tardq96g.jpg]

server
[Image: s9igu5b6dkb9oo06g.jpg]

i hope somebody can find a y and fix it 

Haven't looked at the code yet, but almost all of the animation functions are G-L, meaning their argument (the unit) can be global but the effect is only local.

In essence, you need to run it on all clients, using remoteExec.
Ok, found a solution.
Share a demo mission here if somebody may need it and want to use it.

http://www.mediafire.com/file/8yz3oj35mr...os3.VR.rar

init.sqf

Code:
fnc_injured = {
    _unit = _this select 0;
   _unit removeAllMPEventHandlers "MPHit";
[ _unit ] remoteExec [ "TAG_fnc_setunconscious", 2 ];

    sleep 3;


_anim = [
"UnconsciousReviveArms_A","UnconsciousReviveArms_B","UnconsciousReviveArms_C","UnconsciousReviveBody_A",
"UnconsciousReviveBody_B","UnconsciousReviveDefault_A","UnconsciousReviveDefault_B","UnconsciousReviveHead_A",
"UnconsciousReviveHead_B","UnconsciousReviveHead_C","UnconsciousReviveLegs_A","UnconsciousReviveLegs_B"
] call bis_fnc_selectRandom;

[[[_unit,_anim],"animation.sqf"],"BIS_fnc_execVM",true,false] call BIS_fnc_MP;

while {(true)} do {

sleep (30 + random 60);

_ls = lifeState _unit;

if (_ls != "INCAPACITATED") exitWith {};
    
_sound = [
"pain1", "pain2", "pain3", "pain4", "pain5", "pain6", "pain7", "pain8", "pain9", "pain10", "pain11", "pain12", "pain13"
] call BIS_fnc_selectRandom;

_unit say3D [_sound, 100, 1];

sleep (60 + random 60);
    
};
    };




initserver.sqf

Code:
TAG_fnc_setunconscious = {
    params[ "_unit" ];
[ _unit, true ] remoteExec [ "setUnconscious", _unit ];
    
};

_null = [] execvm "injured.sqf";



injured,sqf
Code:
sleep 3;

{
    if (side _x == east) then {
        
         if (_x isKindOf "Man") then
           {
                _x removeAllMPEventHandlers "MPHit";
                
        call compile format["
            %1 addMPEventHandler ['MPHit',{
                if (vehicle %1 == %1) then {
                    _rand = random 100;
                    if (_rand < 35) then {
                        [%1] spawn fnc_injured;
                    };
                };
            }]
        ",[_x] call BIS_fnc_objectVar];
    };
    
    };
    
} forEach allUnits;
animation.sqf
Code:
_unit = _this select 0;
_anim = _this select 1;

   _unit disableAI "TARGET";
   _unit disableAI "AUTOTARGET";
   _unit disableAI "MOVE";
   _unit disableAI "TEAMSWITCH";
   _unit disableAI "FSM";
   _unit disableAI "AIMINGERROR";
   _unit disableAI "SUPPRESSION";
   _unit disableAI "COVER";
   _unit disableAI "AUTOCOMBAT";
   _unit disableAI "PATH";
    
    
    
while {true} do {
        
_ls = lifeState _unit;
if (_ls != "INCAPACITATED") exitWith {};


_unit playMove _anim;
    

sleep 5;    
    
};