HELP: TIMER FOR EACH PLAYER???
#1

Here is code:
pawn Код:
#include <a_samp>

new Text:Chiliad_Timer0[MAX_PLAYERS];
new Text:Chiliad_Timer1;

new Milliseconds[MAX_PLAYERS];
new Seconds[MAX_PLAYERS];
new Minutes[MAX_PLAYERS];

new Chiliad_Timer[MAX_PLAYERS];
new Timer_Result[128];
new Timer_Is_Stopped[MAX_PLAYERS];
forward Chiliad_Counter(playerid);

public OnFilterScriptInit()
{
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        Timer_Is_Stopped[i] = 0;
        Milliseconds[i] = 0;
        Seconds[i] = 0;
        Minutes[i] = 0;
   
        Chiliad_Timer0[i] = TextDrawCreate(120.000000, 230.000000, "0:0.0");
        TextDrawAlignment(Chiliad_Timer0[i], 3);
        TextDrawBackgroundColor(Chiliad_Timer0[i], 255);
        TextDrawFont(Chiliad_Timer0[i], 1);
        TextDrawLetterSize(Chiliad_Timer0[i], 0.759999, 2.699999);
        TextDrawColor(Chiliad_Timer0[i], -1);
        TextDrawSetOutline(Chiliad_Timer0[i], 0);
        TextDrawSetProportional(Chiliad_Timer0[i], 1);
        TextDrawSetShadow(Chiliad_Timer0[i], 1);
    }
    Chiliad_Timer1 = TextDrawCreate(69.000000, 203.000000, "- Time -");
    TextDrawAlignment(Chiliad_Timer1, 2);
    TextDrawBackgroundColor(Chiliad_Timer1, 255);
    TextDrawFont(Chiliad_Timer1, 1);
    TextDrawLetterSize(Chiliad_Timer1, 0.550000, 2.099999);
    TextDrawColor(Chiliad_Timer1, -1);
    TextDrawSetOutline(Chiliad_Timer1, 0);
    TextDrawSetProportional(Chiliad_Timer1, 1);
    TextDrawSetShadow(Chiliad_Timer1, 1);
    return 1;
}

public OnFilterScriptExit()
{
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        TextDrawHideForAll(Chiliad_Timer0[i]);
        TextDrawDestroy(Chiliad_Timer0[i]);
    }
    TextDrawHideForAll(Chiliad_Timer1);
    TextDrawDestroy(Chiliad_Timer1);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/start", cmdtext, true, 10) == 0)
    {
        Chiliad_Timer[playerid] = SetTimer("Chiliad_Counter", 100, false);
        Timer_Is_Stopped[playerid] = 0;
        return 1;
    }
    if (strcmp("/stop", cmdtext, true, 10) == 0)
    {
        KillTimer(Chiliad_Timer[playerid]);
        Timer_Is_Stopped[playerid] = 1;
        Milliseconds[playerid] = 0;
        Seconds[playerid] = 0;
        Minutes[playerid] = 0;
        return 1;
    }
    return 0;
}

public Chiliad_Counter(playerid)
{
    Milliseconds[playerid]++;
    if (Milliseconds[playerid] > 9)
    {
        Seconds[playerid]++;
        Milliseconds[playerid] = 0;
    }
    if (Seconds[playerid] > 59)
    {
        Minutes[playerid]++;
        Seconds[playerid] = 0;
    }
    format(Timer_Result, sizeof(Timer_Result), "%i:%i.%i", Minutes[playerid], Seconds[playerid], Milliseconds[playerid]);
    TextDrawSetString(Chiliad_Timer0[playerid], Timer_Result);
    if (Timer_Is_Stopped[playerid] != 1) Chiliad_Timer[playerid] = SetTimer("Chiliad_Counter", 100, false);
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        TextDrawShowForPlayer(playerid, Chiliad_Timer0[playerid]);
        TextDrawShowForPlayer(playerid, Chiliad_Timer1);
    }
    else if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
    {
        TextDrawHideForPlayer(playerid, Chiliad_Timer0[playerid]);
        TextDrawHideForPlayer(playerid, Chiliad_Timer1);
    }
    return 1;
}
Reply
#2

Is it possible for each player to have their own timer ??
Reply
#3

Use SetTimerEx.
Reply
#4

SetTimerEx("name", time, true/false, "i", playerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)