Jump to content
Sign in to follow this  
bigpickle

Help with Adding Event Handler To Helicopter Config

Recommended Posts

#I have had to repost here because of posting in missions by accident#

Hello,

I've been trying to make a small sound replacement mod for use with my group on Arma CO, the replacement part is going fine and sounds ok. But when I tried to add a new sound it fell apart.

My objective is to make a sound file play when the player(s) gets into a UH1Y, then terminate playing when the player(s) gets out.

I have been told the best way to do this is add an event handler to my UH1Y config, and direct it to an SQF file.

I've googled on how to write this stuff but have no luck with getting any clear instruction. Could someone please help me to do this.

What I have written is below but it does not work:

Added into the UH1Y config :

class CfgSounds {

class Radio {

name = "Radio";

sound[] = {"cmSound_s_UH1Y\Radio_On", db+15, 1};

titles[] = {};

};

class Radio_Off {

name = "Radio_Off";

sound[] = {"cmSound_s_UH1Y\Radio_Off", db+15, 1};

titles[] = {};

};

};

The Event Handler in my UH1Y config:

class EventHandlers {

init = " [_this select 0] execVM ""\cmSound_c_UH1Y\scripts\Radio.sqf""";

My SQF file:

_UH1Y addEventHandler ["GetIn",

{

if (_this select 1) then {

sound[] = {"cmSound_s_UH1Y\Radio_On", db+15, 1};

};

};

];

_UH1Y addEventHandler ["GetOut",

{

if (_this select 1) then {

sound[] = {"cmSound_s_UH1Y\Radio_Off", db+15, 1};

};

};

];

I know this is probably time consuming for someone to help me but If i can get a working version I can learn from it and stuff.

Thank you

Share this post


Link to post
Share on other sites

I'm afraid it's not that easy. ;)

First, provided your sounds are set up correctly, there's really no need for an init eventhandler here since you should be able to define getIn and getOut eventhandlers from the config too.

As for your script; simply sticking config lines into your SQF file won't work. They are completely different languages and applied in seperate contexts. Before continuing you should probably do a little research on writing SQF code.

As for a solution to your problem; since your sound file is obviously of fixed length, you'll need to use a loop that continuously plays the sound until it's time to turn it off. Here's how I'd do it:

radioOn.sqf

// execute this from a GetIn event handler
_vehicle = _this select 0;
_unit = _this select 2;

_sleepDelay = 0.1; // time (seconds) interval to check radio status
_soundDuration = 15; // duration of the sound file (seconds)
_sound = "Radio";         // classnames of configured sound files
_soundOff = "Radio_Off";
_isOn = _vehicle getVariable ["RadioOn",false]; // the value (true or false) of RadioOn, or false if it hasn't been initialized

if(_unit == player && !(_isOn))then{

  _vehicle setVariable ["RadioOn",true];
  _timer = 0;

  // loop while RadioOn is true
  while{_vehicle getVariable ["RadioOn",false]}do{

     // every soundDuration seconds play the sound
     if(_timer <= 0)then{
        _vehicle say _sound;
        _timer = _soundDuration;
     };

     // wait a bit and decrease the timer
     sleep _sleepDelay;
     _timer = _timer - _sleepDelay;

     // check if the vehicle was killed
     if(!(alive _vehicle))then{
        // turn the radio off
        _vehicle setVariable ["RadioOn",false];
     };
  };

  // turning the radio off
  _vehicle say _soundOff;
};

radioOff.sqf

// execute this from a GetOut event handler
_vehicle = _this select 0;
_unit = _this select 2;

_isOn = _vehicle getVariable ["RadioOn",false];

if(_unit == player && _isOn)then{
  // turn the radio off
  _vehicle setVariable ["RadioOn",false];
};

Finally, the eventhandlers section of your config:

class EventHandlers {
  getin = "_this execVM ""\cmSound_c_UH1Y\scripts\radioOn.sqf""";
  getout = "_this execVM ""\cmSound_c_UH1Y\scripts\radioOff.sqf""";
};

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

Thank you so much Big D for taking the time to do this for me. I really appreciate it.

