added check for seconds that hopefully should not bug out
This commit is contained in:
parent
6417676633
commit
20e73f0859
@ -2,7 +2,7 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
|
||||
float roundStartedTime = -1.0;
|
||||
int g_iTextChannel;
|
||||
bool g_bDisabled;
|
||||
ConVar g_cvEnabled;
|
||||
@ -11,14 +11,15 @@ public Plugin:myinfo =
|
||||
{
|
||||
name = "UNLOZE Console Messages",
|
||||
description = "Make console messages printed by maps more fancy",
|
||||
author = "zaCade",
|
||||
version = "1.0",
|
||||
author = "zaCade, decompiled by neon and slightly modified by jenz",
|
||||
version = "1.1",
|
||||
url = ""
|
||||
};
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_cvEnabled = CreateConVar("sm_centertext", "1", "Enable the 'game_text' message", 0, true, 0.0, true, 1.0);
|
||||
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
@ -64,6 +65,25 @@ public void OnMapStart()
|
||||
return;
|
||||
}
|
||||
|
||||
public float GetRoundTimeAtTimerEnd(number)
|
||||
{
|
||||
float g = GetCurrentRoundTime() - number;
|
||||
return g;
|
||||
}
|
||||
|
||||
public float GetCurrentRoundTime()
|
||||
{
|
||||
Handle hFreezeTime = FindConVar("mp_freezetime"); // Freezetime Handle
|
||||
int freezeTime = GetConVarInt(hFreezeTime); // Freezetime in seconds
|
||||
return GameRules_GetProp("m_iRoundTime") - ((GetEngineTime() - roundStartedTime) - freezeTime);
|
||||
}
|
||||
|
||||
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
|
||||
{
|
||||
roundStartedTime = GetEngineTime();
|
||||
}
|
||||
|
||||
|
||||
public Action PointServerCommandForward(String:sCommand[])
|
||||
{
|
||||
if (!strncmp("say", sCommand, 3, false))
|
||||
@ -75,7 +95,58 @@ public Action PointServerCommandForward(String:sCommand[])
|
||||
sMessage[i] = sCommand[i + 4];
|
||||
i++;
|
||||
}
|
||||
new String:sSecondsAppend[32];
|
||||
bool found_numeric = false;
|
||||
if (StrContains(sMessage, "sec", false) != -1)
|
||||
{
|
||||
new indexTracker = -1
|
||||
new endIndexTracker = -1
|
||||
for (new j = 0; j <= strlen(sMessage); ++j)
|
||||
{
|
||||
if (IsCharNumeric(sMessage[j]))
|
||||
{
|
||||
found_numeric = true;
|
||||
if (indexTracker == -1)
|
||||
{
|
||||
indexTracker = j;
|
||||
}
|
||||
}
|
||||
else if (found_numeric)
|
||||
{
|
||||
endIndexTracker = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found_numeric)
|
||||
{
|
||||
if (endIndexTracker == -1)
|
||||
{
|
||||
endIndexTracker = strlen(sMessage);
|
||||
}
|
||||
new String:SecondsLocal[512];
|
||||
for (new ij = indexTracker; ij <= endIndexTracker; ij++)
|
||||
{
|
||||
StrCat(SecondsLocal, sizeof(SecondsLocal), sMessage[ij]);
|
||||
}
|
||||
new number = StringToInt(SecondsLocal);
|
||||
//PrintToChatAll("number: %i", number);
|
||||
if (GetRoundTimeAtTimerEnd(number) > 0.0)
|
||||
{
|
||||
float client_time = GetRoundTimeAtTimerEnd(number);
|
||||
char sTime[32];
|
||||
FormatPlayerTime(client_time, sTime, sizeof(sTime), false, 1);
|
||||
Format(sSecondsAppend, sizeof(sSecondsAppend), " {green}@ %s", sTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found_numeric)
|
||||
{
|
||||
CPrintToChatAll("{CRIMSON}[NARRATOR] {WHITESMOKE}%s%s", sMessage, sSecondsAppend);
|
||||
}
|
||||
else
|
||||
{
|
||||
CPrintToChatAll("{CRIMSON}[NARRATOR] {WHITESMOKE}%s", sMessage);
|
||||
}
|
||||
if (!g_bDisabled)
|
||||
{
|
||||
if (g_cvEnabled.BoolValue)
|
||||
@ -109,3 +180,33 @@ public Action PointServerCommandForward(String:sCommand[])
|
||||
return Action:0;
|
||||
}
|
||||
|
||||
stock void FormatPlayerTime(float Time, char[] result, int maxlength, bool showDash, int precision)
|
||||
{
|
||||
if(Time <= 0.0 && showDash == true)
|
||||
{
|
||||
Format(result, maxlength, "-");
|
||||
return;
|
||||
}
|
||||
int hours = RoundToFloor(Time/3600);
|
||||
Time -= hours*3600;
|
||||
int minutes = RoundToFloor(Time/60);
|
||||
Time -= minutes*60;
|
||||
float seconds = Time;
|
||||
|
||||
char sPrecision[16];
|
||||
|
||||
if(precision == 0)
|
||||
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%04.1f":"%.1f", seconds);
|
||||
else if(precision == 1)
|
||||
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%06.3f":"%.3f", seconds);
|
||||
else if(precision == 2)
|
||||
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%09.6f":"%.6f", seconds);
|
||||
|
||||
if(hours > 0)
|
||||
Format(result, maxlength, "%d:%02d:%s", hours, minutes, sPrecision);
|
||||
else if(minutes > 0)
|
||||
Format(result, maxlength, "%d:%s", minutes, sPrecision);
|
||||
else
|
||||
Format(result, maxlength, "%s", sPrecision);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user