Raised This Month: $114 Target: $400
 28% 

Timer Issue


Post New Thread Reply   
 
Thread Tools Display Modes
XiLuo
Junior Member
Join Date: Mar 2018
Old 12-29-2018 , 05:44   Re: Timer Issue
Reply With Quote #11

I guess it not be,timer repeat issue is the most easier wrong,timer can kill(initialize) by onMapStart(),onMapEnd(),
RoundStart or RoundEnd.
The best way to deal timer issue is that consider original timer.
Every time to create timer should to consider the last timer had been killed? Or timer may will repeat and stack
more
XiLuo is offline
XiLuo
Junior Member
Join Date: Mar 2018
Old 12-29-2018 , 05:47   Re: Timer Issue
Reply With Quote #12

I perfectly agree with 1337norway ,try many times you will know how event,timer work.
XiLuo is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 12-29-2018 , 06:00   Re: Timer Issue
Reply With Quote #13

PHP Code:

Handle hTimer
;

public 
void OnMapEnd()
{
    
delete hTimer;
}

public 
Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
delete hTimer;
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    
g_iCountdown 30;
    
    
hTimer CreateTimer(1.0EndZoneCheck_TIMER_REPEAT);
}

public 
Action EndZoneCheck(Handle timerany data)
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i) && coursetimer_InEndZone(i))
        {
            
EmitSoundToAll("training/countdown.wav"iSNDCHAN_VOICESNDLEVEL_RAIDSIREN);
            
PrintToChatAll("[SM] \x07%N \x02has reached the end!"i);
            
PrintToChatAll("[SM] \x0330 seconds remaining to complete the map.");
            
            
ForcePlayerSuicide(i);
            
            
hTimer CreateTimer(1.0Timer_CountdownGetClientUserId(i), TIMER_REPEAT);
            return 
Plugin_Stop;
        }
    }
    
    return 
Plugin_Continue;
}

public 
Action Timer_Countdown(Handle timerany data)
{
    
int client GetClientOfUserId(data);

    if (
g_iCountdown && IsClientInGame(client))
    {
        if ((
g_iCountdown == 20) || (g_iCountdown == 10) || (g_iCountdown == 5) || (g_iCountdown 4))
        {
            if (
g_iCountdown == 1)
            {
                
PrintToChatAll("[SM] \x03%d second remaining to complete the map."g_iCountdown);
                
                for (
int i 1<= MaxClients; ++i)
                {
                    if(
IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) > 1)
                    {
                        
ForcePlayerSuicide(i);
                    }
                }
                
                
hTimer null;
                return 
Plugin_Stop;
            }
        }
        else 
        {
            
PrintToChatAll("[SM] \x03%d seconds remaining to complete the map."g_iCountdown);
        }
        
        
g_iCountdown--;
    }
    
    return 
Plugin_Continue;

__________________

Last edited by Ilusion9; 12-29-2018 at 06:01.
Ilusion9 is offline
Lubricant Jam
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 12-29-2018 , 06:41   Re: Timer Issue
Reply With Quote #14

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:

Handle hTimer
;

public 
void OnMapEnd()
{
    
delete hTimer;
}

public 
Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
delete hTimer;
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    
g_iCountdown 30;
    
    
hTimer CreateTimer(1.0EndZoneCheck_TIMER_REPEAT);
}

public 
Action EndZoneCheck(Handle timerany data)
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i) && coursetimer_InEndZone(i))
        {
            
EmitSoundToAll("training/countdown.wav"iSNDCHAN_VOICESNDLEVEL_RAIDSIREN);
            
PrintToChatAll("[SM] \x07%N \x02has reached the end!"i);
            
PrintToChatAll("[SM] \x0330 seconds remaining to complete the map.");
            
            
ForcePlayerSuicide(i);
            
            
hTimer CreateTimer(1.0Timer_CountdownGetClientUserId(i), TIMER_REPEAT);
            return 
Plugin_Stop;
        }
    }
    
    return 
Plugin_Continue;
}

