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);
}About the author
Stay Up all night playing PS3 ;) add me PSN: RCBASEBALL13.
Associate William Lee Sims
Machine Code Games