Home   Help Search Login Register  

Author Topic: Play A Random Sound  (Read 3555 times)

0 Members and 1 Guest are viewing this topic.

Offline Semedar

  • Members
  • *
    • Semedars Official Website
Play A Random Sound
« on: 25 Apr 2011, 05:36:51 »
So I have this script for when I kill an opfor dude a sound plays:

Code: [Select]
?!local _this: exit
playSound "GotHim"

Question is: How do I make it play a random one of two. So:

Code: [Select]
?!local _this: exit
playSound "GotHim"
or
playSound "GotHim2"

I'm assuming you will use the "Random" argument but I wouldn't know how to implement it.  :(

Thanks for any help.  ;)

Hah! I found out with a ton of research.  :D Here's how I did it:

"KillSound.sqs"
Code: [Select]
; ****************************************************************
; Random Kill Sound Script
; Created by: Semedar
; ****************************************************************

?!local _this: exit

_random = random 5
_a = _random - (_random mod 1)

~(random 3)

?(_a == 1) : goto "1"
?(_a == 2) : goto "2"
?(_a == 3) : goto "3"
?(_a == 4) : goto "4"
?(_a == 5) : goto "5"

#1
playSound "GotHim"
exit

#2
playSound "Contact"
exit

#3
playSound "TangoDown"
exit

#4
playSound "BingoBingo"
exit

#5
playSound "ThreatNeutralized"
exit

And if you want to know how I implemented this in-game, just add a trigger like this:



Axis a: 99999
Axis b: 99999

Activation: OPFOR (Once)

Present

Text: Kill Sound

Condition: true

On Act.:
Code: [Select]
{_x addEventHandler ["killed", "(_this select 1) exec ""KillSound.sqs"""]} forEach thisList
« Last Edit: 26 Apr 2011, 05:45:31 by Semedar »

Re: Play A Random Sound
« Reply #1 on: 01 Jul 2011, 15:43:24 »
If you want to use slightly less scripts something like this would work just as well

Code: [Select]
_random = random 100

? _random <= 50 : playsound "GotHim"
? _random > 50 : playsound "GotHim2"

That would work just as well, doesn't really make any difference but just thought I'd mention it

Offline Zipper5

  • BIS Team
  • ****
Re: Play A Random Sound
« Reply #2 on: 08 Jul 2011, 19:38:14 »
The best way to do it in ARMA 2 is using BIS' function. Saves a lot of space:
Code: [Select]
waitUntil {!(isNil "bis_fnc_init")};
_sound = ["Sound1","Sound2","Sound3"] call bis_fnc_selectRandom;
playSound _sound;
Obviously you'll need to place the Functions Module in the mission. Anyways, this thread was made in April so I guess there isn't much benefit to us telling him better ways to find it. :P
« Last Edit: 08 Jul 2011, 19:40:22 by Zipper5 »

Offline Semedar

  • Members
  • *
    • Semedars Official Website
Re: Play A Random Sound
« Reply #3 on: 09 Aug 2011, 23:56:05 »
Haha thanks for the update :) I now switched from my version to yours, Zipper5. :D Can always appreciate cutting down the file size.  ;)

Offline Semedar

  • Members
  • *
    • Semedars Official Website
Re: Play A Random Sound
« Reply #4 on: 17 Oct 2011, 14:34:19 »
I have another thing I would like to add to this:

How would I add a sideChat feature to it so every time I kill someone, it plays a random sound AND the person who killed the enemy would say something like: "Tango Down" along with a sound file I have that says exactly that. I thought it would be simple to just put something like this:

Code: [Select]
waitUntil {!(isNil "bis_fnc_init")};
_responses = [["GotHim","Got Him!"],["Contact","Contact!"],["TangoDown","Tango Down!"],["BingoBingo","Bingo Bingo!"],["ThreatNeutralized","Threat Neutralized!"]];
_indx = floor random 3;
playsound ((_responses select _indx) select 0);
player sidechat ((_responses select _indx) select 1);

But everyone says the response (assuming they're an actual player). And if an AI kills an enemy, it will make me say the response. I just want the killer to say the response.

tl:dr: How would I be able to make the killer say the response but everyone else be able to hear the sound file?
« Last Edit: 17 Oct 2011, 14:48:08 by Semedar »