Problem with car IDS
#1

Hello.
I have a script which tells you the car is broken at <= 500 HP. Also it will shutdown the engine. Now when I spawn / enter another car (when I got another car at 500 or lower) and crash it until its 500 or lower nothing happens anymore.

CODE:

pawn Код:
new bool:isBroken[MAX_VEHICLES];
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new Float:health;
        new vehid = GetPlayerVehicleID(playerid);
        new message = GetPVarInt(playerid, "Message");
        GetVehicleHealth(vehid, health);
        if(health <= 500 && message == 0)
        {
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(vehid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehid, 0, lights, alarm, doors, bonnet, boot, objective);
            SendClientMessage(playerid, -1, "BROKEN");
            SetPVarInt(playerid, "Message", 1);
            isBroken[vehid] = true;
        }
    }
    return 1;
}
pawn Код:
CMD:engine(playerid, params[])
{
    new engine, lights, alarm, doors, bonnet, boot, objective;
    new vehicleid = GetPlayerVehicleID(playerid);
    new string[126];
    new playerState = GetPlayerState(playerid);
    new aName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);

    if(IsPlayerInAnyVehicle(playerid))
    {
        if(isBroken[vehicleid] != true)
        {
            if(playerState == PLAYER_STATE_DRIVER)
            {
                if(engine != 1)
                {
                    engine = 1;
                    SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective);
                    format(string, sizeof(string), "* %s turns the vehicles engine ON.", aName);
                    ProxDetector(20.0, playerid, string, COLOR_PURPLE);
                    return 1;
                }
                else
                {
                    engine = 0;
                    SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
                    format(string, sizeof(string), "* %s turns the vehicles engine OFF.", aName);
                    ProxDetector(20.0, playerid, string, COLOR_PURPLE);
                    return 1;
                }
            }
            else
            {
                format(string, sizeof(string), ""COL_RED"ERROR: "COL_WHITE"You need to be the driver in order to start/stop the engine.");
                SendClientMessage(playerid, -1, string);
            }
        }
        else
        {
            format(string, sizeof(string), ""COL_RED"ERROR: "COL_WHITE"The engine is siriously damaged, you failed to start it..");
            SendClientMessage(playerid, -1, string);
            format(string, sizeof(string), "%s tried to start the vehicles engine but it failed. [Siriously Damaged]", aName);
            ProxDetector(20.0, playerid, string, COLOR_PURPLE);
        }
    }
    else
    {
        format(string, sizeof(string), ""COL_RED"ERROR: "COL_WHITE"You need to be in a vehicle to control its engine.");
        SendClientMessage(playerid, -1, string);
    }
    return 1;
}
Reply
#2

You should set the PVar "Message" to 0 again if the player enters a vehicle in OnPlayerStateChange (if you didnt do that already).

Does the Command /Engine work correctly after you did ^ this?


Furthermore, I would rather use a timer for this than OnPlayerUpdate (OnPlayerUpdate gets called pretty often, the timer can be set to 1 second), also the Broken variable is not really needed, because you can check the vehicle's health in the CMD again, which makes it more safe.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)