SA-MP Forums Archive
GetVehicleHealth on trailers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP (https://sampforum.blast.hk/forumdisplay.php?fid=3)
+--- Forum: Bug Reports (https://sampforum.blast.hk/forumdisplay.php?fid=20)
+--- Thread: GetVehicleHealth on trailers (/showthread.php?tid=390067)



GetVehicleHealth on trailers - tyler12 - 04.11.2012

pawn Код:
public GlobalTimer()
{
for(new c = 0; c < MAX_PLAYERS; c++)
    {
        new vehicleid = GetPlayerVehicleID(c);
        if(IsPlayerInAnyVehicle(c))
        {
            if(GetVehicleModel(vehicleid) == 515)
            {
                new vtrailer = GetVehicleTrailer(vehicleid);
                if(GetVehicleModel(GetVehicleTrailer(vehicleid))== 584)
                {
                    new Float:health;
                    GetVehicleHealth(vtrailer, health);
                    SetVehicleHealth(vtrailer, health-1);
                }

            }
        }

    }
}
It only stay's at 999.00 as GetVehicleHealth return's 1000 always.


Re: GetVehicleHealth on trailers - Basssiiie - 05.11.2012

Aren't trailers by default invincible? Like bicycles and trains? I'm not sure though.


Re: GetVehicleHealth on trailers - tyler12 - 05.11.2012

No, health decreases.


Re: GetVehicleHealth on trailers - kaisersouse - 05.11.2012

You're only checking trailers IF they are attached. Are you looking for god-mode trailers all the time, or do you actually need the health amounts for individual trailers?

Heres something to start with:
Код:
new vmodel;
for(new v; v < MAX_VEHICLES; v++)
{
     vmodel = GetVehicleModel(v);
     switch(vmodel)
     {
         case 435,450,569,570,584,590,591,606,607,608,610,611: //all trailers according to wiki.sa-mp.com
         {
               SetVehicleHealth(v,1000);
         }
     }
}
Some notes on the loop you provided: If GetPlayerVehicleID returns a value OTHER than INVALID_VEHICLE_ID....you don't need to further check IsPlayerInAnyVehicle. If it returned a valid ID...they are in a vehicle.


Re: GetVehicleHealth on trailers - AndreT - 05.11.2012

Quote:
Originally Posted by kaisersouse
Посмотреть сообщение
Some notes on the loop you provided: If GetPlayerVehicleID returns a value OTHER than INVALID_VEHICLE_ID....you don't need to further check IsPlayerInAnyVehicle. If it returned a valid ID...they are in a vehicle.
Now that's an amazing optimization note we don't often see on these forums!

In fact,
pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
    vID = GetPlayerVehicleID(playerid);
    // ...
}
is as good as
pawn Код:
if((vID = GetPlayerVehicleID(playerid)) != 0)
or
pawn Код:
vID = GetPlayerVehicleID(playerid);
if(vID != 0)
{
    // ...
}



Re: GetVehicleHealth on trailers - kaisersouse - 05.11.2012

Thanks! However for the LONGEST time I didnt realize something...started scripting in 2007 and only realized this in 2012 once it was pointed out:

Vechicle ID CAN be 0!!! I had to change everything in Everystuff from:

if(!GetPlayerVehicleID(playerid))

to

if(GetPlayerVehicleID(playerid) == INVALID_VEHICLE_ID)

The first one checks to see if vehicleid is 0...assuming that there is no 'vehicle 0'. That assumption was wrong...the best way to check if a vehicleid is valid is to use things like:

if(GetPlayerVehicleID(playerid) == INVALID_VEHICLE_ID) SendClientMessage(playerid,COLOR_WHATEVER,"Thats not a real car!");

if(GetPlayerVehicleID(playerid) != INVALID_VEHICLE_ID) SendClientMessage(playerid,COLOR_WHATEVER,"That IS a real car!");


Re: GetVehicleHealth on trailers - Kar - 06.11.2012

Say what?

kaisersouse I think your wrong there, but https://sampwiki.blast.hk/wiki/GetPlayerVehicleID does not return INVALID_VEHICLE_ID, none of the sa-mp functions actually return INVALID_VEHICLE_ID, I only use it to initialize and reset variables.

That code you have there
pawn Код:
if(GetPlayerVehicleID(playerid) == INVALID_VEHICLE_ID)
actually shouldn't work, it should return false all the time. GetPlayerVehicleID returns 0 if the player doesn't have a vehicle id assigned.