Little problem with random..
#1

Hey, I have little problem with switch random thing..
I want to make if car have more than 500hp there are 100% chances to turn engine on (this is working perfect)
But if car is under 500HP I want to make random thing.. but it's working somehow but the problem is.. time to time this random thing don't even choose the given options "case 1" or "case 2" there isn't any effect / SendClientMessage or anything...

here is the code
pawn Код:
public EngStart(playerid)
{
    new Float:vehHP, vehicle = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehicle, vehHP);
    if(vehHP >= 500)
    {
        Eng[playerid] = 1;
        SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
        TogglePlayerControllable(playerid, 1);
    }
    if(vehHP <= 500)
    {
        switch(random(3))
        {
            case 1:
            {
                Eng[playerid] = 1;
                SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
                TogglePlayerControllable(playerid, 1);
            }
            case 2:
            {
                Eng[playerid] = 0;
                SendClientMessage(playerid, COLOR_YELLOW,"Engine failed to start, please try again");
                TogglePlayerControllable(playerid, 0);
            }
        }
    }
    return 1;
}
What is wrong ?
Reply
#2

What if the number was 0? It does nothing.

Change to:
pawn Код:
public EngStart(playerid)
{
    new Float:vehHP, vehicle = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehicle, vehHP);
    if(vehHP >= 500)
    {
        Eng[playerid] = 1;
        SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
        TogglePlayerControllable(playerid, 1);
    }
    else
    {
        switch(random(2))
        {
            case 0:
            {
                Eng[playerid] = 1;
                SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
                TogglePlayerControllable(playerid, 1);
            }
            case 1:
            {
                Eng[playerid] = 0;
                SendClientMessage(playerid, COLOR_YELLOW,"Engine failed to start, please try again");
                TogglePlayerControllable(playerid, 0);
            }
        }
    }
    return 1;
}
Reply
#3

Oh true everything here starts with 0
Umm you helped me as always REP for you
Thank you
Reply
#4

Okay 1 more problem.. When I enter the vehicle I added if player state is Driver it will start the timer but it won't..
Code:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        SetTimerEx("EngStartup", 1000, false, "d", playerid);
        return 1;
    }
    return 1;
}
Where is the problem?
Reply
#5

You should use OnPlayerStateChange instead. You are going to detect the driver's new state there.
Reply
#6

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)