public 
Action Timer_Countdown(Handle timerany data)
{
    
int client GetClientOfUserId(data);

    if (
g_iCountdown && IsClientInGame(client))
    {
        if ((
g_iCountdown == 20) || (g_iCountdown == 10) || (g_iCountdown == 5) || (g_iCountdown 4))
        {
            if (
g_iCountdown == 1)
            {
                
PrintToChatAll("[SM] \x03%d second remaining to complete the map."g_iCountdown);
                
                for (
int i 1<= MaxClients; ++i)
                {
                    if(
IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) > 1)
                    {
                        
ForcePlayerSuicide(i);
                    }
                }
                
                
hTimer null;
                return 
Plugin_Stop;
            }
        }
        else 
        {
            
PrintToChatAll("[SM] \x03%d seconds remaining to complete the map."g_iCountdown);
        }
        
        
g_iCountdown--;
    }
    
    return 
Plugin_Continue;

This fixed my issue, thanks a bunch!
Lubricant Jam is offline
Lubricant Jam
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 12-29-2018 , 09:21   Re: Timer Issue
Reply With Quote #15

Okay it works however if you are the last person alive and complete the map, the timer still runs on the next round so it's not completely fixed.
Lubricant Jam is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 12-29-2018 , 10:00   Re: Timer Issue
Reply With Quote #16

How are you checking to see if the person completes the map or not? Is it based on a zone or something? i'm assuming you just have to do the same thing with the timer on that event. Kill the timer or delete the handle and it should be fine
backwards is offline
Lubricant Jam
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 12-29-2018 , 10:10   Re: Timer Issue
Reply With Quote #17

Quote:
Originally Posted by 1337norway View Post
How are you checking to see if the person completes the map or not? Is it based on a zone or something? i'm assuming you just have to do the same thing with the timer on that event. Kill the timer or delete the handle and it should be fine
Using a native I made from the timer, works perfectly fine it's just the timer that causes the problem. I think I've sorted it, I'll have to test further.

Code:
public Action EndZoneCheck(Handle timer, int userid)
{
    for (int i = 1; i <= MaxClients; i++)
    {
		if (IsClientInGame(i) && coursetimer_InEndZone(i) && IsPlayerAlive(i))
		{
			if (g_iCompleted == 0) {
				EmitSoundToAll("training/countdown.wav", i, SNDCHAN_VOICE, SNDLEVEL_RAIDSIREN);
				ForcePlayerSuicide(i);
				if (IsClientInGame(i) && (coursetimer_CurrentStyle(i) >= 4) < 4 && IsPlayerAlive(i))
				{
					PrintToChatAll("[SM] \x07%N \x02has reached the end!", i);
					PrintToChatAll("[SM] \x0330 seconds remaining to complete the map.");
					hTimer = CreateTimer(1.0, Timer_Countdown, GetClientUserId(i), TIMER_REPEAT);
					g_iCompleted++;
				} else hTimer = null;
				return Plugin_Stop;
			}
		}
	}

	return Plugin_Continue;
}
Lubricant Jam is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 12-29-2018 , 10:34   Re: Timer Issue
Reply With Quote #18

Quote:
Originally Posted by Lubricant Jam View Post
Okay it works however if you are the last person alive and complete the map, the timer still runs on the next round so it's not completely fixed.
PHP Code:

public Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
delete hTimer;

you must hook the round_end event.
__________________
Ilusion9 is offline
Lubricant Jam
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 12-29-2018 , 10:42   Re: Timer Issue
Reply With Quote #19

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:

public Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
delete hTimer;

you must hook the round_end event.
Yes, it is hooked. I even tried making a delay to see if that would help also, still no luck.

Code:
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
	delete hTimer;
	CreateTimer(1.0, ClearTimer);
}

public Action ClearTimer(Handle timer)
{
	delete hTimer;
}
EDIT: Do you want me to hook it to round_end or round_officially_end?

Last edited by Lubricant Jam; 12-29-2018 at 10:46.
Lubricant Jam is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-29-2018 , 10:50   Re: Timer Issue
Reply With Quote #20

What game is this ?
Bacardi is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:21.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode