Save Vehicle Status
#1

Hello. I'm trying to save the damage status of a car. Now, I am using this:

Код:
public OnFilterScriptInit()
{
	LoadVehicles();
	for(new a = 0; a < MAX_VEHICLES; a++)
	{
		timerLife = SetTimerEx("carHealth", 1000, 1, "i", a);
	}
	return 1;
}

public carHealth(id)
{
	if (id != INVALID_VEHICLE_ID)
	{
	    if(Vehicle[VehicleIDX(id)][Created])
     	{
		    new Float:health;
		    GetVehicleHealth(id, health);
		    Vehicle[id][Health] = health;
		    if(health < 352)
		    {
      			SetVehicleHealth(id, 353);
	        	SetVehicleParamsEx(id, VEHICLE_PARAMS_OFF, -1, -1, -1, -1, -1, -1);
		        Engine[id] = 0;
			}
		}
    }
	return 1;
}
With this, I can save the Health variable every time. But, if I destroy a car on purpose, overturning the car, the car explodes and respawns with 1000 health. What I want is to store, for example the vehicle exploded with 353 of health (like my function does, but this function don't work with overturned cars or cars on water). If the vehicle is beign damaged, when arrives to 353 the Engine stops (this works correctly).

Is there any function where I can set the health or don't respawn the car again if the car is destroyed?

Thanks!
Reply
#2

Hello.

The vehicle respawns automatically in PAWN. When you don't want to respawn this vehicle then you can set a variable and check in OnVehicleSpawn wheather the variable is on 1 and when it is you can port the vehicle to the position where it destroyed and set the health.

You can do it like this:
PHP код:
//under includes:
new Float:oldPosX[MAX_VEHICLES],Float:oldPosY[MAX_VEHICLES],Float:oldPosZ[MAX_VEHICLES],Float:oldPosA[MAX_VEHICLES],bool:vehDestroy[MAX_VEHICLES];
//your callback:
public carHealth(id)
{
    if (
id != INVALID_VEHICLE_ID)
    {
        if(
Vehicle[VehicleIDX(id)][Created])
         {
            new 
Float:health;
            
GetVehicleHealth(idhealth);
            
Vehicle[id][Health] = health;
            if(
health 352)
            {
                  
SetVehicleHealth(id353);
                
SetVehicleParamsEx(idVEHICLE_PARAMS_OFF, -1, -1, -1, -1, -1, -1);
                
Engine[id] = 0;
                
vehDestroy[id] = true;
                
GetVehiclePos(id,oldPosX[id],oldPosY[id],oldPosZ[id]);
                
GetVehicleZAngle(id,oldPosA[id]);
            }
        }
    }
    return 
1;
}
//OnVehicleSpawn:
public OnVehicleSpawn(vehicleid)
{
    if(
vehDestroy[vehicleid] == true)
    {
        
SetVehiclePos(vehicleid,oldPosX[vehicleid],oldPosY[vehicleid],oldPosZ[vehicleid]);
        
SetVehicleZAngle(vehicleid,oldPosA[vehicleid]);
        
vehDestroy[vehicleid] = false;
        return 
1;
    }
    return 
1;

Reply
#3

Yes, but carHealth don't work when a vehicle is dropped at water or overturned... only if car is damaged when you are driving.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)