sm-plugins/_entWatch4/scripting/entWatch-interface.sp

172 lines
4.8 KiB
SourcePawn
Raw Normal View History

//====================================================================================================
//
// Name: [entWatch] Interface
// Author: zaCade & Prometheum
// Description: Handle the interface of [entWatch]
//
//====================================================================================================
#pragma newdecls required
#include <sourcemod>
#include <entWatch_core>
#include <entWatch_helpers>
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "[entWatch] Interface",
author = "zaCade & Prometheum",
description = "Handle the interface of [entWatch]",
version = "4.0.0"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{
CreateTimer(1.0, OnDisplayHUD, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnDisplayHUD(Handle timer)
{
2019-04-11 18:32:44 +02:00
int iZombiesCount;
int iZombies[MAXPLAYERS+1];
int iHumansCount;
int iHumans[MAXPLAYERS+1];
int iSpecsCount;
int iSpecs[MAXPLAYERS+1];
for (int client = 1; client <= MaxClients; client++)
{
2019-04-11 18:32:44 +02:00
if (!IsClientInGame(client) || IsFakeClient(client))
continue;
2019-04-11 18:32:44 +02:00
switch(GetClientTeam(client))
{
2019-04-11 18:32:44 +02:00
case(2): iZombies[iZombiesCount++] = client;
case(3): iHumans[iHumansCount++] = client;
default: iSpecs[iSpecsCount++] = client;
}
}
2019-04-11 18:32:44 +02:00
char sZombieHUD[255];
char sHumanHUD[255];
char sSpecHUD[255];
for (int index; index < EW_GetItemCount(); index++)
{
CItem item = EW_GetItemData(index);
if (item.bClient && item.dConfig.bDisplayInterface)
{
char sLine[64];
char sShort[32];
item.dConfig.GetShort(sShort, sizeof(sShort));
2019-04-11 18:32:44 +02:00
switch(item.dConfig.iMode)
{
case MODE_COOLDOWN:
{
2019-04-11 18:32:44 +02:00
if (item.iTimeReady > RoundToCeil(GetEngineTime()))
{
2019-04-11 18:32:44 +02:00
Format(sLine, sizeof(sLine), "%s [%d]: %N\n", sShort, item.iTimeReady - RoundToCeil(GetEngineTime()), item.iClient);
}
2019-04-11 18:32:44 +02:00
else
{
2019-04-11 18:32:44 +02:00
Format(sLine, sizeof(sLine), "%s [%s]: %N\n", sShort, "R", item.iClient);
}
2019-04-11 18:32:44 +02:00
}
case MODE_MAXUSES:
{
if (item.iTimesUsed < item.dConfig.iMaxUses)
{
2019-04-11 18:32:44 +02:00
Format(sLine, sizeof(sLine), "%s [%d/%d]: %N\n", sShort, item.iTimesUsed, item.dConfig.iMaxUses, item.iClient);
}
2019-04-11 18:32:44 +02:00
else
{
Format(sLine, sizeof(sLine), "%s [%s]: %N\n", sShort, "D", item.iClient);
}
}
case MODE_COOLDOWNMAXUSES:
{
if (item.iTimesUsed < item.dConfig.iMaxUses)
{
if (item.iTimeReady > RoundToCeil(GetEngineTime()))
{
2019-04-11 18:32:44 +02:00
Format(sLine, sizeof(sLine), "%s [%d]: %N\n", sShort, item.iTimeReady - RoundToCeil(GetEngineTime()), item.iClient);
}
else
{
2019-04-11 18:32:44 +02:00
Format(sLine, sizeof(sLine), "%s [%d/%d]: %N\n", sShort, item.iTimesUsed, item.dConfig.iMaxUses, item.iClient);
}
}
2019-04-11 18:32:44 +02:00
else
{
2019-04-11 18:32:44 +02:00
Format(sLine, sizeof(sLine), "%s [%s]: %N\n", sShort, "D", item.iClient);
}
}
2019-04-11 18:32:44 +02:00
case MODE_COOLDOWNCHARGES:
{
2019-04-11 18:32:44 +02:00
if (item.iTimeReady > RoundToCeil(GetEngineTime()))
{
Format(sLine, sizeof(sLine), "%s [%d]: %N\n", sShort, item.iTimeReady - RoundToCeil(GetEngineTime()), item.iClient);
}
else
{
Format(sLine, sizeof(sLine), "%s [%d/%d]: %N\n", sShort, item.iTimesUsed, item.dConfig.iMaxUses, item.iClient);
}
}
default:
{
Format(sLine, sizeof(sLine), "%s [%s]: %N\n", sShort, "N/A", item.iClient);
}
}
2019-04-11 18:32:44 +02:00
switch(GetClientTeam(item.iClient))
{
2019-04-11 18:32:44 +02:00
case(2):
{
if (strlen(sZombieHUD) + strlen(sLine) < sizeof(sZombieHUD))
{
StrCat(sZombieHUD, sizeof(sZombieHUD), sLine);
}
}
case(3):
{
if (strlen(sHumanHUD) + strlen(sLine) < sizeof(sHumanHUD))
{
StrCat(sHumanHUD, sizeof(sHumanHUD), sLine);
}
}
}
2019-04-11 18:32:44 +02:00
if (strlen(sSpecHUD) + strlen(sLine) < sizeof(sSpecHUD))
{
2019-04-11 18:32:44 +02:00
StrCat(sSpecHUD, sizeof(sSpecHUD), sLine);
}
}
}
2019-04-11 18:32:44 +02:00
Handle hZombieMessage = StartMessage("KeyHintText", iZombies, iZombiesCount);
BfWriteByte(hZombieMessage, 1);
BfWriteString(hZombieMessage, sZombieHUD);
EndMessage();
Handle hHumanMessage = StartMessage("KeyHintText", iHumans, iHumansCount);
BfWriteByte(hHumanMessage, 1);
BfWriteString(hHumanMessage, sHumanHUD);
EndMessage();
Handle hSpecMessage = StartMessage("KeyHintText", iSpecs, iSpecsCount);
BfWriteByte(hSpecMessage, 1);
BfWriteString(hSpecMessage, sSpecHUD);
EndMessage();
}