Macser_old 0 Posted June 25, 2007 Ok, It's possible that someone's already done this, but if they have,I haven't seen a working example. Here's where I am,in any case. Basically I randomized the firing sound of a weapon, via this script,with the fired EH: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _array = _this select 0 _unit = _array select 0 _weapon = _array select 1 ?!(alive _unit):exit ?!(_weapon == "SOPMODm4"):exit _Fire = ["M4a","M4b","M4c"] _Soundsource = "EmptyDetector" createVehicle [0,0,0] _Soundsource setpos [getpos _unit select 0,(getpos _unit select 1)+2,(getpos _unit select 2)+1]; _sound = random count _Fire _sound = _sound - (_sound % 1) _Soundsource say (_Fire select _sound) exit Here's an example of the result. Short clip What I need to know,is if it's possible to transfer that script directly into the Fired Eh,rather than just "triggering" it.If you see what I mean. You may not hear it in the clip,but there's a tiny delay between "click" and sound.I was hoping,if the code could be executed from within the EH,it might speed things up.So,can it be done? I'd appreciate any help or advice. Macser. Share this post Link to post Share on other sites
Pulverizer 1 Posted June 25, 2007 ?, ~, goto etc don't work in code strings. You can use if(bool)then{code} for conditions, or while "bool" do{code} <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{ _unit = _this select 0; _weapon = _this select 1; if(alive _unit && _weapon="SOPMODm4")then{ _Fire = ["M4a","M4b","M4c"]; _Soundsource = "EmptyDetector" createVehicle [0,0,0]; _Soundsource setpos [(getpos _unit select 0)+(sin getdir _unit)*2,(getpos _unit select 1)+(cos getdir _unit)*2,(getpos _unit select 2)+1]; _Soundsource say (_Fire select ((random count _Fire)-0.5)); deleteVehicle _Soundsource; }; } Remove line changes. The delay might be partly caused by createVehicle. It will also cause extra traffic in MP (global command), maybe it could be replaced with camCreate. Share this post Link to post Share on other sites
AtStWalker 0 Posted June 25, 2007 [..]i randomized the firing sound of a weapon, via this script,with the fired EH[..] Quote[/b] ]class CfgSounds { class KABOOM1 { name="KABOOM1"; sound[]={"ur sound",100,1.0}; titles[]={}; }; class KABOOM2 { name="KABOOM2"; sound[]={"ur sound",100,1.0}; titles[]={}; }; }; class eventhandlers { fired=[_this select 0] exec "\folder\ehfired.sqs"; }; the script "ehfired.sqs" : Quote[/b] ]~0.05 _randomsound = random 15 if(_randomsound > 0 AND _randomsound < 2)then{playsound "KABOOM1"} if(_randomsound > 1 AND _randomsound < 3)then{playsound "KABOOM2"} [..] exit Share this post Link to post Share on other sites
Macser_old 0 Posted June 25, 2007 Thanks for the assistance guys, There's enough there for me to experiment with. Btw,if it's of any relevance.The "emptyDetector" is the sound source,because as far as I'm aware, the "say" command won't operate on a weapon. That,and the fact that only one sound per mode, can be allocated to a weapon.I could've used the unit as the sound source,but then it would be locked to him.So the "emptyDetector" allows me to put the sound where I want it. I only mention it,because I noticed Sin/Cos. Which would indicate movement,yes?Which I don't really need,except upon creation. Also,the "playSound" command will always be played at the players location,rather than at the source.And the source is where I'd prefer to have it. Anyway,thank you both for your help,much appreciated.With my average scripting,I wouldn't have known how to proceed. If I can achieve what I'm after,I'll post any findings. Share this post Link to post Share on other sites
Pulverizer 1 Posted June 25, 2007 I only mention it,because I noticed Sin/Cos.Which would indicate movement,yes?Which I don't really need,except upon creation. No. Sin/cos will offset the sound 2m to the direction of the unit on the xy plane, not always 2m north of it like it was in your script. You could have the unit say the sounds, that way you'd get rid of the createVehicle command and the setpos stuff. The position of the sound might be weird from 1st person view or something though. You might need to delay the deleteVehicle command for the sounds to work but don't leave it out completely. Replace deletevehicle with _soundsource exec "deletess.sqs" ;deletess.sqs ~10 deleteVehicle _this exit Share this post Link to post Share on other sites