Jump to content
Sign in to follow this  
YO

hit by explosion

Recommended Posts

Is there any way I can check if a player has been damage by an explosion?, let's say by grenades or bombs... I tried hit EH but it only returns the owner of the object that caused the damage, maybe a quick search for nearestObjects triggered by that EH?

Any help is much appreciated

Share this post


Link to post
Share on other sites

If the explosion is close and strong enough, dammaged EH will trigger several times within one frame (max 4 times, once for each selection, ie "head_hit","legs","hands" and "body"). If you count the number of times it triggered, you can judge from there. It's not a reliable enough way though, because powerful projectiles, even without indirect damage, will also trigger dammaged EH several times. The only reliable, albeit a bit CPU-heavy, way i know of is tracking each explosive round through fired EH and use nearestobjects to detect affected soldiers when it reaches the destination.

You can also try detecting craters near the hit soldier, but not sure how to separate recent ones from the old ones.

Share this post


Link to post
Share on other sites

thx for you answer, I'll try that dammaged EH, seems the most reasonable to me. I'd thought about tracking constanlty nearest objects to player until a grenade or schatel is found but this seems even more cpu unfriendly than tracking thrown grenades via fired EH plus the effect i'm searching really doesn't deserve it, and should be present all game long. I'll take a look at this, thx mate.

Share this post


Link to post
Share on other sites

I can't make this working so I'd really appreciate any clues you can provide. Here my results till now:

First, dammaged EH only triggers when a section has been damaged (damage texture displayed) so sometimes soldier is hit by grenade, wich triggers hit EH, but as none of the sections are dammaged enough, dammaged EH doesn't activate. Also, as Q1184 said, big impacts may cause damage to more than one section, and also things like jumping out from a moving vehicle, so it's definitively not a reliable way to check that matter.

Also my search for nearestObjects with types "HandGrenade" or "HandGrenadeMuzzle" (or timed version) returns no object. That's the code I'm trying:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {true} do

{

while {alive player} do

{

sleep 0.25;

_n = nearestObjects [player, ["HandGrenade", "HandGrenadeTimed"], 25];

if (count _n > 0) then

{

_g = _n select 0;

waitUntil {!alive _g};

// assuming we're hit by a grenade

};

};

while {!alive player} do

{

sleep 1;

};

};

And for what Q1184 said, tracking explosives via firedEH, I'm not sure how shoud be done, I imagine that I shoud assign that EH to every unit in mission and on script checking distance to player, make a little maths to calculate if it aims to the player... but I get lost here.

Anyway, I think I get stucked cause of missunderstanding of the fired EH... does any of the parameters refers to the bullet itself and not the classname?

I wonder how XAM or ACE mods do to play that wheezing sound when you're hit by a grenade, I imagine it's some addon feature. Does XEH handle such stuff? Anyway, I wanted it for an addon-free mission.

Ok, I stop writing, I'll still trying to figure out a way to detect explosion impacts, maybe as the guy above suggested, tracking craters near to the player.

Thanks for your time.

PD: why the hell hit EH doesn't return the bullet that caused the damage!?

Share this post


Link to post
Share on other sites

G'day, Not sure if this will help you but it is basicaly what you asked for.

I addapted my old teammate SurdistPriest's nearExplosion.sqf, which gave a few effects and played a sound. I have added/removed a bit from his original work to do the same thing your after, its a function file so is called by the init.sqf and dosent need a damaged,hit or fired EH. But for some reason once the player is dead it wont start again on Respawn, so I had to add a Killed EH on the player to recall the function. So if any one can fix this problem it could be Better.

Any way add this to your init

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player addEventHandler ["killed", {handle = [(_this select 0)] execVM "readdfunction.sqf"}];

if (alive player and (canStand player)) then

{

[20] call compile (preprocessFileLineNumbers "hit.sqf")

};

The [20] part is the distance the projectile is from player, for the script to run.

hit.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_d = _this select 0;

Hit_list = //this function detects explosions near the player of certain ammo

 //and starts the effect script

{

private["_shell"];

_shell = _this select 0;

//_shell is a string containing the ammo name

_projectile = nearestObject [player, _shell];

while {(_projectile distance player) < _d} do

{

sleep 0.01;

//_projectile = nearestObject [player, _shell];

if (isnull _projectile) then

{

if (alive player) then

{

sleep 0.1;

    player sideChat format["Wounded by a, %1",_shell];

    player say "wheeze";

  };

if (not(alive player)) then

{

sleep 0.1;

    player sideChat format["Killed by a, %1",_shell];

  };

}; //if

}; //while

}; //function Hit_list

while {alive player} do

