Question about Vehicles health, timer and re position.
#1

Hey guys,


I have this idea, that when a vehicles health goes under 350, then a timer starts and after 10 minutes, the vehicle will be placed at another position.
However, if the vehicles health goes above 350, the timer shouldn't affect this car anylonger.

Ofcourse it should be working seperately with every car, so that it won't bug any other cars, but the one that just went just under 350 health.

I have this so far, but i'm not quite sure of how to actually get it to work with the timer.

Код:
 public Scrap(playerid, vehicleid)
{
 	if(vehhealth > 349){
	KillTimer(ScrapTimer);
	}else{
	if(vehhealth <= 349){
	new r = random(MAX_RANDOM_POSITIONS-1);
	vehicleid = GetPlayerVehicleID(playerid);
	SetVehiclePos(vehicleid, rPos[r][0], rPos[r][1], rPos[r][2]);
	KillTimer(ScrapTimer);
}
I am aware that the killtimer will completely remove the timer, but do You have any idea of how i could get this to work?
Also, i havn't yet made a timer yet. I could use your assistance in this one.


Much appreciated. Thanks.
Reply
#2

This could be one option..
pawn Код:
new sTimer[MAX_VEHICLES] = { -1, ... };

public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
  new Float:health;
  GetVehicleHealth(vehicleid, health);
  if(health >= 350)
  {
    if(sTimer[vehicleid] != -1)
    {
      KillTimer(sTimer[vehicleid]);
      sTimer[vehicleid] = -1;
    }
  }
  else if(health < 350)
  {
    if(sTimer[vehicleid] == -1)
    {
      sTimer[vehicleid] = SetTimerEx("RespawnVehicle", 600000, 0, "i", vehicleid);
    }
  }
  return 1;
}

forward RespawnVehicle(vehicleid);
public RespawnVehicle(vehicleid)
{
  new r = random(MAX_RANDOM_POSITIONS-1);
  SetVehiclePos(vehicleid, rPos[r][0], rPos[r][1], rPos[r][2]);
}
...however OnVehicleDamageStatusUpdate doesnt detect vehicle health change, so it would work probably about 50% of the time.
I suggest you find OnVehicleHealthChange callback, unless you have it already, and paste the code there..
Reply
#3

I love you! Thanks

I'll try this out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)