Terrance

Adding injury sounds

9 posts in this topic

Hey everyone,

Apologies if this has already been asked. I've done some searching around but I couldn't find anything distinct.

I'm the creator of a workshop scenario which utilises the injury sounds from the DayZ mod, you know, the ridiculous "EOW" sounds, in conjunction with the leg breaking sound.

I've managed to hook that via my intro.sqf in my workshop scenario like so:

intro.sqf

// Is server executing code?
if (isServer) then {
	// Loop through playableUnits.
	{
		// Add hook for MPHit event (injuries).
		_x addMPEventHandler ["MPHit", {[_this] execVM "scripts\hooks\survivorHit.sqf";}];
	} forEach playableUnits;
};

description.ext

// Game sounds.
class CfgSounds
{
	// All sounds defined below.
	sounds[] = {hit1};

	class hit1
	{
		name = "hit1";
		sound[] = {\sounds\injuries\hit1.ogg, 1, 1.0};
		titles[] = {};
	};
};

The script that the hook (survivorHit.sqf) calls, survivorHitVictim.sqf:

// Survivor is hit script
// Play sound upon injury.

// For the sake of logic.
_victim = _this select 0;
_sleepTime = _this select 1;

// Do we exist? Are we alive? Are we in a vehicle?
if (isNull _victim || !alive _victim || vehicle _victim != _victim) exitWith {};

// Array of sounds.
_soundArray = ["hit1", "hit2", "hit3", "hit4", "hit5", "hit6", "hit7", "hit8", "hit9"];

// Select a sound.
_soundToPlay = _soundArray select (floor(random(count _soundArray)));

// Say sound.
_victim say [_soundToPlay, 25];

// Delay so we don't hear rapid pain.
// IF, we are causing self harm.
if (_sleepTime > 0) then {
	sleep _sleepTime;
};

Now this works as-is, both in dedicated & non-dedicated environments for my mission, however, I can't get this to fire in Exile.

There are no script errors, I've chucked a few diag_log's here and there but no bueno :(

If this is something very obvious I apologise, I am rather new to working with Exile, in fact, I only started tinkering with it yesterday.

If more information is required, please let me know and I'd be more than happy to share (also happy to share the entire script when it bloody well works!)

Cheers,

-tez.

Share this post


Link to post
Share on other sites

Do you have a RPT from the server? I don't see any reason why this wouldn't run O.o

Share this post


Link to post
Share on other sites
Advertisement

Hey Taytay :)

I do, but it only references the hook itself being applied itself, the example being:

 

diag_log format ["Hook applied."]

....

{

... insert event handler code here
} forEach playableUnits

 

The 'hook applied' appears in the log, but it appears when I put this within the loop itself, it doesn't appear. Perhaps something to do with the BattlEye filters provided by Exile?

Not sure, just thinking out loud I guess :)

Share this post


Link to post
Share on other sites

@DirtySanchez

You are an absolute bloody legend mate, thank you so much. I'll take your theory and put it to the test.

If it works, I'll share it here :)

Cheers,

-tez.

Share this post


Link to post
Share on other sites

Apologies, I forgot Exile is already handling onHit. Glad you got it sorted, can I close this now? :)

Share this post


Link to post
Share on other sites

Yep! I'm sure if it's already handled via the Exile onHit I should be able to implement this :)
 

I'll admit, I feel a little stupid now! Is there somewhere these functions are documented, for future reference?

Share this post


Link to post
Share on other sites

Funnily enough, the Wiki is being worked on as we speak. All Useful Exile function will be listed :)

 

1 person likes this

Share this post


Link to post
Share on other sites

Great work :)

Thank you both for being so helpful and kind to a newcomer.

I guess if this is to be closed I'll edit my first post with the results when I manage to get some free time on the weekend!

Also, I got to see her live when she came to Melbourne and she was absolutely phenomenal! Offtopic as all hell =)

Share this post


Link to post
Share on other sites

