Author Topic: random firing sound  (Read 764 times)

How do you make the gun sounds randomized?

Just parent the guns onFire.

Code: [Select]
function gunImage::onFire(%this,%obj,%slot)
{
%r = getRandom(3);
switch(%r)
{
case 0:
serverplay3d(IDKTHEARGS, %this.getPosition());
//ETC YOU FIGURE OUT THE REST, I need to sleep
}
}
« Last Edit: January 23, 2014, 07:46:02 AM by Honorabl3 »

%sound = "SoundDatablock" @ getRandom(0,3);
serverPlay3D(%sound,%this.getPosition());


also works if you name your datablocks as such.

Sorry for the bump :(
Sorry, It's just that I'm new to scripting and adding functions, so I was just wondering of how to add this function to the script after the previous function

Literally just add it after it. That's it.

function first()
{
}

function second()
{
}

How do you continue and end the random firing function? and how do you do the "getPosition" thing

Code: [Select]
//SOUND DATABLOCK SHOULD BE NAMED SoundObjectHere[0] ...

function gunImage::onFire(%this,%obj,%slot)
{
parent::onFire(%this, %obj, %slot);
%r = getRandom(3);
serverplay3d(SoundObjectHere[%r], %this.getPosition());
}

Code: [Select]
//SOUND DATABLOCK SHOULD BE NAMED SoundObjectHere[0] ...

function gunImage::onFire(%this,%obj,%slot)
{
parent::onFire(%this, %obj, %slot);
%r = getRandom(3);
serverplay3d(SoundObjectHere[%r], [s]%this[/s]%obj.getPosition());
}
umm
why not just
Code: [Select]
function gunImage::onFire(%this,%obj,%slot)
{
parent::onFire(%this, %obj, %slot);
%obj.playAudio(%slot, sound @ getRandom(1, 3));
}

you'd have to name your datablocks like myFireSound1, myFireSound2, ... myFireSoundN
N = num if ur 2stupid

Honorable, by the way, your code won't work. %this is an image datablock.
« Last Edit: February 19, 2014, 09:34:11 AM by Crystalwarrior »

"%this.getMuzzlePoint(%slot)"

I'm pretty sure an image datablock doesn't have a muzzle point, haha.


o you fixed it
« Last Edit: February 19, 2014, 09:36:57 AM by Port »

Honorable, by the way, your code won't work. %this is an image datablock.
Thanks for correcting it, keep in mind I barely code Torque these days. Though, I do try to help out.