SA-MP Forums Archive
low Vehicle Health.....EJECTED! - 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: low Vehicle Health.....EJECTED! (/showthread.php?tid=152823)



low Vehicle Health.....EJECTED! - JustinB - 05.06.2010

Hey all,Yeah it's me AGAIN

I just wanted to know if it's possible to make it so if your vehicle Health is low it automatically ejects you?
If You can,Can you please help me try to script the code?

Thanks for all the help .


Re: low Vehicle Health.....EJECTED! - (SF)Noobanatior - 05.06.2010

yep run a timer the checks all the cars being used health and if the health is < x removeplayerfromvehicle


Re: low Vehicle Health.....EJECTED! - JustinB - 05.06.2010

Quote:
Originally Posted by (SF)Noobanatior
yep run a timer the checks all the cars being used health and if the health is < x removeplayerfromvehicle
Okay So I did that and I made it look like this:

public carhealth()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
{
new Float:vHealth;
if (vHealth<100.0)
RemovePlayerFromVehicle();
SetTimer("carhealth",1000,1);
}
}
}


The Ejecting Works!
But it ejects whenever somebody gets in a vehicle....


Re: low Vehicle Health.....EJECTED! - Fj0rtizFredde - 05.06.2010

This should fix it (I think)
pawn Код:
public carhealth()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    new car2 = GetPlayerVehicleID(i);
    new Float:Vhealth;
    GetVehicleHealth(car2, Vhealth);
    if(Vhealth < 200)
    {    
     RemovePlayerFromVehicle(i);
     SetTimer("carhealth",1000,1); //maybe you should put the timer ongamemodeinit?
    }
  }
}



Re: low Vehicle Health.....EJECTED! - (SF)Noobanatior - 05.06.2010

pawn Код:
public carhealth()
{
for(new i = 0; i < MAX_PLAYERS; i++)
  {
  if(!IsPlayerInAnyVehicle(playerid)continue;
  new Float:vHealth;
  GetVehicleHeath(GetPlayerVehicleID(i),vHealth);
  if (vHealth<100.0) RemovePlayerFromVehicle();
  }

}
then just

SetTimer("carhealth",2000,1); on init

something like that


Re: low Vehicle Health.....EJECTED! - JustinB - 06.06.2010

Quote:
Originally Posted by Fj0rtizFredde
This should fix it (I think)
pawn Код:
public carhealth()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
   new car2 = GetPlayerVehicleID(i);
   new Float:Vhealth;
   GetVehicleHealth(car2, Vhealth);
   if(Vhealth < 200)
   {    
     RemovePlayerFromVehicle(i);
     SetTimer("carhealth",1000,1); //maybe you should put the timer ongamemodeinit?
   }
 }
}
Thanks a Bunch It works!

P.S Im trying to make it SendClientMessage(playerid,COLOR_RED,"Your Vehicle Is Going To Explode,You Have Been Ejected");

But I keep getting this error:

Код:
error 017: undefined symbol "playerid"



Re: low Vehicle Health.....EJECTED! - (SF)Noobanatior - 06.06.2010

SendClientMessage(i,COLOR_RED,"Your Vehicle Is Going To Explode,You Have Been Ejected");

you var will be a player in a loop like this in this case its "i"

hold on a sec ill do 1 more thing
pawn Код:
public carhealth()
{
for(new i = 0; i < MAX_PLAYERS; i++)
  {
  if(!IsPlayerInAnyVehicle(playerid)continue;
  new Float:vHealth;
  GetVehicleHeath(GetPlayerVehicleID(i),vHealth);
  if (vHealth<100.0) RemovePlayerFromVehicle();
  }

}
use this the other dont check if 1 is in a car


Re: low Vehicle Health.....EJECTED! - JustinB - 06.06.2010

Quote:
Originally Posted by (SF)Noobanatior
SendClientMessage(i,COLOR_RED,"Your Vehicle Is Going To Explode,You Have Been Ejected");

you var will be a player in a loop like this in this case its "i"

hold on a sec ill do 1 more thing
pawn Код:
public carhealth()
{
for(new i = 0; i < MAX_PLAYERS; i++)
  {
  if(!IsPlayerInAnyVehicle(playerid)continue;
  new Float:vHealth;
  GetVehicleHeath(GetPlayerVehicleID(i),vHealth);
  if (vHealth<100.0) RemovePlayerFromVehicle();
  }

}
use this the other dont check if 1 is in a car
Yes This is all correct but It doesn't know what playerid means :S
Код:
undefined symbol:playerid



Re: low Vehicle Health.....EJECTED! - (SF)Noobanatior - 06.06.2010

in the function just change playerid to i


Re: low Vehicle Health.....EJECTED! - (SF)Noobanatior - 06.06.2010

pawn Код:
public carhealth()
{
for(new i = 0; i < MAX_PLAYERS; i++)
  {
  if(!IsPlayerInAnyVehicle(i)continue;
  new Float:vHealth;
  GetVehicleHeath(GetPlayerVehicleID(i),vHealth);
  if (vHealth<100.0) {
    RemovePlayerFromVehicle(GetPlayerVehicleID(i));
    SendClientMessage(i,COLOR_RED,"Your Vehicle Is Going To Explode,You Have Been Ejected");
   }

  }

}
like this