I said I'd share so here's what I have (in it's working state!)

I chose to utilise: ExileClient_object_player_event_onHandleDamage (Figured I'd wanted injury sounds for crashing, falling, etc.. that aren't handled by the standard Hit handler, or so it seems!)

ExileClient_object_player_event_onHandleDamage.sqf:

/**
 * ExileClient_object_player_event_onHandleDamage
 *
 * Exile Mod
 * www.exilemod.com
 * © 2015 Exile Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 */
 
private["_unit","_selectionName","_amountOfDamage","_sourceOfDamage","_typeOfProjectile"];
_unit = _this select 0;
_selectionName = _this select 1;
_amountOfDamage = _this select 2;
_sourceOfDamage = _this select 3;
_typeOfProjectile = _this select 4;

// There's probably a better way of doing this.
if (isNil {_unit getVariable "LastInjuredSound"}) then {
	_unit setVariable ["LastInjuredSound", 0];
};

// Push this for use.
_lastHitTime = _unit getVariable "LastInjuredSound";

// If it's the first time triggering, or the last time the sound was played is greater than 0.005 (To avoid sounds being spammed...) then fire.
if (_lastHitTime == 0 || diag_tickTime - _lastHitTime > 0.005) then {
	// Set new timer to current tick time.
	_unit setVariable ["LastInjuredSound", diag_tickTime];
	
	// Execute script.
	[_unit, _sourceOfDamage, _amountOfDamage] execVM "scripts\hooks\survivorHit.sqf";
};

// Return original damage value back out.
_amountOfDamage

 

In config.cpp:

class CfgExileCustomCode 
{
	/*
		You can overwrite every single file of our code without touching it.
		To do that, add the function name you want to overwrite plus the 
		path to your custom file here. If you wonder how this works, have a
		look at our bootstrap/fn_preInit.sqf function.

		Simply add the following scheme here:

		<Function Name of Exile> = "<New File Name>";

		Example:

		ExileClient_util_fusRoDah = "myaddon\myfunction.sqf";
	*/
	// Emergency fixes for 0.9.41	
	ExileClient_object_player_bambiStateBegin = "ExileClient_object_player_bambiStateBegin.sqf";
	
	// On damage trigger for injury sounds.
	ExileClient_object_player_event_onHandleDamage = "ExileClient_object_player_event_onHandleDamage.sqf";
};

scripts/hooks/survivorHit.sqf (This could probably be done without this, but I have another script I'm using, unrelated to this :)):

// For the sake of logic.
_victim = _this select 0;
_shooter = _this select 1;
_damage = _this select 2;

// Don't stack scripts if we are hurting ourself.
if (_victim == _shooter) then {
	[_victim, _damage] execVM "scripts\hooks\survivorHitVictim.sqf";
} else {
	[_victim, _damage] execVM "scripts\hooks\survivorHitVictim.sqf";
	//[_shooter] execVM "scripts\hooks\survivorHitShooter.sqf";
};

survivorHitVictim.sqf:

// Survivor is hit script
// This is the GLOBAL script
// This script is for updating clients
// THE SOUND LOL

// For the sake of logic.
_victim = _this select 0;
_damage = _this select 1;

// Do we exist? Are we alive? Are we in a vehicle?
if (isNull _victim || !alive _victim || vehicle _victim != _victim) exitWith {};

// If we sustain more than 50% damage, we have broken legs in Exile.
if (_damage > 0.5) then {
	_victim say ["legBreak", 25];
	sleep 0.25;
};

// Array of sounds.
_soundArray = ["hit1", "hit2", "hit3", "hit4", "hit5", "hit6", "hit7", "hit8", "hit9"];

// Select a sound.
_soundToPlay = _soundArray select (floor(random(count _soundArray)));

// Say sound.
_victim say [_soundToPlay, 25];

description.ext:

class CfgSounds
{
	sounds[] = {legbreak, hit1, hit2, hit3, hit4, hit5, hit6, hit7, hit8, hit9};
	
	class legbreak
	{
		name = "legbreak";
		sound[] = {\sounds\injuries\legbreak.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit1
	{
		name = "hit1";
		sound[] = {\sounds\injuries\hit1.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit2
	{
		name = "hit2";
		sound[] = {\sounds\injuries\hit2.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit3
	{
		name = "hit3";
		sound[] = {\sounds\injuries\hit3.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit4
	{
		name = "hit4";
		sound[] = {\sounds\injuries\hit4.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit5
	{
		name = "hit5";
		sound[] = {\sounds\injuries\hit5.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit6
	{
		name = "hit6";
		sound[] = {\sounds\injuries\hit6.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit7
	{
		name = "hit7";
		sound[] = {\sounds\injuries\hit7.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit8
	{
		name = "hit8";
		sound[] = {\sounds\injuries\hit8.ogg, 1, 1.0};
		titles[] = {};
	};

	class hit9
	{
		name = "hit9";
		sound[] = {\sounds\injuries\hit9.ogg, 1, 1.0};
		titles[] = {};
	};
};

That last script still needs a little work. Especially around the legbreak part, considering it should only fire when the user's legs aren't broken, rather than just taking >50% of their health in damage I suppose, but hey, I added that part in just for fun.

And the injury sounds:

http://www.mediafire.com/download/u5b71p5264k6ipe/injuries.rar

Thanks to the both of you assisting me on this :)

 

2 people like this

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.