Author Topic: Player is still running when a variable is turned off.  (Read 2964 times)

I've made a loop called Player::RPGPlayerLoop(%this) that implements a check to see when the player was last hit. If they were hit in the last 4 seconds, they cannot run. (This run method will soon be changed to checking their health status because "haha I have 1% of health and I can still run!" is just terrible), but anyway.

The check basically will see if they aren't moving during the running check and if their stamina level is less than 5, they can no longer move. <- In the red area is where it doesn't seem to call it.

Things I have tried:
  • Staying still while holding the run button (my jet key) and then leaving, which does not do anything
  • [0] Moving very very slow

    The speed factors are all at 1.

   if(getSimTime() - %this.lastHit > 4000)
   {
      if(%this.RPGStamina() < %this.RPGMaxStamina() && !%this.isRunning)
         %cl.RPGData["stamina"] += 0.2;
      else if(%this.isRunning)
      {
         if(vectorLen(%this.getVelocity()) > 1 && %this.RPGStamina() >= 5)
            %cl.RPGData["stamina"] --;
         else
         {
            %this.isRunning = 0;
            %this.setMaxForwardSpeed(%this.getMaxForwardSpeed() * %this.getSpeedFactor() * %this.RPG_SpeedFactor);
         }


         if(%this.RPGStamina() > 0)
            %usePrint = 1;
      }
   }


There is the running code that makes him directly run, which works perfectly fine.

This checks if the player is moving before they are even able to run, so why jog in place?
Again, the speed factors are at 1.

Packaged
Code: (server.cs) [Select]
function RPGPlayer::onTrigger(%this,%player,%slot,%val)
{
if(%slot == 4)
{
if(%val && %player.RPGStamina() >= 10 && vectorLen(%player.getVelocity()) > 1)
{
%player.setMaxForwardSpeed(%this.maxForwardSpeed * %player.getSpeedFactor() * %player.RPG_SpeedFactor * 1.75);
%player.isRunning = true;
}
else
{
%player.setMaxForwardSpeed(%this.maxForwardSpeed * %player.getSpeedFactor() * %player.RPG_SpeedFactor);
%player.isRunning = false;
}
}
return Parent::onTrigger(%this,%player,%slot,%val);
}
« Last Edit: April 15, 2015, 11:10:43 PM by Advanced Bot »

I'm not exactly sure what you're asking. I understand you're trying to stop players from running, but what is the issue exactly? Is the else statement not getting called at all, or is the code inside the else not working?

The else statement in red is not calling, even if I am at a complete stop, which should disable my running.

Seems I have to make a function isRunning with other speed checks to see if they are running.

Have you tried echoing the values you're testing? Is that .RPGStamina() method working?

Yeah, no offense but this seems like rudimentary debugging.

Throw this in before your if statement:

echo("VEL: " @ vectorLen(%this.getVelocity()));
echo("RPGStamina: " @ %this.RPGStamina());


See which one has an incorrect or unexpected value.

I've solved it by using 2 check functions

function Player::isRunning(%this)
{
   if(%this.getMaxForwardSpeed() == %this.getDatablock().maxForwardSpeed * %this.getSpeedFactor() * %this.RPG_SpeedFactor * 1.5)
      return true;
   return false;
}

function Player::setRunning(%this,%bool)
{
   if(%bool)
      %this.setMaxForwardSpeed(%this.getDatablock().maxForwardSpeed * %this.getSpeedFactor() * %this.RPG_SpeedFactor * 1.5);
   else
      %this.setMaxForwardSpeed(%this.getDatablock().maxForwardSpeed * %this.getSpeedFactor() * %this.RPG_SpeedFactor);
   return true;
}


Main difference is that I was using %this.getMaxForwardSpeed(), which means that it will just keep adding speed. I might release this as well as an add-on.