Raised This Month: $32 Target: $400
 8% 

CSGO Timer problem - firing in random moments.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lechoo
Member
Join Date: Jul 2010
Location: Poland
Old 06-26-2015 , 05:07   CSGO Timer problem - firing in random moments.
Reply With Quote #1

Hello guys. I'm having CSGO server with my own made plugin. There is no need to write what plugin is that, it allows Free-for-all mode if players want so. I was looking for good idea to block round end with "mp_teammates_are_enemies" and "mp_ignore_round_win_conditions" (but in many ideas teams wasn't getting their points because of teammates are enemies). After few tries i made this:
PHP Code:
public Event_RoundFreezeEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
Float:roundtime=GetConVarFloat(FindConVar("mp_roundtime"))*60.0;
    
handlez1=CreateTimer(roundtime-5.5,PrepareEnd,_,TIMER_FLAG_NO_MAPCHANGE);
}
public 
Action:PrepareEnd(Handle:timer)
{
    
handlez2=CreateTimer(0.1,EndInfo,_,TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
    
handlez3=CreateTimer(5.2,EndSlay,_,TIMER_FLAG_NO_MAPCHANGE);
    
counting=5.0;
    
handlez1=INVALID_HANDLE;
}
public 
Action:EndInfo(Handle:timer)
{
    if(
counting>0)
    {
        
PrintHintTextToAll("Round will end in: %0.1f seconds.",counting);
        
counting=counting-0.1;
        if(
counting<0.2 && couting>0.0)
        {
            
ServerCommand("mp_teammates_are_enemies 0");
            
ServerCommand("mp_ignore_round_win_conditions 0");
        }
    } else
    {
        if(
handlez2!=INVALID_HANDLE)
        {
            
KillTimer(handlez2);
            
handlez2=INVALID_HANDLE;
        }
    }
}
public 
Action:EndSlay(Handle:timer)
{
    
PrintHintTextToAll("Round has ended, everyone will be slayed.");
    for (new 
i=1i<=GetMaxClients(); i++)
    {
        if (
IsClientInGame(i) && !IsClientObserver(i) && IsPlayerAlive(i))
        {
            new 
deaths GetEntProp(iProp_Data"m_iDeaths");
            
SetEntProp(iProp_Data"m_iDeaths"deaths-1);
            new 
kills GetEntProp(iProp_Data"m_iFrags");
            
SetEntProp(iProp_Data"m_iFrags"kills+1);
            
ForcePlayerSuicide(i);
        }
    }
    
handlez3=INVALID_HANDLE;

If only 1 player stays alive, I'm using this to end round after 'his win':
PHP Code:
public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
alive=0;
    for(new 
i=1i<=GetMaxClients(); i++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i))
        {
            
alive++;
        }
    }
    if(
alive==1)
    {
        if(
handlez1!=INVALID_HANDLE)
        {
            
KillTimer(handlez1)
            
handlez1=INVALID_HANDLE
        
}
        if(
handlez2!=INVALID_HANDLE)
        {
            
KillTimer(handlez2);
            
handlez2=INVALID_HANDLE;
        }
        if(
handlez3!=INVALID_HANDLE)
        {
            
KillTimer(handlez3);
            
handlez3=INVALID_HANDLE;
        }
        
handlez1=CreateTimer(0.1,PrepareEnd);
    }

The problem is that PrepareEnd timer sometimes is firing in random moments in random rounds, slaying all players without reason. This is list of my hooked events, if it helps in anything:
PHP Code:
HookEvent("round_freeze_end"Event_RoundFreezeEnd,EventHookMode_PostNoCopy);
HookEvent("player_death"Event_PlayerDeathEventHookMode_Pre);
HookEvent("round_end"Event_RoundEnd); 
Of course I'm killing all timers on round end (using the same way like in Event_PlayerDeath), also I set all handles to INVALID_HANDLE on map start, because I'm using TIMER_FLAG_NO_MAPCHANGE.

What is the problem here?
__________________
Sorry for my bad English