{

sleep 0.01;

//call the function ones for each type of ammo

["RocketCore"] call Hit_list;

["MissileCore"] call Hit_list;

["ShellCore"] call Hit_list;

["MineCore"] call Hit_list;

["TimeBombCore"] call Hit_list;

["G_40mm_HE"] call Hit_list;

["G_30mm_HE"] call Hit_list;

["G_40mm_HE_6G30"] call Hit_list;

["GrenadeHandTimed"] call Hit_list;

["GrenadeHand"] call Hit_list;

["B_556x45_Ball"] call Hit_list;

["B_556x45_SD "] call Hit_list;

["B_9x19_Ball"] call Hit_list;

["B_9x19_SD"] call Hit_list;

["B_762x51_Ball"] call Hit_list;

["B_127x99_Ball_noTracer"] call Hit_list;

["B_545x39_Ball"] call Hit_list;

["B_545x39_SD"] call Hit_list;

["B_762x54_Ball"] call Hit_list;

["B_762x54_noTracer"] call Hit_list;

["B_127x108_Ball"] call Hit_list;

["B_9x18_Ball"] call Hit_list;

["B_9x18_SD"] call Hit_list;

["B_127x107_Ball"] call Hit_list;

["B_127x99_Ball"] call Hit_list;

["FuelExplosion"] call Hit_list;

}; //while alive player

exit;

I still have a few bullet types to add ie;- twin vikers and a few vehicle mounted MG.

you need this to restart the function.

readdfunction.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">waitUntil {alive player};

if (alive player and (canStand player)) then

{

[20] call compile (preprocessFileLineNumbers "hit.sqf");

};

Now you just need to create a folder called sounds and create a .ogg soundfile and save as wheeze.ogg and add it to your new folder, then define the sound and source in your description file

Description.ext

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class CfgSounds

{

// List of sounds (.ogg files without the .ogg extension)

sounds[] = {wheeze};

// Definition for each sound

class wheeze

{

name = "wheeze";

sound[] = {"\sounds\wheeze.ogg", db-5, 1.0};

titles[] = {};

};

};

Hope this helps.

Odin

Share this post


Link to post
Share on other sites

lol .... thx guy, haven't tested it yet but I belive you if you say this works, although it seems it really abuses from cpu as it's calling 26 scripts every 0.01 seconds! I'm not sure how it will perform in a long term game. Anyway, I think I can extract some good stuff from here. I'm gonna try to build up something better optimised from that and I'll post my results.

Note: to keep that script effect constantly simply nest the "while alive player" loop inside another "while true" loop, like this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {true} do

{

waitUntil {alive player};

while {alive player} do

{

sleep 0.01;

//call the function ones for each type of ammo

["RocketCore"] call Hit_list;

["MissileCore"] call Hit_list;

["ShellCore"] call Hit_list;

["MineCore"] call Hit_list;

["TimeBombCore"] call Hit_list;

["G_40mm_HE"] call Hit_list;

["G_30mm_HE"] call Hit_list;

// etc.

};

};

and also, don't call that script from init, better spawn it, as the call command will wait until that script has ended, wich will never happen.

Share this post


Link to post
Share on other sites

hi again,

I've been playing for a few days with this and now I think I can share my results as it seems I've find an enough reliable and cpu affordable way to check when a player is hit by an explosion. I've to admit that at first I was scared of the massive code calling in Odin's script, but in my tests it seems to perform ok, and it is effective in its proposal, so I only adapted it a little bit for my purposes. Thank you Odin!!

here's the code, it only need a calling from init, no arguments nedeed:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_hit_list =

{

private["_shell", "_d", "_dam"]; // needed?

_shell = _this select 0;

_d = _this select 1;

_dam = damage player;

_projectile = nearestObject [player, _shell];

while {(_projectile distance player) < _d} do

{

sleep 0.15;

if (isnull _projectile) then

{

//sleep 0.1;

if (alive player) then

{

//playSound "wheeze";

//player sideChat format ["Wounded by a %1",_shell];

[_dam, _shell] spawn Hit_effect;

}

else

{

//player sideChat format ["Killed by a %1",_shell];

};

};

_dam = damage player;

};

};

Hit_effect =

{

private ["_dam", "_shell", "_imp"];

_dam = _this select 0;

_shell = _this select 1;

_imp = (damage player) - _dam;

//titleText [format ["Impact: %1", _imp], "plain"];

if (_imp > 0.02) then // we have been damaged by the explosion

{

//player sideChat format ["Wounded by a %1",_shell];

playSound "wheeze";

// + desired effects

};

};

while {true} do

{

sleep 0.5;

while {alive player AND !(vehicle player isKindOf "Tank")} do

{

sleep 0.01;

["ShellCore", 20] call _hit_list;

["RocketCore", 20] call _hit_list;

["MissileCore", 20] call _hit_list;

["G_40mm_HE", 16] call _hit_list;

["G_30mm_HE", 16] call _hit_list;

["G_40mm_HE_6G30", 16] call _hit_list;

["MineCore", 16] call _hit_list;

["TimeBombCore",30] call _hit_list;

["Grenade", 20] call _hit_list;

};

};

exit;

Now it also checks if the explosion has damaged us wich was basicly what I was looking for, although sometimes it fails and consider an impact of 0, but it's not really often that it happens, and 0.15 sec seems enought in most of cases for the explosion to occur and the shell to disapear. So by now it's done with this script, having to test performance in long games, anyway any suggestion and improvement provided is more than welcome.

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
Sign in to follow this  

×