Results 1 to 5 of 5

Thread: Randomized weapon sounds

  1. #1

    Unhappy

    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


    ?&#33;&#40;alive _unit&#41;&#58;exit
    ?&#33;&#40;_weapon == &#34;SOPMODm4&#34;&#41;&#58;exit


    _Fire = &#91;&#34;M4a&#34;,&#34;M4b&#34;,&#34;M4c&#34;&#93 ;

    _Soundsource = &#34;EmptyDetector&#34; createVehicle &#91;0,0,0&#93;

    _Soundsource setpos &#91;getpos _unit select 0,&#40;getpos _unit select 1&#41;+2,&#40;getpos _unit select 2&#41;+1&#93;;

    _sound = random count _Fire

    _sound = _sound - &#40;_sound % 1&#41;



    _Soundsource say &#40;_Fire select _sound&#41;


    exit
    [/QUOTE]
    Here&#39;s an example of the result.
    Short clip

    What I need to know,is if it&#39;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&#39;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&#39;d appreciate any help or advice.

    Macser.






  2. #2
    ?, ~, goto etc don&#39;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&#40;alive _unit && _weapon=&#34;SOPMODm4&#34;&#41;then{
    _Fire = &#91;&#34;M4a&#34;,&#34;M4b&#34;,&#34;M4c&#34;&#93 ;;
    _Soundsource = &#34;EmptyDetector&#34; createVehicle &#91;0,0,0&#93;;
    _Soundsource setpos &#91;&#40;getpos _unit select 0&#41;+&#40;sin getdir _unit&#41;*2,&#40;getpos _unit select 1&#41;+&#40;cos getdir _unit&#41;*2,&#40;getpos _unit select 2&#41;+1&#93;;
    _Soundsource say &#40;_Fire select &#40;&#40;random count _Fire&#41;-0.5&#41;&#41;;
    deleteVehicle _Soundsource;
    };
    }[/QUOTE]
    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.

  3. #3
    Quote Originally Posted by (Macser @ June 25 2007,10:04)
    [..]i randomized the firing sound of a weapon, via this script,with the fired EH[..]
    Quote Originally Posted by [b
    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 "&#92;folder&#92;ehfired.sqs";
    };

    the script "ehfired.sqs" :
    Quote Originally Posted by [b
    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




    Would you please can could may might will would shall should ? Because when everything is hunky-dory, AT do it better, because he's just some crazy old coot putting everyone in odd's way !

    FESTUNG - MOD Leader
    Berlin 1945 - MOD Leader
    the old dear WWIIEC - Addon maker

  4. #4
    Thanks for the assistance guys,

    There&#39;s enough there for me to experiment
    with.

    Btw,if it&#39;s of any relevance.The "emptyDetector"
    is the sound source,because as far as I&#39;m aware,
    the "say" command won&#39;t operate on a weapon.

    That,and the fact that only one sound per mode,
    can be allocated to a weapon.I could&#39;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&#39;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&#39;d prefer
    to have it.

    Anyway,thank you both for your help,much
    appreciated.With my average scripting,I wouldn&#39;t
    have known how to proceed.

    If I can achieve what I&#39;m after,I&#39;ll post any
    findings.





  5. #5
    Quote Originally Posted by (Macser @ June 25 2007,18:28)
    I only mention it,because I noticed Sin/Cos.
    Which would indicate movement,yes?Which
    I don&#39;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&#39;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&#39;t leave it out completely. Replace deletevehicle with _soundsource exec "deletess.sqs"

    ;deletess.sqs
    ~10
    deleteVehicle _this
    exit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •