How to divided a timer when its already counting down
#1

Hello how do a divide a timer by like 2 when a timer is already being counted down so like when somebody captures a gangzone

My code to setup the timer:
pawn Код:
timer[playerid][Land] = SetTimerEx("SetZone",30000, false, "i", playerid);
Reply
#2

Simple , kill the current and start the another time but : start > kill ;
Reply
#3

But then how i know what the current timer was so like if someone stands in the checkpoints and a team mate joins
after capture it for 10 seconds? or 20 etc
Reply
#4

Why not get the amount of players in the certain area, then deduct that from the total time? Example: There is 1 player in the area, and the timer is deducting 1 point every second. Another player enters and the timer then begins to deduct 2 points every second, having the same effect as halving the timer, where when the points reach or go below 0, the timer stops and the zone is then captured.

Further Example of code:
pawn Код:
ZonePoints[RedZone] = 30; //We want to have 30 seconds for a single player, so we will use 30 points.
SetTimer("CaptureRedZone", 1000, true); //Timer will repeat, every second.

forward CaptureRedZone();
public CaptureRedZone()
{
    new count = 0; //Begin the count at 0 players.
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i)) //foreach is a better alternative
        {
            if(IsPlayerInRangeOfPoint(i, range, X, Y, Z)) //Check if they are in, or near the area, you can use your own custom functions/stocks instead of IsPlayerInRangeOfPoint if you want.
            {
                if(gTeam[i] != TEAM_RED) //Check if the zone does not belong to them
                {
                    count++;
                    continue;
                }
            }
        }
    }
    if(count == 0) return ZonePoints[RedZone] = 30; //Reset the points if the players leave the area.
    ZonePoints[RedZone] = ZonePoints[RedZone] - count;
    if(ZonePoints[RedZone] <= 0)
    {
        SendClientMessageToAll(0xFF0000FF, "The red zone has been captured.");
        KillTimer("ZoneCapture"); //This won't work, but you can change it accordingly so it no longer continues to countZonePoints[RedZone] = 0;
        //Capture area etc.
    }
    return 1;
}
This is an example, probably not the best method available, but should work properly.
Reply
#5

You could
A: Use GetTickCount like ****** said to check the difference on times (on a specific events).
B: Use a 1 second repeating timer that adds one to a variable every single second. That way you could tell how long the timer has been going for and be able to cancel it when the timer is up.
Reply
#6

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
Why not get the amount of players in the certain area, then deduct that from the total time? Example: There is 1 player in the area, and the timer is deducting 1 point every second. Another player enters and the timer then begins to deduct 2 points every second, having the same effect as halving the timer, where when the points reach or go below 0, the timer stops and the zone is then captured.

Further Example of code:
pawn Код:
ZonePoints[RedZone] = 30; //We want to have 30 seconds for a single player, so we will use 30 points.
SetTimer("CaptureRedZone", 1000, true); //Timer will repeat, every second.

forward CaptureRedZone();
public CaptureRedZone()
{
    new count = 0; //Begin the count at 0 players.
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i)) //foreach is a better alternative
        {
            if(IsPlayerInRangeOfPoint(i, range, X, Y, Z)) //Check if they are in, or near the area, you can use your own custom functions/stocks instead of IsPlayerInRangeOfPoint if you want.
            {
                if(gTeam[i] != TEAM_RED) //Check if the zone does not belong to them
                {
                    count++;
                    continue;
                }
            }
        }
    }
    if(count == 0) return ZonePoints[RedZone] = 30; //Reset the points if the players leave the area.
    ZonePoints[RedZone] = ZonePoints[RedZone] - count;
    if(ZonePoints[RedZone] <= 0)
    {
        SendClientMessageToAll(0xFF0000FF, "The red zone has been captured.");
        KillTimer("ZoneCapture"); //This won't work, but you can change it accordingly so it no longer continues to countZonePoints[RedZone] = 0;
        //Capture area etc.
    }
    return 1;
}
This is an example, probably not the best method available, but should work properly.
Yes i think i need this this works for dynamiccheckpoints aswell?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)