Vehicle Damage
#1

I've got this set to shut the vehicle's engine off when the health gets below 60, but it simply doesn't shut the engine off. You keep driving.

pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    new Float:health;
    GetVehicleHealth(vehicleid, health);
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    if(health < 60)
    {
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
        return 1;
    }
    return 1;
}
Reply
#2

"This callback is called when a vehicle element such as doors, tires, panels, or lights get damaged."

I suggest you doing loop though all players, checking if he is using a vehicle && isdriver and if vehicle health < 60


pawn Код:
forward VehicleCheckTimer();
SetTimer("VehicleCheckTimer", 1000, 1);

public VehicleCheckTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInAnyVehicle(i))
        {
            new vid, Float:vhp;
            vid = GetPlayerVehicleID(i);
            GetVehicleHealth(vid, vhp);
            if(vhp < 265)
            {
                SendClientMessage(i, -1, "Your engine is blown. Use /service mechanic to call a Mechanic");
                SendClientMessage(i, -1, "or type /exit to get out of your car.");
                new engine,lights,alarm,doors,bonnet,boot,objective;
                GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                SetVehicleParamsEx(vid,0,0,alarm,doors,bonnet,boot,objective);
                SetVehicleHealth(vid, 250);
            }
        }
    }
    return 1;
}
Reply
#3

You will never be able to damage to 60 HP

vehicles have 1000 HP and at 250 HP it starts to burn, use

if(health < PreviousHealth+100)


Where PreviousHealth is HP you get previously, like in some timer or so.
and 100 is how heavy impact you want that engine cuts.

Or just Turn the engine off at any damage, then you dont need a health at all.



@StreetGT, yoyo
Reply
#4

omg i fucking forgot that, i was thinking it was 100.00 :P
Reply
#5

Quote:
Originally Posted by ikey07
Посмотреть сообщение
You will never be able to damage to 60 HP

vehicles have 1000 HP and at 250 HP it starts to burn, use

if(health < PreviousHealth+100)


Where PreviousHealth is HP you get previously, like in some timer or so.
and 100 is how heavy impact you want that engine cuts.

Or just Turn the engine off at any damage, then you dont need a health at all.



@StreetGT, yoyo
Ah yes, i forgot it, less than 250 it starts burn :b

@Ikey yoyo
Reply
#6

I set mine around 260 for a nice dark black smoke but not quite on fire yet, and the way I did it was with a timer that gets vehicles health and if gets below 260 is automatically sets the health to 260 and shuts the engine off and won't let you start it back.

pawn Код:
forward RPTimers();
forward VehicleHealthSet();
forward BrokenCar();
new RolePlayTimer;
new CarIsBroken[MAX_VEHICLES] = 0;
pawn Код:
OnGameModeInIt()
{
     RolePlayTimer = SetTimer("RPTimers", 1000, 1);
     return 1;
}
pawn Код:
public RPTimers()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
                    new Float:h;
                    new veh = GetPlayerVehicleID(playerid);
                    GetVehicleHealth(veh, h);
                    if(h <= 260)
                    {
                         BrokenCar();
                    }
                 }
         }
         return 1;
}
pawn Код:
public BrokenCar()
{
    for(new i = 0; i< MAX_PLAYERS; i++)
    {
        new string[256];
        new name[MAX_PLAYERS];
        GetPlayerName(i, name, sizeof(name));
            new veh = GetPlayerVehicleID(playerid);
        if(IsPlayerInVehicle(i, veh))
        {
                    SetVehicleHealth(veh, 260.000);
                    CarIsBroken[veh] = 1;
                        new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(veh, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(veh, VEHICLE_PARAMS_OFF, lights, alarm, locked, bonnet, boot, objective);
            EngineRunning[veh] = 0; //however your engine commands is set up
            format(string, sizeof(string), "** %s's vehicle's engine stalled", name);
            ProxDetector(30.0, i, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        }
pawn Код:
if(strcmp(cmdtext, "/engine", true) == 0)
    {
             new veh = GetPlayerVehicleID(playerid);
             if(CarIsBroken[veh] == 0 &&//whatever you use to tell if engine is running)
             {
                  //Code to start your car
             }
             else
             {
                  //Don't start the car
             }
             return 1;
         }
Just a small example of kinda how my code is set up, maybe you can look at it a little and kind of understand a little more.

And I know the indentation is right but I don't have time to fix it correctly doesn't really matter as this is just an example.
Reply
#7

I added another 0 to my code, so it shuts off at 600. I left some things out to stop a direct copy-paste, thanks anyhow :P
Reply
#8

Welcome!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)