[BOLLOX I NEED HELP] Car fire?
#1

If the car goes on fire, how do i set it to automatically repair?
Reply
#2

On a timer:

Код:
for(new i; i<200; i++)
{
  if(!IsPlayerConnected(i)) continue;
  if(!IsPlayerInAnyVehicle(i)) continue;
  new Float:fVehicleHealth;
  GetVehicleHealth(GetPlayerVehicleID(i),fVehicleHealth);
  if(fVehicleHealth < 400)
    SetVehicleHealth(GetPlayerVehicleID(i),1000.0);
}
Reply
#3

Quote:
Originally Posted by Jay_
On a timer:

Код:
for(new i; i<200; i++)
{
  if(!IsPlayerConnected(i)) continue;
  if(!IsPlayerInAnyVehicle(i)) continue;
  new Float:fVehicleHealth;
  GetVehicleHealth(GetPlayerVehicleID(i),fVehicleHealth);
  if(fVehicleHealth < 400)
    SetVehicleHealth(GetPlayerVehicleID(i),1000.0);
}
How do i make that work for admins only?
Reply
#4

Check in the loop if a player is an admin, and if so proceed:

Код:
for(new i; i<200; i++)
{
  if(!IsPlayerConnected(i)) continue;
  if(!IsPlayerInAnyVehicle(i) || !IsPlayerAdmin(i)) continue;
  new Float:fVehicleHealth;
  GetVehicleHealth(GetPlayerVehicleID(i),fVehicleHealth);
  if(fVehicleHealth < 400)
    SetVehicleHealth(GetPlayerVehicleID(i),1000.0);
}
Reply
#5

ehm, not to be a noob, but can i get tah whole code
Reply
#6

There's a trick for that called pseudocode, it's really all about translating the code into english

Код:
for(new i; i<200; i++)
{
  if(!IsPlayerConnected(i)) continue;
  if(!IsPlayerInAnyVehicle(i) || !IsPlayerAdmin(i)) continue;
  new Float:fVehicleHealth;
  GetVehicleHealth(GetPlayerVehicleID(i),fVehicleHealth);
  if(fVehicleHealth < 400)
    SetVehicleHealth(GetPlayerVehicleID(i),1000.0);
}
becomes
[quote]
loop through all players
- if the player ID isn't connected -> go to the next player ID
- if the player isn't in any vehicle, or if the player isn't logged in as an RCON admin -> go to the next player ID
- create a variable named fVehicleHealth and store the players current vehicle health in it
- if the health of the car reaches a value of below 400
-- set the vehicle health back to 1000
end loop - next player ID
Reply
#7

i still dont understand a shiiiiiiiit
Reply
#8

Go buy a book on scripting (I started with PHP & MySQL for dummies )
Reply
#9

Код:
//OnGameModeInit
SetTimer("AutoRepair",500,1);
on the end of map

Код:
forward AutoRepair();
public AutoRepair(){
for(new i=0; i<GetMaxPlayers(); i++)
{
  if(IsPlayerConnected(i)) if(IsPlayerInAnyVehicle(i) && IsPlayerAdmin(i)){
	new Float:fVehicleHealth;
	GetVehicleHealth(GetPlayerVehicleID(i),fVehicleHealth);
  if(fVehicleHealth < 400) SetVehicleHealth(GetPlayerVehicleID(i),1000.0);
  }
}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)