Vehicle Health
#1

I have coded such that when a players Vehicle health is same for a period of 20 seconds he get removed from his vehicles. But it removes players from their vehicle even the health has changed, plz help tia.

pawn Код:
new Float:oldv[MAX_PLAYERS];
new Float:newv[MAX_PLAYERS];
forward health();
forward vhealth();


public health()
{
   
        for(new i=0;i<MAX_PLAYERS;i++)
    {
      if(PlayerDerby[i] == 1){
        if(IsPlayerInAnyVehicle(i))
    {
      GetVehicleHealth(GetPlayerVehicleID(i),oldv[i]);
            SetTimer("vhealth",20000,0);
       
        }
   
        }
        }

}
public vhealth()
{
        for(new i=0;i<MAX_PLAYERS;i++)
    {
      if(PlayerDerby[i] == 1){
        if(IsPlayerInAnyVehicle(i))
      {
      GetVehicleHealth(GetPlayerVehicleID(i),newv[i]);
            SetTimer("health",1000,0);
            if (oldv[i] == newv[i]) RemovePlayerFromVehicle(i);

       
        }
        }
        }
   
}
Reply
#2

pawn Код:
new Float:oldv[MAX_PLAYERS];
new Float:newv[MAX_PLAYERS];
forward health();
forward vhealth();


public health()
{
  for(new i=0;i<MAX_PLAYERS;i++)
  {
    if(PlayerDerby[i] == 1)
    {
      if(IsPlayerInAnyVehicle(i))
      {
        new Float:carhp, Float:FinalHP;
        new VID = GetPlayerVehicleID(i);
        GetVehicleHealth(VID, carhp);
        FinalHP = carhp/10;
        oldv[i] = floatround(FinalHP, floatround_round);
        SetTimer("vhealth",20000,0);
      }
    }
  }

}

public vhealth()
{
  for(new i=0;i<MAX_PLAYERS;i++)
  {
    if(PlayerDerby[i] == 1)
    {
      if(IsPlayerInAnyVehicle(i))
      {
        new Float:carhp, Float:FinalHP;
        new VID = GetPlayerVehicleID(i);
        GetVehicleHealth(VID, carhp);
        FinalHP = carhp/10;
        newv[i] = floatround(FinalHP, floatround_round);
        SetTimer("health",1000,0);
        if(oldv[i] == newv[i]) RemovePlayerFromVehicle(i);
      }
    }
  }
}
That should work. By default Vehicle's hp are out of 1000. Anything you do may decrease it very little. This simply rounds it so the vehicle hp is out of 100. It should work fine.
Reply
#3

thanks for the help, but it is not working.

It just removes playerid 0 from the vehicle and it doesnt event check the health, plz help
Reply
#4

Use SetTimerEx
Reply
#5

i dont know how to use it, can u help me a little bit.
Reply
#6

Here's an example:
pawn Код:
//top
new timername[MAX_PLAYERS];
//onplayercmdtext
    if(strcmp(cmdtext, "/execute", true) == 0)
    {
    timername[playerid] = SetTimerEx("timerfunction", 50, false, "i", playerid);
    }

    if(strcmp(cmdtext, "/kill", true) == 0)
    {
    KillTimer(timername[playerid]);
    }

//the function
forward timerfunction(playerid);
public timerfunction(playerid)
{
//do something
}
https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#7

Quote:
Originally Posted by cloud9
i dont know how to use it, can u help me a little bit.
https://sampwiki.blast.hk/wiki/SetTimerEx

I'll tell you how I learned it.

So, you have a function with an extra param(Ex.'playerid') so you'd have to use SetTimerEx to go through that extra param. The way it is is, SetTimerEx("FunctionName", timeinmilliseconds, repeating?, format, extraparam);
In our case, the extraparam would be 'playerid', because that's the extra param we're using.

"I know the wiki says the same thing basically, but I said this because:
1) He probably wont' click the link
2) the way the wiki explains it can be confusing
Reply
#8

SetTimerEx also didnt worked
Reply
#9

Can you show the code that you used for SetTimerEx please?
Reply
#10


pawn Код:
new Float:oldv[MAX_PLAYERS];
new Float:newv[MAX_PLAYERS];
forward health();
forward vhealth();


public health()
{
  for(new i=0;i<MAX_PLAYERS;i++)
  {
    if(PlayerDerby[i] == 1)
    {
      if(IsPlayerInAnyVehicle(i))
      {
        new Float:carhp, Float:FinalHP;
        new VID = GetPlayerVehicleID(i);
        GetVehicleHealth(VID, carhp);
        FinalHP = carhp/10;
        oldv[i] = floatround(FinalHP, floatround_round);
        SetTimerEx("vhealth",20000,0,i,playerid);
      }
    }
  }

}

public vhealth()
{
  for(new i=0;i<MAX_PLAYERS;i++)
  {
    if(PlayerDerby[i] == 1)
    {
      if(IsPlayerInAnyVehicle(i))
      {
        new Float:carhp, Float:FinalHP;
        new VID = GetPlayerVehicleID(i);
        GetVehicleHealth(VID, carhp);
        FinalHP = carhp/10;
        newv[i] = floatround(FinalHP, floatround_round);
        SetTimerEx("health",1000,0,i,playerid);
        if(oldv[i] == newv[i]) RemovePlayerFromVehicle(i);
      }
    }
  }
}
sorry if i have done anything wrong that wat u said, i just started learning pawno
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)