Mate your gonna want to kick my ass though cos I added everything you gave me, read up as best I could about sqf files, and put in the right values in the radioOn sqf such as time in seconds, changing the radioOn variable to true and the loop to true, added the corrected eventhandler lines to my UH1 config and still I couldnt get it to work.

Feelin like I'm a total fail now, especially as you did all the work for me. :mad:

Share this post


Link to post
Share on other sites

Hmm, well I might be able to help if you give me some hints as to why it's not working. Try doing a little debugging and see if you can get any results.

Share this post


Link to post
Share on other sites

I waited to see if there was any error messages but none showed up when starting the game.

Thats my altered radioOn.sqf :

// execute this from a GetIn event handler

_vehicle = _this select 0;

_unit = _this select 2;

_sleepDelay = 0.1; // time (seconds) interval to check radio status

_soundDuration = 67; // duration of the sound file (seconds)

_sound = "Radio"; // classnames of configured sound files

_soundOff = "Radio_Off";

_isOn = _vehicle getVariable ["RadioOn",true]; // the value (true or false) of RadioOn, or false if it hasn't been initialized

if(_unit == player && !(_isOn))then{

_vehicle setVariable ["RadioOn",true];

_timer = 0;

// loop while RadioOn is true

while{_vehicle getVariable ["RadioOn",true]}do{

// every soundDuration seconds play the sound

if(_timer <= 0)then{

_vehicle say _sound;

_timer = _soundDuration;

};

// wait a bit and decrease the timer

sleep _sleepDelay;

_timer = _timer - _sleepDelay;

// check if the vehicle was killed

if(!(alive _vehicle))then{

// turn the radio off

_vehicle setVariable ["RadioOn",false];

};

};

// turning the radio off

_vehicle say _soundOff;

};

And this is my RTP file entry:

=====================================================================

== Z:\ArmA Combined Ops\arma2oa.exe

== "Z:\ArmA Combined Ops\arma2oa.exe" -nosplash -world=empty -maxmem=2047 -cpucount=4 "-mod=Z:\ArmA Combined Ops\@cmSound;Z:\ArmA Combined Ops\@CBA"

=====================================================================

Exe timestamp: 2011/01/10 21:38:47

Current time: 2011/01/31 12:12:15

Version 1.57.76815

Item str_disp_server_control listed twice

Warning: looped for animation: ca\wheeled\data\anim\uaz_cargo01_v0.rtm differs (looped now 0)! MoveName: kia_uaz_cargo02

Warning: looped for animation: ca\wheeled\data\anim\uaz_cargo01_v0.rtm differs (looped now 1)! MoveName: uaz_cargo02

Warning: Road selection asf3 has wrong name format

Warning: Road selection mud has wrong name format

Warning: Road selection asf3 has wrong name format

Warning: Road selection mud has wrong name format

Warning: Road selection asf3 has wrong name format

Warning: Road selection mud has wrong name format

[1677,55.91,0,"XEH: PreInit Started. v3.0.6"]

[1677,56.087,0,"MISSINIT","Radio%20Chatter%20Test","utes",false,true,false]

[1677,61.871,0,"XEH: PreInit Finished"]

[1677,61.977,0,"XEH: VehicleCrewInit: 1"]

[2298,68.006,0,"XEH: PostInit Started"]

[2298,68.084,0,"CBA_VERSIONING",["#CBA_HASH#",["cba"],[[[0,7,3,148],-1]],[[0,0,0],0]]]

[2298,68.09,0,"XEH: PostInit Finished; [true,false,false,true,false,true,true,true,true,false]"]

[7283,171.682,0,"XEH: PreInit Started. v3.0.6"]

[7283,171.745,0,"MISSINIT","intro","utes",false,true,false]

[7283,172.921,0,"XEH: PreInit Finished"]

[7283,173.146,0,"XEH: VehicleCrewInit: 10"]

[7286,173.848,0.05,"XEH: PostInit Started"]

[7286,174.015,0.05,"CBA_VERSIONING",["#CBA_HASH#",["cba"],[[[0,7,3,148],-1]],[[0,0,0],0]]]

[7286,174.038,0.05,"XEH: PostInit Finished; [true,false,false,true,false,true,true,true,true,false]"]

I'm only running CBA and my sound mod cmSounds.

Edited by Bigpickle

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  

×