Author Topic: multiple sound related things i'd like help implementing  (Read 3742 times)

For those of you who have answered my sound related questions before, I appreciate it, but new ideas pop into my head 24/7 and me being an amateur with torque I don't know much, so witch that being said, heres what id like to see is possible, and if so give me some tips that will send me on my way.

Feature One: Is it possible to play a sound when a certain number of projectiles flies by the character?

Feature Two: Is is possible to play a sound when a player has fired his weapon for a certain amount of time?

Now for feature 3, I have asked how to do this a LONG time ago, and I was wondering if you could help me out again

Last Feature: can you re teach me how to make weapon sound layers?

Heres the OP for that : http://forum.blockland.us/index.php?topic=258738.0

Anyways, I could get all the help and tips you can toss at me!

Hello? I didn't ask for help for the hell of it!

Feature two is possible, just use a variable that incriments every time the weapon fires, then when the target number is reached make the weapon play the sound, I can modify this post later if you need any help with the code, but its hard to write torque from my phone lol

1. Can be done -- hackily. Here's how to do it hackily, not suggested.
Code: [Select]
function Player::scanForProjectiles(%this) {
  cancel(%this.projectileCounterSchedule);
  if(!isObject(%this.client))
    return;
  initContainerRadiusSearch(%this.getTransform(), 5, $TypeMasks::ProjectileObjectType);
  while(%obj = containerSearchNext())
    if(!%obj.passed[%this]) {
      %this.projectileNear++;
      %obj.passed[%this] = true;
    }
  if((%this.projectileNear %= 25)) == 0 && %obj)
    %this.client.play2d(YourAudioProfile);
  %this.projectileCounterSchedule = %this.schedule(100, scanForProjectiles);
}

package projectileCounter {
  function GameConnection::spawnPlayer(%this) {
    %ret = parent::spawnPlayer(%this);
    %this.player.scanForProjectiles();
    return %ret;
  }
};
activatePackage(projectileCounter);

2.
Code: [Select]
function YourWeaponImage::onFire(%db, %player, %slot) {
  if((%player.fireCount = (%player.fireCount + 1) % 25) == 0)
    if(%player.getClassName() $= "player" && isObject(%player.client))
      %player.client.play2d(YourSoundProfile);
  return Parent::onFire(%db, %player, %slot);
}

Yeah, I know I spoon fed him. Frankly, I can't be bothered to explain everything right now. If you have any questions, OP, just ask and I'll answer them.
« Last Edit: September 05, 2014, 02:08:18 AM by $trinick »

1. Can be done -- hackily. Here's how to do it hackily, not suggested.
Code: [Select]
function Player::scanForProjectiles(%this) {
  cancel(%this.projectileCounterSchedule);
  if(!isObject(%this.client))
    return;
  initContainerRadiusSearch(%this.getTransform(), 5, $TypeMasks::ProjectileObjectType);
  while(%obj = containerSearchNext())
    if(!%obj.passed[%this])
      %this.projectileNear++;
  if((%this.projectileNear %= 25)) == 0)
    %this.client.play2d(YourAudioProfile);
  %this.projectileCounterSchedule = %this.schedule(100, scanForProjectiles);
}

package projectileCounter {
  function GameConnection::spawnPlayer(%this) {
    %ret = parent::spawnPlayer(%this);
    %this.player.scanForProjectiles();
    return %ret;
  }
};
activatePackage(projectileCounter);

2.
Code: [Select]
function YourWeaponImage::onFire(%db, %player, %slot) {
  if((%player.fireCount = (%player.fireCount + 1) % 25) == 0)
    if(%player.getClassName() $= "player" && isObject(%player.client))
      %player.client.play2d(YourSoundProfile);
  return Parent::onFire(%db, %player, %slot);
}

Yeah, I know I spoon fed him. Frankly, I can't be bothered to explain everything right now. If you have any questions, OP, just ask and I'll answer them.
I enjoy being spoon fed, at least your not breast feeding me, im not new but, im not a pro either :P thanks for the help guys

So when I attempted to implement Feature 2 it gave me a syntax error warning on line 272 which is this part of the function
Code: [Select]
if((%player.fireCount = (%player.fireCount + 1) % 25) == 0)
Code: [Select]
function ARX160Image::onFire(%this,%obj,%slot)
  if((%player.fireCount = (%player.fireCount + 1) % 25) == 0)
    if(%player.getClassName() $= "player" && isObject(%player.client))
      %player.Server.play3d(Fire);
  return Parent::onFire(%db, %player, %slot);
}

^ that's the full function
Im assuming I dun forgeted on something, so if I did let me know please

Code: [Select]
function ARX160Image::onFire(%this,%obj,%slot)
  if((%player.fireCount = (%player.fireCount + 1) % 25) == 0)
    if(%player.getClassName() $= "player" && isObject(%player.client))
      %player.Server.play3d(Fire);
  return Parent::onFire(%db, %player, %slot);
}
You forgot your opening bracket on the function.

You forgot your opening bracket on the function.

See I told you I dun forgeted, god im bad "kid"

So i got Feature 2 to work, but I want it to play a 3D sound that other people can hear also where would I put:

Code: [Select]
serverPlay3D(Firing @ getRandom(1,5),%obj.getPosition());
so I can get these sounds to randomize?

So i got Feature 2 to work, but I want it to play a 3D sound that other people can hear also where would I put:

Code: [Select]
serverPlay3D(Firing @ getRandom(1,5),%obj.getPosition());
so I can get these sounds to randomize?
Well with the 2nd feature you're using %player out of nowhere when the function only has the arguments of %this,%obj,%slot so %player isn't defined at all. I don't know much about playing sounds but it should work as serverPlay3D(Firing @ getRandom(1,5),%object.getTransform); notice it uses getTransform instead of getPosition

Well with the 2nd feature you're using %player out of nowhere when the function only has the arguments of %this,%obj,%slot so %player isn't defined at all. I don't know much about playing sounds but it should work as serverPlay3D(Firing @ getRandom(1,5),%object.getTransform); notice it uses getTransform instead of getPosition
and now that were talking about that, this feature broke the reloading, recoil and ammo system for the guns, because the arguments were different the reloading, ammo and recoil all use the argument %obj. is there a way I can make this feature compatible with the others and not break them?

Well if this is for a gun you're making yourself, and there is no ARX160Image::onFire function already then you don't have to return anything, or even parent it. Also on your parent you used the arguments %db,%obj,%slot if it does need to be parented then you'll want to use %this,%obj,%slot instead. Also it's bad practice to use return in that sense. Honestly you don't even need the return in there.

So for the Function i used that trinick spoon fed, i gave it a shot, and im gonna scratch the feature unless zombiekillz can spoon feed me a different function. It technically works, but ima still try and figure it out, some other time.

So ima go ahead and try Feature 1 (IDRC if its hacky, ima give it a shot) and im also gonna do some more brain-storming around Feature 3.