Last edited by lechoo; 06-26-2015 at 05:24. Reason: bugged bbcode
lechoo is offline
Send a message via Skype™ to lechoo
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-26-2015 , 18:27   Re: CSGO Timer problem - firing in random moments.
Reply With Quote #2

Simply ensure that handlez1 == INVALID_HANDLE before calling CreateTimer. If it is "!= INVALID_HANDLE", kill it & call CreateTimer once again.

You probably have a scenario where 2 PrepareEnd exist at the same time. (i.e. warmup problem, or the initial round where someone is waiting for an opponent to spawn to initiate the "match" (I don't know your Event_RoundEnd code; you may be escaping such a scenario); it may also be related to hibernating (ugh; I've had unreproducible strange timer problem with hibernation ) ).

Red
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 06-26-2015 at 18:32.
RedSword is offline
lechoo
Member
Join Date: Jul 2010
Location: Poland
Old 06-27-2015 , 08:49   Re: CSGO Timer problem - firing in random moments.
Reply With Quote #3

On round end I'm killing all existing timers and changing some cvars (mp_teammates_are_enemies etc), so there is not fault here.

My server is not hibernating, I'm using sv_hibernate_when_empty 0. I'll try checking if timer exist before creating new timer, maybe this will help. I'll give you info when I'll try that.
__________________
Sorry for my bad English

Last edited by lechoo; 06-27-2015 at 08:50.
lechoo is offline
Send a message via Skype™ to lechoo
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-27-2015 , 14:38   Re: CSGO Timer problem - firing in random moments.
Reply With Quote #4

Quote:
Originally Posted by lechoo View Post
so there is not fault here
iirc, at least in CSS, round_end isn't guaranteed to fire for every round_start. It does for "normal" play however. I.e. if you were to do mp_restartgame 1, I believe round_end wouldn't be triggered.

Red
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword is offline
lechoo
Member
Join Date: Jul 2010
Location: Poland
Old 07-02-2015 , 06:54   Re: CSGO Timer problem - firing in random moments.
Reply With Quote #5

Hm.. Ok, I've added debug and there are no double timers already, but I've found another problem.
I set the timer to roundtime - 5.5 seconds. Roundtime is set to 9 minutes every round (or 15 minutes in the last round). Plugin is slaying players too early, for example after 6-7 minutes. Why this happens? I was reading about timers' accuracy and dependence from tickrate, but 2 minutes? :c
__________________
Sorry for my bad English

Last edited by lechoo; 07-02-2015 at 06:54.
lechoo is offline
Send a message via Skype™ to lechoo
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 07-02-2015 , 09:55   Re: CSGO Timer problem - firing in random moments.
Reply With Quote #6

Is that occurring only during the first rounds ? If so I'd believe that what I said is happening. Could you post the updated code ?

Red
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword is offline
lechoo
Member
Join Date: Jul 2010
Location: Poland
Old 07-02-2015 , 15:40   Re: CSGO Timer problem - firing in random moments.
Reply With Quote #7

It is happening independently from round number, so there is no fault there. (I also set all handles to Invalid each round_start)

Nothing changed from prev. code, I've just added statements like:
Code:
if(handle1!=INVALID_HANDLE)
{
          KillTimer(1);
          handle1=INVALID_HANDLE;
}
In the beggining of every timer and some say debug at the end of every timer to let me now, when timer is firing.
__________________
Sorry for my bad English

Last edited by lechoo; 07-02-2015 at 15:42.
lechoo is offline
Send a message via Skype™ to lechoo
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 07-02-2015 , 18:31   Re: CSGO Timer problem - firing in random moments.
Reply With Quote #8

Quote:
Originally Posted by lechoo View Post
It is happening independently from round number, so there is no fault there. (I also set all handles to Invalid each round_start)

Nothing changed from prev. code, I've just added statements like:
Code:
if(handle1!=INVALID_HANDLE)
{
          KillTimer(1);
          handle1=INVALID_HANDLE;
}
In the beggining of every timer and some say debug at the end of every timer to let me now, when timer is firing.
"KillTimer(1);" ? I'm pretty sure you should get an error there.

And what it "round number" ?

"In the beggining of every timer" ; you mean before creating the timer right ?
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword is offline
Reply



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 21:05.


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