Basic Fatigue System For Running

Started by Sonmez, Nov 12, 2020, 04:15 PM

Previous topic - Next topic

Sonmez

Updated...

[noae][noae][noae][noae]function onScriptLoad()
{
    fatigue <- array(GetMaxPlayers(), null);
}
function onPlayerJoin( player )
{
    fatigue[player.ID] = false;
}
function onPlayerMove( player, lastX, lastY, lastZ, newX, newY, newZ )
{
    if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
    {
        if(fatigue[player.ID] == false && !player.Vehicle)
        {
            NewTimer("CheckFatigue", 1000, 1, player.ID,1,0);
            fatigue[player.ID] = true;
        }
    }
}
function CheckFatigue(p,a,t)
{
    local player = FindPlayer(p)
    if (!player) return false;
    if (player.Vehicle) return false;
    switch(a)
    {
        case 0:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,1,0);
          }
          else
          {
              fatigue[player.ID] = false;
          }
        break;
        case 1:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,2,0);
          }
          else
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,0,0);
          }
        break;
        case 2:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,3,0);
          }
          else
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,1,0);
          }
        break;
        case 3:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,4,0);
          }
          else
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,2,0);
          }
        break;
        case 4:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,5,0);
          }
          else
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,3,0);
          }
        break;
        case 5:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,6,0);
          }
          else
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,4,0);
          }
        break;
        case 6:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,7,0);
          }
          else
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,5,0);
          }
        break;
        case 7:
          if (player.Speed.x > 0.15 || player.Speed.x < -0.15||player.Speed.y > 0.15 || player.Speed.y < -0.15)
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,8,0);
          }
          else
          {
              NewTimer("CheckFatigue", 1000, 1, player.ID,6,0);
          }
        break;
        case 8:
          player.IsFrozen = true;
          player.SetAnim(0,9);
          NewTimer("CheckFatigue", 75, 1, player.ID,9,0);
        break;
        case 9:
          player.SetAnim(0,9);
          t +=1
          if (t > 99){
            NewTimer("CheckFatigue", 100, 1, player.ID,10,0);
          }else{NewTimer("CheckFatigue", 75, 1, player.ID,9,t);}
         
        break;
        case 10:
          player.IsFrozen = false;
          fatigue[player.ID] = false;
        break;

    }
}
[/noae][/noae][/noae][/noae]
if (!perfect) createAgain();

Inferno

didnt test yet but code seems good and working.
Good snippet for RP servers.
Good work
Viva la VU
VFS Developer
VCCNR Administrator