~ Checkpoint Help Please ~
#4

In seconds? You need to use a timer. When they enter the checkpoint, start a timer (SetTimerEx) with an interval of 1 second, repeating on. Use a variable to store the timer's ID and kill it when they leave a CP (OnPlayerLeaveDynamicCP) with KillTimer().

Example:

pawn Код:
new Text:gMyText1;
new cp_count = 30; // Set to 30 seconds
new cp_timer_id;

public OnGameModeInit()
{
    AddPlayerClass(188, 6, 6, 3, random(360), WEAPON_DEAGLE, 28, WEAPON_M4, 180, WEAPON_GRENADE,  1);
    Checkpoint[0] = CreateDynamicCP(-36.5200,-5.2453,3.1094,2,0,0);
    return 1;
}

public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == Checkpoint[0] && gTeam[playerid] == TEAM_GANG && cp_count == 31)
    {
        cp_count--; // Set to 30, this lets you know that the timer is active
        gMyText1 = TextDrawCreate(280, 435, "CP TIME: 30");
        TextDrawFont(gMyText1, 1);
        TextDrawAlignment(gMyText1, 2);
        TextDrawSetShadow(gMyText1, 0);
        TextDrawSetOutline(gMyText1, 1);
        TextDrawShowForAll(gMyText1);
        cp_timer_id = SetTimer("cp_timer", 888, true); // Timers are slow, 888 MS is around a second.
    }
}

public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
    if(checkpointid == Checkpoint[0] && gTeam[playerid] == TEAM_GANG && cp_count < 31)
    {
        KillTimer(cp_timer_id);
        TextDrawDestroy(gMyText1);
        cp_count = 31; // Set back to 30 so we know it's stopped
    }
    return 1;
}

forward cp_timer();
public cp_timer()
{
    cp_count--;
    if(cp_count == 0)
    {
        // Reached 0, give score or whatever
        KillTimer(cp_timer_id);
        TextDrawDestroy(gMyText1);
        cp_count = 31; // So we know the timer isn't running
    }
    else // Still counting
    {
        new tds[32];
        format(tds, sizeof(tds), "CP TIME: %i", cp_count);
        TextDrawSetString(gMyText1, tds);
    }
    return 1;
}
Please note that this isn't tested, and I'm not sure if it will even compile. It looks fine to me.
Reply


Messages In This Thread
~ Checkpoint Help Please ~ - by theinformer - 28.12.2011, 02:37
Re: ~ Checkpoint Help Please ~ - by MP2 - 28.12.2011, 03:02
Re: ~ Checkpoint Help Please ~ - by theinformer - 28.12.2011, 03:09
Re: ~ Checkpoint Help Please ~ - by MP2 - 28.12.2011, 03:16
Re: ~ Checkpoint Help Please ~ - by theinformer - 28.12.2011, 15:16
Re: ~ Checkpoint Help Please ~ - by MP2 - 28.12.2011, 16:30
Re: ~ Checkpoint Help Please ~ - by theinformer - 28.12.2011, 16:59
Re: ~ Checkpoint Help Please ~ - by MP2 - 28.12.2011, 18:36
Re: ~ Checkpoint Help Please ~ - by theinformer - 28.12.2011, 19:00
Re: ~ Checkpoint Help Please ~ - by MP2 - 28.12.2011, 21:45

Forum Jump:


Users browsing this thread: 1 Guest(s)