Game Development Community

How do I mix these together?

by Robert Carroll · in Torque Game Builder · 11/11/2009 (2:46 am) · 2 replies

Hi, Im tring to mix this behavior with another... Im tring to get it to not fire more than once on its click. Like my sniper rifle has a speed of 1 shot for every 3 seconds but how it is now you can fire as many times as you press the mouse. (in short Im trying to put a fire rate that works on it)

I tried this.
function MouseClickSoundBehavior::onMouseDown(%this, %modifier, %worldPos)
{ 
        %this.fire(1);
//if ($currentMenu != %this.menuID) return;
  if ( isobject(%this.sound) )       
      %explosion = %this.particleEffect.cloneWithBehaviors();
      %explosion.position = %position;
      %explosion.setEffectLifeMode("Kill", 1.0);
      %explosion.playEffect();
   }
}


}

function MouseClickSoundBehavior::onMouseUp(%this, %modifier, %worldPos)
{
        %this.fire(0);
}


function MouseClickSoundBehavior::fire(%this, %val)
{
   %this.tryingToFire = %val;
   if (%val == 0) 
   {
      cancel(%this.fireSchedule);
      if( !isEventPending(%this.waitSchedule))
         %this.waitSchedule = %this.schedule( %this.fireRate * 1000, "fireCond");
      return;
   }
   
   if (isEventPending(%this.fireSchedule) || isEventPending( %this.waitSchedule))
      return;
   
   if (!isObject(%this.projectile) || !%this.owner.enabled || !%this.owner.getVisible())
      return;
   
   %projectile = %this.projectile.cloneWithBehaviors();
   
   %projectile.setPosition(%this.owner.position);
   %projectile.setRotation(%this.owner.rotation);
   %projectile.setLinearVelocityPolar(%this.owner.rotation, %this.projectileSpeed);
   
   if(%this.fireRate <= 0)	
   {
      cancel(%this.fireSchedule);
      return;
   }

      alxPlay(   %this.sound );

      if (!isEventPending(%this.fireSchedule))
      %this.fireSchedule = %this.schedule(%this.fireRate * 1000, "fire", 1);

This is a behavior I wrote with a little help sorry if it has lots of errors :(

#1
11/11/2009 (3:45 am)
Try doing %this.owner.schedule rather than %this.schedule. What you are doing are assigning schedules to the behavior - not your object (which is %this.owner).
#2
11/11/2009 (10:09 pm)
K Ill try that