Vehicle health state
#1

Hey guys, this is my current vehicle health system. The health is showing like 1000.00, i want to make it either showing as a percentage Eg: 100%, or with state name Eg: Perfect, Good, Bad etc.

pawn Код:
GetVehicleHealth(vehicleid, vehiclehealth);
        format(HPString, sizeof(HPString), "~w~Damage: %.2f", vehiclehealth);
        if(vehiclehealth < 300)
        {
            new engine,lights,alarm,doors,bonnet,boot,objective;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
            TextDrawSetString(APlayerData[playerid][VHealth], "~r~Engine broken");
       
        }
        else TextDrawSetString(APlayerData[playerid][VHealth], HPString);
Can someone help me?
Reply
#2

That should work.
pawn Код:
GetVehicleHealth(vehicleid, vehiclehealth);
        format(HPString, sizeof(HPString), "~w~Damage: %.0f", vehiclehealth);//You should use .0f to get the correct/perfect percentage.
        if(vehiclehealth < 300)
        {
            new engine,lights,alarm,doors,bonnet,boot,objective;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
            TextDrawSetString(APlayerData[playerid][VHealth], "~r~Engine broken");
       
        }
Reply
#3

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
That should work.
pawn Код:
GetVehicleHealth(vehicleid, vehiclehealth);
        format(HPString, sizeof(HPString), "~w~Damage: %.0f", vehiclehealth);//You should use .0f to get the correct percentage.
        if(vehiclehealth < 300)
        {
            new engine,lights,alarm,doors,bonnet,boot,objective;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
            TextDrawSetString(APlayerData[playerid][VHealth], "~r~Engine broken");
       
        }
Why are you using TextDrawSetString if you aren't passing any string after [VHealth]?
Reply
#4

Quote:
Originally Posted by Face9000
Посмотреть сообщение
Why are you using TextDrawSetString if you aren't passing any string after [VHealth]?
Well , i don't know about that script he only showed a part of it , i answered his question that he made the thread for.
Reply
#5

I accidentally copied half code, it is updated now.

But the vehicle health is now showing from 1000. I wanted it to be 100% max. then decrease like 99%, 98% etc.
Reply
#6

Quote:
Originally Posted by iOxide
Посмотреть сообщение
I accidentally copied half code, it is updated now.

But the vehicle health is now showing from 1000. I wanted it to be 100% max. then decrease like 99%, 98% etc.
Well that's because you used GetVehicleHealth function and default vehicle health is 1000.
https://sampwiki.blast.hk/wiki/GetVehicleHealth
Quote:

Note: Full vehicle health is 1000. For more information on health values

So i suggest you to use your idea about if the health equals too 1000 set the textdraw string to CarState: Good , etcc here's a small example
pawn Код:
GetVehicleHealth(vehicleid, vehiclehealth);
        if(vehiclehealth == 1000)
        {
            new engine,lights,alarm,doors,bonnet,boot,objective;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
            TextDrawSetString(APlayerData[playerid][VHealth], "~g~Vehicle stats : Good");
       
        }
        else if(vehiclehealth == 500)
        {
         //and so on..
        }
Reply
#7

Since a vehicle catches on fire at a health of 250.0, we'll assume that to be 0%. So:

pawn Код:
new Float:percentage = (((vehiclehealth - 250.0) / (1000.0 - 250.0)) * 100.0);
Reply
#8

Thanks, Vince.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)