sm-plugins/unloze_ConsoleMessages/scripting/unloze_ConsoleMessages.sp

214 lines
5.4 KiB
SourcePawn
Raw Normal View History

2021-08-08 23:10:22 +02:00
#include <multicolors>
#include <sourcemod>
#include <sdktools>
2021-08-15 13:27:59 +02:00
#include <pscd>
#pragma newdecls required
2021-08-08 23:10:22 +02:00
float roundStartedTime = -1.0;
2021-08-08 23:10:22 +02:00
int g_iTextChannel;
bool g_bDisabled;
ConVar g_cvEnabled;
2021-08-15 13:27:59 +02:00
public Plugin myinfo =
2021-08-08 23:10:22 +02:00
{
name = "UNLOZE Console Messages",
description = "Make console messages printed by maps more fancy",
2021-08-15 13:27:59 +02:00
author = "zaCade, decompiled by Neon and slightly modified by jenz",
version = "1.2",
2021-08-08 23:10:22 +02:00
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);
2021-08-08 23:10:22 +02:00
}
public void OnMapStart()
{
2021-08-15 13:27:59 +02:00
bool bChannelTaken[6];
bool bChannelFound;
int entity = -1;
2021-08-08 23:10:22 +02:00
while ((entity = FindEntityByClassname(entity, "game_text")) != -1)
{
2021-08-15 13:27:59 +02:00
int channel = GetEntProp(entity, Prop_Data, "m_textParms.channel", 4, 0);
2021-08-08 23:10:22 +02:00
LogMessage("Checking channel: %d", channel);
if (channel < 6)
{
if (!bChannelTaken[channel])
{
LogMessage("Channel in use: %d", channel);
bChannelTaken[channel] = true;
}
}
}
2021-08-15 13:27:59 +02:00
int channel;
2021-08-08 23:10:22 +02:00
while (channel < 6)
{
if (!bChannelTaken[channel])
{
LogMessage("Using channel: %d", channel);
g_iTextChannel = channel;
bChannelFound = true;
if (!bChannelFound)
{
LogMessage("No channel found!");
g_bDisabled = true;
}
return;
}
channel++;
}
if (!bChannelFound)
{
LogMessage("No channel found!");
g_bDisabled = true;
}
return;
}
2021-08-15 13:27:59 +02:00
public float GetRoundTimeAtTimerEnd(int 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();
}
2021-08-15 13:27:59 +02:00
public Action PointServerCommandForward(const char[] sCommand)
2021-08-08 23:10:22 +02:00
{
if (!strncmp("say", sCommand, 3, false))
{
2021-08-15 13:27:59 +02:00
char sMessage[512];
char sSecondsAppend[32];
bool found_numeric = false;
int i;
2021-08-08 23:10:22 +02:00
while (strlen(sCommand) + -4 > i)
{
sMessage[i] = sCommand[i + 4];
i++;
}
if (StrContains(sMessage, "sec", false) != -1)
{
2021-08-15 13:27:59 +02:00
int indexTracker = -1
int endIndexTracker = -1
for (int 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);
}
2021-08-15 13:27:59 +02:00
char SecondsLocal[512];
for (int ij = indexTracker; ij < endIndexTracker; ij++)
{
StrCat(SecondsLocal, sizeof(SecondsLocal), sMessage[ij]);
}
2021-08-15 13:27:59 +02:00
int 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);
}
2021-08-08 23:10:22 +02:00
if (!g_bDisabled)
{
if (g_cvEnabled.BoolValue)
{
2021-08-15 13:27:59 +02:00
Handle hMessage = StartMessageAll("HudMsg", 0);
2021-08-08 23:10:22 +02:00
if (hMessage)
{
BfWriteByte(hMessage, g_iTextChannel);
BfWriteFloat(hMessage, -1.0);
BfWriteFloat(hMessage, 0.15);
BfWriteByte(hMessage, 200);
BfWriteByte(hMessage, 200);
BfWriteByte(hMessage, 200);
BfWriteByte(hMessage, 255);
BfWriteByte(hMessage, 200);
BfWriteByte(hMessage, 200);
BfWriteByte(hMessage, 200);
BfWriteByte(hMessage, 255);
BfWriteByte(hMessage, 0);
BfWriteFloat(hMessage, 0.5);
BfWriteFloat(hMessage, 0.0);
BfWriteFloat(hMessage, 5.0);
BfWriteFloat(hMessage, 0.0);
BfWriteString(hMessage, sMessage);
EndMessage();
}
}
}
2021-08-15 13:27:59 +02:00
return Plugin_Handled;
2021-08-08 23:10:22 +02:00
}
2021-08-15 13:27:59 +02:00
return Plugin_Continue;
2021-08-08 23:10:22 +02:00
}
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);
}