Game Development Community

Where do I put the Alxplay?

by Robert Carroll · in Torque Game Builder · 03/19/2010 (6:43 pm) · 3 replies

Hi, Im trying to make this behavior have audio. I don't know where to put it though. I know its there because I played it in the Console while in the game. but here's the code. I want it to shoot every time a bullet fires if you can do that. I've tried multiple places with no luck =(

if (!isObject(ShootsBehavior))
{
   %template = new BehaviorTemplate(ShootsBehavior);
   
   %template.friendlyName = "Shoots";
   %template.behaviorType = "Game";
   %template.description  = "Shoots an object";

   %template.addBehaviorField(projectile, "The projectile to clone and shoot", object, "", t2dSceneObject);
   %template.addBehaviorField(fireKey, "The key to fire the projectile with", keybind, "keyboard space");
   %template.addBehaviorField(fireRate, "The rate to fire when the fire key is held down (seconds)", float, "0.25");
   %template.addBehaviorField(projectileSpeed, "The speed of projectiles (world units per second)", float, "150");
}

function ShootsBehavior::onBehaviorAdd(%this)
{
   if (isObject(moveMap))
      moveMap.bindObj(getWord(%this.fireKey, 0), getWord(%this.fireKey, 1), "fire", %this);
}

function ShootsBehavior::onBehaviorRemove(%this)
{
   alxplay(Shoot);
      if (isObject(moveMap))
      moveMap.unbindObj(getWord(%this.fireKey, 0), getWord(%this.fireKey, 1), %this);
}

function ShootsBehavior::fire(%this, %val)
{
   
   if (%val == 0)
   {
      cancel(%this.fireSchedule);
      return;
   }
   
   if (!isObject(%this.projectile))
      return;
   
   %projectile = %this.projectile.cloneWithBehaviors();
   

   %projectile.setPosition(%this.owner.position);
   %projectile.setRotation(%this.owner.rotation);
   %projectile.setLinearVelocityPolar(%this.owner.rotation, %this.projectileSpeed);
   if (!isEventPending(%this.fireSchedule))
      %this.fireSchedule = %this.schedule(%this.fireRate * 1000, "fire", 1);
   
}

#1
03/19/2010 (6:46 pm)
Why not put it at the spot where you clone a projectile and send it on its way?
#2
03/19/2010 (6:54 pm)
Oh, K thanks that was a really simple question... I haven't done any audio for a few months =( Thnx!
#3
03/19/2010 (6:58 pm)
I know why it didn't work the first time I put it there (before I posted) I didn't save after I did it =( I'm slow today.