SA-MP Forums Archive
Vehicle Health - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicle Health (/showthread.php?tid=81796)



Vehicle Health - cloud9 - 14.06.2009

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);

       
        }
        }
        }
   
}



Re: Vehicle Health - lavamike - 14.06.2009

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.



Re: Vehicle Health - cloud9 - 14.06.2009

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


Re: Vehicle Health - dice7 - 14.06.2009

Use SetTimerEx


Re: Vehicle Health - cloud9 - 14.06.2009

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


Re: Vehicle Health - dice7 - 14.06.2009

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


Re: Vehicle Health - Grim_ - 14.06.2009

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


Re: Vehicle Health - cloud9 - 14.06.2009

SetTimerEx also didnt worked


Re: Vehicle Health - Grim_ - 14.06.2009

Can you show the code that you used for SetTimerEx please?


Re: Vehicle Health - cloud9 - 14.06.2009


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