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

[L4D2] Round Duration (Timer)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gashi
New Member
Join Date: Oct 2013
Old 10-22-2013 , 17:24   [L4D2] Round Duration (Timer)
Reply With Quote #1

hello,

i saw this Thread @ http://forums.alliedmods.net/showthread.php?t=227995

And i need exactly this plugin, but this doenst work fine:
PHP Code:
#include <sourcemod>
#include <sdktools>

new bool:g_Round;
new 
g_Count;

public 
Plugin:myinfo 
{
    
name "l4d2_duration",
    
author "RU_6uK",
    
description "Duration of map played",
    
version "0.0",
    
url "http://forums.alliedmods.net"
}

public 
OnPluginStart()
{
    
HookEvent(    "round_start",    Event_Round    );
    
HookEvent(    "round_end",    Event_Round    );
}

public 
OnMapStart()
{
    
g_Round true;
}

public 
Action:Event_Round(Handle:event, const String:name[], bool:dontBroadcast)  
{
    if ( 
g_Round == true )
    {
        
g_Count 0;
        
CreateTimer1.0Timer_RoundCount_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE );
        
g_Round false;
    }
    else
    {
        
g_Round true;
    }
}

public 
Action:Timer_RoundCountHandle:timerany:client )
{
    
g_Count ++;
    if ( 
g_Round == false )
    {
        return 
Plugin_Continue;
    }
    else
    {
        
// Do the math here.. i lazy
        // Note that the timer ticking every 1.0 sec once. With +1 sec gape.
        
new min g_Count/60;
        new 
sec g_Count min;
        
        
        
PrintToChatAll"[ROUNDDURATION]: %d min | %d sec"minsec );
    }
    return 
Plugin_Stop;

But it shows me [ROUNDDURATION]: 6 min | 122 sec

Or if a say slay @all it shows: [ROUNDDURATION]: 0 min | 15 sec (= always)

Iam a noob, how can i fix this?

Thanks in advance

Last edited by Gashi; 10-22-2013 at 17:24.
Gashi is offline
Gugie
Member
Join Date: Jul 2012
Old 10-23-2013 , 01:14   Re: [L4D2] Round Duration (Timer)
Reply With Quote #2

new sec = g_Count - min*60;
Gugie is offline
Gashi
New Member
Join Date: Oct 2013
Old 10-23-2013 , 07:35   Re: [L4D2] Round Duration (Timer)
Reply With Quote #3

Quote:
Originally Posted by Gugie View Post
new sec = g_Count - min*60;
Thank you! I will try it later ;)
Gashi is offline
noxman
Member
Join Date: Jun 2012
Old 10-23-2013 , 08:49   Re: [L4D2] Round Duration (Timer)
Reply With Quote #4

Sometimes it works, sometimes it shows:

[ROUNDDURATION] 0 min | 15 sec

What is wrong with the code??
noxman is offline
RU_6uK
SourceMod Donor
Join Date: May 2010
Old 10-23-2013 , 15:22   Re: [L4D2] Round Duration (Timer)
Reply With Quote #5

W/o timer, not tested.

PHP Code:
new Float:g_fSeconds;

public 
OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStartEventHookMode_PostNoCopy);
    
HookEvent("round_end"Event_RoundEndEventHookMode_PostNoCopy);
}

public 
Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_fSeconds GetEngineTime();
}

public 
Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
secDiff RoundToFloor(GetEngineTime() - g_fSeconds);
    
PrintToChatAll("[ROUNDDURATION]: %02i min | %02i sec"secDiff 60secDiff 60);


Last edited by RU_6uK; 10-23-2013 at 15:29.
RU_6uK is offline
noxman
Member
Join Date: Jun 2012
Old 10-23-2013 , 16:13   Re: [L4D2] Round Duration (Timer)
Reply With Quote #6

Quote:
Originally Posted by RU_6uK View Post
W/o timer, not tested.
Thanks. It works, but one little bug:

If the round is end it shows: [ROUNDDURATION] 5 min | 10 sec ( = right)

but after 10 sec a new message comes up: [ROUNDDURATION] 5min | 20 sec

Bugg: On round_end the message come 2 times. hmmm
noxman is offline
RU_6uK
SourceMod Donor
Join Date: May 2010
Old 10-23-2013 , 18:55   Re: [L4D2] Round Duration (Timer)
Reply With Quote #7

It's game bug, when event fires several times.

PHP Code:
new Float:g_fSeconds;
new 
bool:g_bRoundEnd;

public 
OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStartEventHookMode_PostNoCopy);
    
HookEvent("round_end"Event_RoundEndEventHookMode_PostNoCopy);
}

public 
Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_fSeconds GetEngineTime();
    
g_bRoundEnd false;
}

public 
Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
g_bRoundEnd) {
        new 
secDiff RoundToFloor(GetEngineTime() - g_fSeconds);
        
PrintToChatAll("[ROUNDDURATION]: %02i min | %02i sec"secDiff 60secDiff 60);
        
g_bRoundEnd true;
    }

RU_6uK is offline
noxman
Member
Join Date: Jun 2012
Old 10-24-2013 , 10:31   Re: [L4D2] Round Duration (Timer)
Reply With Quote #8

Quote:
Originally Posted by RU_6uK View Post
It's game bug, when event fires several times.

PHP Code:
new Float:g_fSeconds;
new 
bool:g_bRoundEnd;

public 
OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStartEventHookMode_PostNoCopy);
    
HookEvent("round_end"Event_RoundEndEventHookMode_PostNoCopy);
}

public 
Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_fSeconds GetEngineTime();
    
g_bRoundEnd false;
}

public 
Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
g_bRoundEnd) {
        new 
secDiff RoundToFloor(GetEngineTime() - g_fSeconds);
        
PrintToChatAll("[ROUNDDURATION]: %02i min | %02i sec"secDiff 60secDiff 60);
        
g_bRoundEnd true;
    }

This one works perfect. Thank you
noxman is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 05-23-2022 , 12:59   Re: [L4D2] Round Duration (Timer)
Reply With Quote #9

Updating it, and adding "sm_duration" command

PHP Code:
float g_fSeconds;
bool g_bRoundEnd;

public 
Plugin myinfo 
{
    
name "Round Duration",
    
author "RU_6uK, alasfourom",
    
description "Print Current Round Duration",
    
version "1.0",
    
url "https://forums.alliedmods.net/"
};

public 
void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);

    
RegConsoleCmd("sm_duration"Duration"Print Round Duration To Chat");
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    
g_fSeconds GetEngineTime();
    
g_bRoundEnd false;
    return 
Plugin_Handled;
}

public 
Action Duration(int clientint args)
{
    
int secDiff RoundToFloor(GetEngineTime() - g_fSeconds);
    
ReplyToCommand(client"\x04Round Duration: \x03%i min %i sec"secDiff 60secDiff 60);
    return 
Plugin_Handled;
}

//Printing Round Duration At The End Of The Round
public Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    if(!
g_bRoundEnd) {
        
int secDiff RoundToFloor(GetEngineTime() - g_fSeconds);
        
PrintToChatAll("\x04Round Duration: \x03%i min %i sec"secDiff 60secDiff 60);
        
g_bRoundEnd true;
    }
    return 
Plugin_Handled;

Attached Files
File Type: sp Get Plugin or Get Source (Round Duration.sp - 427 views - 1.2 KB)

Last edited by alasfourom; 06-29-2022 at 17:20.
alasfourom 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 19:56.


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