Jump to content
Corleone Vito

[MP]How to delete dead AI bodies but keep dead player bodies in a while loop?

Recommended Posts

My scripts:

[] spawn {

    while{true}do{

       {if((!alive _x) && (_x != player)) then{deleteVehicle _X}}forEach allDeadMen;

       

        sleep 30;};

    };

 

When I entered the game, the dead AI  bodies were indeed deleted within 30 seconds, but the dead player bodies were also deleted. I'm thinking that maybe when the player dies (or when they respawn), their body is no longer considered as "player", so it is being deleted along with allDeadMen in the _x ?

 

Share this post


Link to post
Share on other sites

You Should look at the "killed" eventhandler:
 

Quote

 

Triggered when the unit is killed.

Be careful when the killer has been a vehicle. For most cases the reference of the vehicle is the same as the effectiveCommander, but not always.

this addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; }];

unit: Object - object the event handler is assigned to

killer: Object - object that killed the unit. Contains the unit itself in case of collisions

1.66 instigator: Object - person who pulled the trigger

1.68 useEffects: Boolean - same as useEffects in setDamage alt syntax

 

 

  • Like 1

Share this post


Link to post
Share on other sites
_x != player

isn't gonna work, try this instead:

!isPlayer [_x]

 

Share this post


Link to post
Share on other sites

just:

addMissionEventHandler ["entityKilled", {

  params ["_killed"];

  if ( _killed isKindOf "CAManBase") then {deleteVehicle _killed}

}];

 

Nothing more needed. Player corpse will remain.

Note: you can add :     && !(_killed in playableUnits)    in condition , letting playable units respawn in MP, without deleting their corpse.

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

×