Author Topic: Toggling with onTrigger [vehicles]  (Read 753 times)

I'd like to make a simple script (for a vehicle) so that if you press the spacebar, it will toggle playing a sound/animation. The sound/animation is a loop, which I why I want spacebar to toggle it. All I need is a script to do that.

I'd like to make a simple script (for a vehicle) so that if you press the spacebar, it will toggle playing a sound/animation. The sound/animation is a loop, which I why I want spacebar to toggle it. All I need is a script to do that.
I'm not sure if it's possibly to mount a 3d sound to a vehicle. The only other way would to constantly have the sound being moved to the vehicle.


Okay, there's two way to make a vehicle play a sound. One is
Code: [Select]
%obj.play3D(<standard sound datablock>,%obj.getTransform());But that only plays a sound in one position once.

Code: [Select]
%obj.PlayAudio(<slot>,<vehiclesounddatablock>);Is how sounds like the helicopter sound is played. However, It requires a special vehicle sound datablock.

For vehicle sound loops:
Code: [Select]
datablock AudioDescription(<vehicle>Looping3d)
{
   volume   = 2.0;
   isLooping= true;

   is3D     = true;
   ReferenceDistance= 5.5;
   MaxDistance= 80.0;
   type     = $SimAudioType;
};
datablock AudioProfile(<vehicle>Sound)
{
   filename    = "./<sound>.wav";
   description = <vehicle>Looping3d;
   preload = true;
};


However, I just want a script to toggle whether it's playing or now, like when you first press it, it plays a sound in a slot. When you press it again, it plays a short, non-looping sound to end it.

How do I get that?

I know I'm missing something in here to make it a toggle, not hold to play.

Code: [Select]
function dentVehicle::onTrigger(%this, %obj, %num, %cli, %wha)
{
      if(%obj.playing $= 1)
      {
// plays a short, quiet sound in the same slot to stop the music
     %obj.PlayAudio(1,stopSound);
         %obj.playing = 0;
      }
      else
      {
         %obj.PlayAudio(1,musicSound);
         %obj.playing = 1;
      }
}

And armor:onTrigger makes the player, no matter where it is, play the music when clicking.

Help.Don't call me a noob. I'm new at this and I need help

put if(%num != 3 || !%cli)return; at the start (indent it yourself of course).

So this:
Code: [Select]
  if(%num != 3 || !%cli)
    return;
Goes like this?
Code: [Select]
function dentVehicle::onTrigger(%this, %obj, %num, %cli, %wha)
{
  if(%num != 3 || !%cli)
    return;

      if(%obj.playing $= 1)
      {
     %obj.PlayAudio(1,musicSound);
         %obj.playing = 1;//also tried 0 there
      }
      else
      {
         %obj.PlayAudio(1,stopSound);
         %obj.playing = 0;//I also tried 1 there
      }
}
I'm sorry, I'm really bad at this. But  if(%num != 3 || !%cli) doesn't seem to make much sense relative to the variables?

Yes that's right. It'll basically make it so only space can trigger it, and only do stuff when you actually click down, not click down then let go like it was before. That was causing it to always play music/whatever.

Yes that's right. It'll basically make it so only space can trigger it, and only do stuff when you actually click down, not click down then let go like it was before. That was causing it to always play music/whatever.
I'm sorry, but, it's not working...

Do you think I can re-write this script completely somehow to make it work?

Please, I put helper's names in the credits and script. I just need help with this.