Raised This Month: $ Target: $400
 0% 

[TF2] Get the time left in a round


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
DarthNinja
SourceMod Plugin Approver
Join Date: Mar 2009
Location: PreThinkHook()
Old 09-10-2010 , 08:33   [TF2] Get the time left in a round
Reply With Quote #1

Here is a way to get exactly how much time is left in the round:
Code should be self explanatory.


PHP Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>


#define PLUGIN_VERSION "1.0.0"

new g_StartTime;
new 
g_AdditionalTime 0;

public 
Plugin:myinfo 
{
    
name "[DEV] Get Round Time Left",
    
author "DarthNinja",
    
description "This was a BITCH",
    
version PLUGIN_VERSION,
    
url "DarthNinja.com"
}

public 
OnPluginStart()
{
    
CreateConVar("sm_roundtime_version"PLUGIN_VERSION"Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
    
RegConsoleCmd("sm_roundtime"Command_Debug);

    
HookEvent("teamplay_setup_finished"EventSetupEnd);
    
HookEvent("teamplay_timer_time_added"EventTimeAdded);
}

public 
Action:EventSetupEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_StartTime GetTime()
    
PrintToChatAll("RoundStart TimeStamp Logged: %i"g_StartTime)
    
g_AdditionalTime 0;
}

public 
Action:EventTimeAdded(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
iAddedTime GetEventInt(event"seconds_added")
    
g_AdditionalTime g_AdditionalTime iAddedTime;
    
PrintToChatAll("Time added: %i"iAddedTime)
}


public 
Action:Command_Debug(clientargs)
{
    
PrintToChatAll("-----------------------------------------")
    
    
//Alright bitch, play tiemz ovar
    
new SecElapsed GetTime() - g_StartTime;
    
PrintToChatAll("%i Seconds have elapsed since the round started"SecElapsed)
    
    
//Get round time that the round started with
    
new ent FindEntityByClassname(MaxClients+1"team_round_timer");
    new 
Float:RoundStartLength GetEntPropFloat(entProp_Send"m_flTimeRemaining");
    
PrintToChatAll("Float:RoundStartLength == %f"RoundStartLength)
    new 
iRoundStartLength RoundToZero(RoundStartLength)
    
PrintToChatAll("Int:iRoundStartLength == %i"iRoundStartLength)
    
    
    
//g_AdditionalTime = time added this round
    
PrintToChatAll("TimeAdded This Round: %i"g_AdditionalTime)
    
    new 
TimeBuffer iRoundStartLength g_AdditionalTime;
    new 
TimeLeft TimeBuffer SecElapsed;
    
PrintToChatAll("TimeLeft Sec: %i"TimeLeft)
    
    
PrintToChatAll("TimeLeft Min: %i~"TimeLeft/60)
    
    new 
timeleftMIN TimeLeft/60;
    new 
Sec TimeLeft-(timeleftMIN*60)
    
PrintToChatAll("<<EXACT TIME LEFT>> :: |||%i:%02i|||"TimeLeft/60,Sec)
    
    
PrintToChatAll("-----------------------------------------")
    return 
Plugin_Handled;

This is a fully working plugin, you can use the command and it will output something like this:
http://img825.**************/img825/1599/1039538834.jpg
http://img825.**************/img825/8148/1039540104.jpg
http://img825.**************/img825/8113/1039546044.jpg

Note that this code only works correctly during rounds, not before or after.
Attached Files
File Type: sp Get Plugin or Get Source (GetRoundTime.sp - 793 views - 2.3 KB)
__________________
DarthNinja is offline
 



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 22:53.


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