One "global" timer or "Per-player" timer?
#8

I don't see what's so difficult. Start the timer when they enter a vehicle, kill the timer when they leave it.

Per player timers with this logic will make the most efficient option.

pawn Код:
forward SpeedometerUpdate(playerid);
public SpeedometerUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid) && IsPlayerConnected(playerid))
    {
        new vID = GetPlayerVehicleID(playerid), string[142], string2[3], Float:rotation, Float:vhealth;
        GetVehicleZAngle(vID, rotation);
        GetVehicleHealth(vID, vhealth);
        new direction = floatround(rotation, floatround_round);
        while(direction > 360) direction -= 360;
        while(direction < 0) direction += 360;
        switch(direction)
        {
            case 0 .. 22, 338 .. 360: string2 = "N";
            case 23 .. 67: string2 = "NW";
            case 68 .. 112: string2 = "W";
            case 113 .. 157: string2 = "SW";
            case 158 .. 202: string2 = "S";
            case 203 .. 247: string2 = "SE";
            case 248 .. 292: string2 = "E";
            case 293 .. 337: string2 = "NE";
        }
        format(string, sizeof(string), "~w~VEHICLE: ~y~%s~n~~w~SPEED: ~y~%d KM/H~n~~w~LOCATION: ~y~%s~n~~w~DIRECTION: ~y~%s~n~~w~HEALTH: ~y~%0.0f%s", VehicleNames[GetVehicleModel(vID) - 400], GetPlayerSpeed(playerid), GetPlayerArea(playerid), string2, vhealth, "%%");
        TextDrawSetString(VehicleInfo[playerid], string);
        TextDrawShowForPlayer(playerid, VehicleInfo[playerid]);
        string = "\0";
    }
    else
    {
        KillTimer(VehicleTimer[playerid]);
        TextDrawHideForPlayer(playerid, VehicleInfo[playerid]);
        TextDrawHideForPlayer(playerid, VehicleBox[playerid]);
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
        VehicleTimer[playerid] = SetTimerEx("SpeedometerUpdate", 1000, true, "i", playerid);
    if(newstate == PLAYER_STATE_ONFOOT && (oldstate == PLAYER_STATE_PASSENGER || oldstate == PLAYER_STATE_DRIVER))
        KillTimer(VehicleTimer[playerid]);
    return 1;
}
Reply


Messages In This Thread
One "global" timer or "Per-player" timer? - by Kyance - 15.11.2014, 06:39
Re: One "global" timer or "Per-player" timer? - by Bakr - 15.11.2014, 08:23
Re: One "global" timer or "Per-player" timer? - by Virtual1ty - 15.11.2014, 08:25
Re : One "global" timer or "Per-player" timer? - by S4t3K - 15.11.2014, 09:13
Re: One "global" timer or "Per-player" timer? - by Bakr - 15.11.2014, 09:44
Re: One "global" timer or "Per-player" timer? - by Kyance - 15.11.2014, 11:47
Re: One "global" timer or "Per-player" timer? - by Bakr - 15.11.2014, 12:35
Re: One "global" timer or "Per-player" timer? - by Threshold - 15.11.2014, 14:31
Re: One "global" timer or "Per-player" timer? - by Kyance - 15.11.2014, 16:30

Forum Jump:


Users browsing this thread: 1 Guest(s)