SetVehicleHealth help !!
#1

ok so I want to make National guards TANK and all armored vehicles have more health , as I tried this OnVehicleSpawn but its not working, tank is still 1000 HP not 10000 and others too are on 1000

Код:
public OnVehicleSpawn(vehicleid)

	if(GetVehicleModel(vehicleid) == 520 || GetVehicleModel(vehicleid) == 425) // SANG aircrafts
	{
		SetVehicleHealth(vehicleid, 2500); // Set the vehicle health
	}
    if(GetVehicleModel(vehicleid) == 528 || GetVehicleModel(vehicleid) == 427) // FBI armored truck
	{
		SetVehicleHealth(vehicleid, 5000); // Set the vehicle health
	}
	if(GetVehicleModel(vehicleid) == 432) // NG tank
	{
		SetVehicleHealth(vehicleid, 10000); // Set the vehicle health
	}
Am I doing it wrong? please tell me how
Reply
#2

Use 'public OnVehicleDamageStatusUpdate(vehicleid, playerid)' callback to check if the vehicle gets any damage and then you have to verify if is a fbi,sang or ng tank and use SetVehicleHealth. Try it .. i think that it works...
Reply
#3

Remember that OnVehicleSpawn is called when a vehicle respawns not when it is created. You can hook CreateVehicle and the other 2 functions that add static vehicles though. An example:
pawn Код:
stock HF_CreateVehicle(modelid, Float: x, Float: y, Float: z, Float: angle, color1, color2, respawn_delay, addsiren = 0)
{
    new
        vehicleid = CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay, addsiren);
       
    switch (modelid)
    {
        // SANG aircrafts
        case 425, 520: SetVehicleHealth(vehicleid, 2500);
        // FBI armored truck
        case 427, 528: SetVehicleHealth(vehicleid, 5000);
        // NG tank
        case 432: SetVehicleHealth(vehicleid, 10000);
    }
    return vehicleid;
}

#if defined _ALS_CreateVehicle
    #undef CreateVehicle
#else
    #define _ALS_CreateVehicle
#endif

#define CreateVehicle HF_CreateVehicle
Reply
#4

Try with this callback:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
        if(playerid != ispassenger)
       {
	if (GetPlayerVehicleID(GetVehicleModel(vehicleid)) == 520 || GetPlayerVehicleID(GetVehicleModel(vehicleid)) == 425) // SANG aeronaves
	{
		SetVehicleHealth (vehicleid, 2500); // Definir a saъde veнculo
	}
	if (GetPlayerVehicleID(GetVehicleModel(vehicleid)) == 528 || GetPlayerVehicleID(GetVehicleModel(vehicleid)) == 427) // FBI caminhгo blindado
	{
		SetVehicleHealth (vehicleid, 5000); // Definir a saъde veнculo
	}
	if (GetPlayerVehicleID(GetVehicleModel(vehicleid)) == 432) // tanque NG
	{
		SetVehicleHealth (vehicleid, 10000); // Definir a saъde veнculo
	}
       }
	return 1;
}
Reply
#5

Okay, I will try that, thanks
Reply
#6

Works but it can be abused so i did this
Код:
new Float:vhealth;
    	new vid = GetPlayerVehicleID(playerid);
    	GetVehicleHealth(vid, vhealth);
		if(vhealth == 1000)
 	    {

                    if(GetVehicleModel(vehicleid) == 520 || GetVehicleModel(vehicleid) == 425) // SANG aircrafts
		{
			SetVehicleHealth(vehicleid, 2500); // Set the vehicle health
		}
		if(GetVehicleModel(vehicleid) == 432) // NG tank
		{
			SetVehicleHealth(vehicleid, 10000); // Set the vehicle health
		}
it doesnt set the hp to 10000 when i get on the car, and the car HP is 1000 exactly
Reply
#7

anyone??
Reply
#8

Or... this ?
PHP код:
public OnGameModeInit()
{
    for(new 
GetVehiclePoolSize(); 0i--)
    {
        switch(
GetVehicleModel(i))
        {
            case 
520425SetVehicleHealth(i2500);
            case 
528427SetVehicleHealth(i5000);
            case 
432SetVehicleHealth(i10000);
        }
    }
    return 
1;

I don't know if this way is working.

EDIT: Changed the code
Reply
#9

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Or... this ?
PHP код:
public OnGameModeExit()
{
     for(new 
GetVehiclePoolSize(); 0i--)
    {
        
SetVehicleToRespawn(i);
    }
    return 
1;

PHP код:
public OnVehicleSpawn(vehicleid)
{
    switch(
GetVehicleModel(vehicleid))
    {
        case 
520425SetVehicleHealth(vehicleid2500);
        case 
528427SetVehicleHealth(vehicleid5000);
        case 
432SetVehicleHealth(vehicleid10000);
    }
    return 
1;

I don't if this way is working.
There is absolutely no need to loop through all the vehicles and respawn them just to call the OnVehicleSpawn callback. What if he is loading server vehicles from a database or files?

What Konstantinos posted above works absolutely fine and makes it easier to do what he's looking for. I also have a custom function to create vehicles and I do the same to set the vehicle health.
Reply
#10

Quote:
Originally Posted by Sjn
Посмотреть сообщение
There is absolutely no need to loop through all the vehicles and respawn them just to call the OnVehicleSpawn callback. What if he is loading server vehicles from a database or files?

What Konstantinos posted above works absolutely fine and makes it easier to do what he's looking for. I also have a custom function to create vehicles and I do the same to set the vehicle health.
Yeah, you are right. My bad. How can I call OnVehicleSpawn if they don't respawn?
Same though but he still needing help, I don't know why.

@D3vin : Have you tested Konstantinos's function ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)