Ctimer moved

This commit is contained in:
Pan32 2021-12-12 21:01:05 +00:00
parent 4ba452c9a9
commit 77e0ba70de
9 changed files with 0 additions and 2275 deletions

View File

@ -1,188 +0,0 @@
#pragma semicolon 1
#define PLUGIN_AUTHOR "TRANSLUCENT"
#define PLUGIN_VERSION "0.62wtf"
#define MAXLENGTH_MESSAGE 256
#define STARTZONE 0
#define ENDZONE 1
#define FRAMEINTERVAL 330
#define REPLAYS_PATH "data/ctimer" // Path to where replays are stored
#define BACKUP_REPLAYS
#define MAXVELOCITY 280.0
#define MAX_DIST 1536.0
#define MAX_DIST_SQ MAX_DIST * MAX_DIST
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <PlayerManager>
/* Global variables */
enum
{
RUNDATA_POSITION_X,
RUNDATA_POSITION_Y,
RUNDATA_POSITION_Z,
RUNDATA_PITCH,
RUNDATA_YAW,
RUNDATA_BUTTONS,
RUNDATA_IMPULSE,
RUNDATA_WEAPONID,
RUNDATA_MAX
}
///TIMER HANDLES
Handle g_hDrawFullZone = INVALID_HANDLE;
Handle g_hDrawZone = INVALID_HANDLE;
Handle g_hHudLoop = INVALID_HANDLE;
Handle g_hSideHudLoop = INVALID_HANDLE;
///DATABASE
Database g_hDatabase = null;
///PLAYERS
float g_fMapTime[MAXPLAYERS + 1];
float g_fStartTime[MAXPLAYERS + 1];
int g_iActivity[MAXPLAYERS + 1] = -1; //-1 - Inactive, 0 - Running, 1 - StartZone, 2 - EndZone
///BOTS AND RECORDING
//ArrayList g_arrayGhost;
ArrayList g_arrayRun[MAXPLAYERS + 1]; //Record array
//char g_sGhostNames[MAX_NAME_LENGTH];
//int g_iGhost = -1;
//int g_iGhostFrame = -1;
//int g_fGhostVel = -1;
float g_fTickrate;
///ZONEMAP INFO
int g_iSnapToClient = -1;
bool g_bEditorComesFromMenu;
float g_fStartOrigins[2][3];
float g_fEndOrigins[2][3];
int g_iEditor = -1;
int g_iTriggerEnt[2] = -1;
///MAP INFO
bool g_bActive = false;
int g_iTier = 1;
int g_iMapID = -1;
float g_fWrTime = -1.0;
char g_sMapName[64];
char g_sWrHolder[MAX_NAME_LENGTH];
///OTHERS
bool g_bLateLoad = false;
int g_iBeam;
ConVar g_hCvarLasers = null;
bool g_bLasers = false;
// Offsets (netprops)
int m_vecOrigin; // CBaseEntity::m_vecOrigin
int m_hActiveWeapon; // CBaseCombatCharacter::m_hActiveWeapon
public Plugin myinfo =
{
name = "Under Average Timer",
author = PLUGIN_AUTHOR,
description = "",
version = PLUGIN_VERSION,
url = ""
};
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("CTimer_Stop", Native_StopTime);
RegPluginLibrary("ctimer");
g_bLateLoad = late;
return APLRes_Success;
}
public void OnPluginStart()
{
LoadTranslations("ctimer.phrases");
HookEvent("round_start", Event_RoundStart);
HookEvent("player_death", Event_PlayerDeath);
RegAdminCmd("sm_timeradmin", Command_TimerAdmin, ADMFLAG_CHEATS, "Your one stop for timer management");
RegAdminCmd("sm_zones", Command_Zones, ADMFLAG_CHEATS, "Create zones");
RegConsoleCmd("sm_stop", Command_Stop, "Stops your timer");
RegConsoleCmd("sm_time", Command_Time, "Get a players time");
RegConsoleCmd("sm_top", Command_Top, "Get a maps top times");
RegConsoleCmd("sm_wr", Command_WR, "Get a maps best time");
RegAdminCmd("sm_origins", Command_Origins, ADMFLAG_CHEATS);
g_hCvarLasers = CreateConVar("ctimer_zone_lazers", "1", "Lazors", FCVAR_NONE, true, 0.0, true, 1.0);
if(g_hCvarLasers != null)
{
g_hCvarLasers.AddChangeHook(OnLazorsChange);
}
g_hDrawFullZone = CreateTimer(0.2, DrawFullZoneTimer, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
g_hDrawZone = CreateTimer(1.0, DrawZoneTimer, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
g_hHudLoop = CreateTimer(0.2, HudLoop, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
g_hSideHudLoop = CreateTimer(1.0, SideHudLoop, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
for (new i = 1; i <= MaxClients; i++)
{
g_arrayRun[i] = new ArrayList(RUNDATA_MAX);
}
m_vecOrigin = FindSendPropInfo("CBaseEntity", "m_vecOrigin");
if (m_vecOrigin == -1)
{
SetFailState("Couldn't find CBaseEntity::m_vecOrigin");
}
if (m_vecOrigin == 0)
{
SetFailState("No offset available for CBaseEntity::m_vecOrigin");
}
m_hActiveWeapon = FindSendPropInfo("CBaseCombatCharacter", "m_hActiveWeapon");
if (m_hActiveWeapon == -1)
{
SetFailState("Couldn't find CBaseCombatCharacter::m_hActiveWeapon");
}
if (m_hActiveWeapon == 0)
{
SetFailState("No offset available for CBaseCombatCharacter::m_hActiveWeapon");
}
//g_arrayGhost = new ArrayList(9, 0);
g_fTickrate = (1.0 / GetTickInterval());
EstablishConnection();
}
#include "ctimer/actions.sp"
#include "ctimer/bots.sp"
#include "ctimer/commands.sp"
#include "ctimer/menus.sp"
#include "ctimer/timers.sp"
#include "ctimer/utility.sp"
#include "ctimer/sql.sp"
#include "ctimer/zones.sp"
public Action Command_Origins(int client, int args)
{
PrintToChatAll("Start: %f|%f|%f %f|%f|%f", g_fStartOrigins[0][0], g_fStartOrigins[0][1], g_fStartOrigins[0][2], g_fEndOrigins[0][0], g_fEndOrigins[0][1], g_fEndOrigins[0][2]);
PrintToChatAll("End: %f|%f|%f %f|%f|%f", g_fStartOrigins[1][0], g_fStartOrigins[1][1], g_fStartOrigins[1][2], g_fEndOrigins[1][0], g_fEndOrigins[1][1], g_fEndOrigins[1][2]);
PrintToChatAll("MapID: %i", g_iMapID);
PrintToChatAll("Active: %s", g_bActive ? "active":"inactive");
PrintToChatAll("Tier: %i", g_iTier);
PrintToChatAll("Wr: %.2f, %s", g_fWrTime, g_sWrHolder);
PrintToChatAll("Speccount: %i", GetSpecCount(client));
return Plugin_Handled;
}

View File

@ -1,219 +0,0 @@
public void OnMapStart()
{
PrecacheModel("models/error.mdl", true);
g_iBeam = PrecacheModel("materials/sprites/physbeam.vmt");
AddFileToDownloadsTable("sound/unl1/disco.wav");
PrecacheSound("unl1/disco.wav");
AddFileToDownloadsTable("sound/unl1/steamedyes.mp3");
PrecacheSound("unl1/steamedyes.mp3");
GetCurrentMap(g_sMapName, sizeof(g_sMapName));
LowerString(g_sMapName, sizeof(g_sMapName));
RestartTimers();
ClearMapInfo();
CheckDirectories();
if (g_hDatabase != null)
{
LoadMapInfo();
}
}
public void OnConfigsExecuted()
{
g_bLasers = g_hCvarLasers.BoolValue;
}
public void OnLazorsChange(ConVar convar, char[] oldValue, char[] newValue)
{
g_bLasers = g_hCvarLasers.BoolValue;
}
public void OnClientPostAdminCheck(int client)
{
if (isValidClient(client))
{
ClearPlayerCache(client);
GetPlayerInfo(client);
}
}
public void OnClientDisconnect(int client)
{
if (client == g_iEditor)
{
g_iEditor = -1;
g_bEditorComesFromMenu = false;
}
}
public void Event_RoundStart(Handle event, char[] name, bool dontBroadcast)
{
for (int i = 0; i <= 1; i++)
{
CreateTrigger(i);
}
for (int i = 0; i <= MAXPLAYERS; i++)
{
g_iActivity[i] = -1;
}
}
/*public Action CS_OnTerminateRound(float& delay, CSRoundEndReason& reason)
{
}*/
public void Event_PlayerDeath(Handle event, char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
g_iActivity[client] = -1;
}
void CheckDirectories()
{
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), REPLAYS_PATH);
if (!DirExists(path))
CreateDirectory(path, 711);
BuildPath(Path_SM, path, sizeof(path), "%s/%s", REPLAYS_PATH, g_sMapName);
if (!DirExists(path))
CreateDirectory(path, 711);
}
public void RestartTimers()
{
delete g_hDrawFullZone;
delete g_hDrawZone;
delete g_hHudLoop;
delete g_hSideHudLoop;
g_hDrawFullZone = CreateTimer(0.2, DrawFullZoneTimer, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
g_hDrawZone = CreateTimer(1.0, DrawZoneTimer, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
g_hHudLoop = CreateTimer(0.2, HudLoop, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
g_hSideHudLoop = CreateTimer(1.0, SideHudLoop, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public void ClearMapInfo()
{
for (int i = 0; i <= 1; i++)
{
g_iTriggerEnt[i] = -1;
for (int f = 0; f <= 2; f++)
{
g_fStartOrigins[i][f] = 0.0;
g_fEndOrigins[i][f] = 0.0;
}
}
g_iTier = 1;
g_iMapID = -1;
g_bActive = false;
g_iEditor = -1;
g_bEditorComesFromMenu = false;
g_iSnapToClient = -1;
g_fWrTime = -1.0;
Format(g_sWrHolder, sizeof(g_sWrHolder), "\0");
}
public void ProcessFinish(int client)
{
float fTime, fTimeToWR;
char name[MAX_NAME_LENGTH], cTime[16], cTimeToWR[16];
GetClientName(client, name, sizeof(name));
fTime = GetEngineTime() - g_fStartTime[client];
fTimeToWR = fTime - g_fWrTime;
TimerFormat(fTime, cTime, sizeof(cTime), true, false);
if (fTimeToWR == fTime)
Format(cTimeToWR, sizeof(cTimeToWR), "WR");
else
TimerFormat(fTimeToWR, cTimeToWR, sizeof(cTimeToWR), true, true);
if (g_fMapTime[client] > fTime)
{
float fTimeDif;
char cTimeDif[16];
fTimeDif = g_fMapTime[client] - fTime;
g_fMapTime[client] = fTime;
TimerFormat(fTimeDif, cTimeDif, sizeof(cTimeDif), true, false);
TimerPrintToChat(client, true, "%T", "FinishedImproved", LANG_SERVER, name, cTime, cTimeToWR, cTimeDif);
UpdateTime(client);
if (fTimeToWR < 0.0)
UpdateWR(client, fTime, name);
}
else
{
TimerPrintToChat(client, true, "%T", "Finished", LANG_SERVER, name, cTime, cTimeToWR);
if (g_fMapTime[client] == 0.0)
{
g_fMapTime[client] = fTime;
UpdateTime(client);
if (fTimeToWR < 0.0 || g_fWrTime == 0.0)
{
UpdateWR(client, fTime, name);
}
}
else
{
AddCompletion(client);
}
}
}
public void UpdateWR(int client, float time, char[] name)
{
if (g_fWrTime == -1.0)
{
LogError("WR never loaded, reload map");
return;
}
if (g_fWrTime < time && g_fWrTime != 0.0)
{
LogError("Time submitted is not faster");
return;
}
SaveRecord(client);
g_fWrTime = time;
strcopy(g_sWrHolder, sizeof(g_sWrHolder), name);
}
public void ProcessRankMessage(int client, int rank, int total)
{
char name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
if (rank > 10)
TimerPrintToChat(client, false, "%T", "Rank", LANG_SERVER, name, rank, total);
else if (rank <= 10 && rank != 1)
{
TimerPrintToChat(client, true, "%T", "RankTop10", LANG_SERVER, name, rank, total);
EmitSoundToAll("unl1/steamedyes.mp3");
}
else if (rank == 1)
{
TimerPrintToChat(client, true, "%T", "RankWR", LANG_SERVER, name, rank, total);
EmitSoundToAll("unl1/disco.wav");
}
}

View File

@ -1,152 +0,0 @@
/*public void LoadMainGhost()
{
//Something went wrong, escape.
if (!g_iGhost)
return;
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "data/ctimer/replay/%s.bin", g_sMapName);
if (!FileExists(path))
{
Format(g_sGhostNames, MAX_NAME_LENGTH, "No replay available");
g_iGhostFrame = -1;
return;
}
File file = OpenFile(path, "rb", false, "GAME");
if (file)
{
g_arrayGhost.Clear();
float pos[3], ang[2], vel[3];
int currentframe, buttons;
while (!file.EndOfFile())
{
currentframe = g_arrayGhost.Length;
currentframe++;
g_arrayGhost.Resize(currentframe);
file.Read(view_as<int>(pos), 3, 4);
file.Read(view_as<int>(ang), 2, 4);
file.Read(view_as<int>(vel), 3, 4);
file.ReadInt32(buttons);
SetArrayCell(g_arrayGhost, currentframe, pos[0], 0);
SetArrayCell(g_arrayGhost, currentframe, pos[1], 1);
SetArrayCell(g_arrayGhost, currentframe, pos[2], 2);
SetArrayCell(g_arrayGhost, currentframe, ang[0], 3);
SetArrayCell(g_arrayGhost, currentframe, ang[1], 4);
SetArrayCell(g_arrayGhost, currentframe, vel[0], 5);
SetArrayCell(g_arrayGhost, currentframe, vel[1], 6);
SetArrayCell(g_arrayGhost, currentframe, vel[2], 7);
SetArrayCell(g_arrayGhost, currentframe, buttons, 8);
}
file.Close();
PrintToServer("Main replay loaded");
g_iGhostFrame = -2;
pos[0] = GetArrayCell(g_arrayGhost, 0, 0);
pos[1] = GetArrayCell(g_arrayGhost, 0, 1);
pos[2] = GetArrayCell(g_arrayGhost, 0, 2);
TeleportEntity(g_iGhost, pos, NULL_VECTOR, NULL_VECTOR);
}
}*/
bool SaveRecord(int client)
{
if ( !isValidClient(client) )
{
LogError("Client %d is not valid", client);
return false;
}
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "%s/%s/%s.steamedhams", REPLAYS_PATH, g_sMapName, g_sMapName);
if (FileExists(path))
{
#if defined BACKUP_REPLAYS
BackupRecord(path);
#endif
DeleteFile(path); // Kinda unnecessary? Opening the file later will truncate it.
}
File file = OpenFile(path, "wb");
if (file)
{
int size = g_arrayRun[client].Length;
if (!size)
{
LogError("Couldn't save record. Run array is empty.");
return false;
}
int values[RUNDATA_MAX];
for (int i = 0; i < size; ++i)
{
g_arrayRun[client].GetArray(i, values, RUNDATA_MAX);
file.Write(values, RUNDATA_MAX-1, 4);
file.WriteInt8(values[RUNDATA_WEAPONID]);
}
file.Close();
return true;
}
LogError("Could not open the file \"%s\" for writing.", path);
return false;
}
void BackupRecord(char[] recordPath)
{
char sPath[PLATFORM_MAX_PATH];
FormatEx(sPath, sizeof(sPath), "%s_old", recordPath);
// Delete the last backup
if (FileExists(sPath))
{
DeleteFile(sPath);
}
RenameFile(sPath, recordPath);
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
// Handle humans
if (isValidClient(client))
{
if (IsPlayerAlive(client))
{
// Is the player running?
if (g_iActivity[client] == 0)
{
if(GetEntityMoveType(client) != MOVETYPE_NOCLIP)
{
// Record run data
int values[RUNDATA_MAX];
float origin[3];
GetEntDataVector(client, m_vecOrigin, origin);
values[RUNDATA_POSITION_X] = view_as<int>(origin[0]);
values[RUNDATA_POSITION_Y] = view_as<int>(origin[1]);
values[RUNDATA_POSITION_Z] = view_as<int>(origin[2]);
values[RUNDATA_PITCH] = view_as<int>(angles[0]);
values[RUNDATA_YAW] = view_as<int>(angles[1]);
values[RUNDATA_BUTTONS] = buttons;
values[RUNDATA_IMPULSE] = impulse;
values[RUNDATA_WEAPONID] = view_as<int>( GetWeaponID(client) );
g_arrayRun[client].PushArray(values, RUNDATA_MAX);
}
else
{
g_iActivity[client] = -1;
TimerPrintToChat(client, false, "%T", "TimerCheatStopped", LANG_SERVER);
}
}
}
}
}

View File

@ -1,137 +0,0 @@
public Action Command_Time(int client, int args)
{
if (!g_bActive)
return Plugin_Handled;
if (g_fMapTime[client] != 0.0)
{
char cTime[16];
TimerFormat(g_fMapTime[client], cTime, sizeof(cTime), true, false);
TimerPrintToChat(client, false, "%T", "PlayerTime", LANG_SERVER, cTime);
}
else
TimerPrintToChat(client, false, "%T", "PlayerNoTime", LANG_SERVER);
return Plugin_Handled;
}
public Action Command_Stop(int client, int args)
{
if (!g_bActive)
return Plugin_Handled;
if (g_iActivity[client] == 0)
{
g_iActivity[client] = -1;
TimerPrintToChat(client, false, "%T", "TimerStopped", LANG_SERVER);
}
else if (g_iActivity[client] == 1)
{
TimerPrintToChat(client, false, "%T", "TimerCantBeStopped", LANG_SERVER);
}
else if (g_iActivity[client] == -1)
{
TimerPrintToChat(client, false, "%T", "TimerNotRunning", LANG_SERVER);
}
return Plugin_Handled;
}
public Action Command_Zones(int client, int args)
{
if (g_iEditor != -1)
{
TimerPrintToChat(client, false, "%T", "ZoneMenuUnavailable", LANG_SERVER);
//PrintToChat(client, "Zone menu currently unavailable");
return Plugin_Handled;
}
g_iEditor = client;
g_iActivity[client] = -1;
g_bEditorComesFromMenu = false;
ZoneMenu(client, g_bEditorComesFromMenu);
return Plugin_Handled;
}
public Action Command_Top(int client, int args)
{
char sMapName[129];
if (args > 0)
{
GetCmdArg(1, sMapName, sizeof(sMapName));
if (strlen(sMapName) > 64)
{
TimerPrintToChat(client, false, "%T", "MapNameTooLong", LANG_SERVER);
return Plugin_Handled;
}
g_hDatabase.Escape(sMapName, sMapName, sizeof(sMapName));
}
else
{
if (!g_bActive)
return Plugin_Handled;
strcopy(sMapName, sizeof(sMapName), g_sMapName);
}
int userid = GetClientUserId(client);
RequestTop(userid, sMapName, 10);
return Plugin_Handled;
}
public Action Command_TimerAdmin(int client, int args)
{
TimerAdminMenu(client);
return Plugin_Handled;
}
public Action Command_WR(int client, int args)
{
if (args == 0)
{
if (!g_bActive)
return Plugin_Handled;
if (g_fWrTime == 0.0)
{
TimerPrintToChat(client, false, "%T", "TimesNotFound", LANG_SERVER, g_sMapName);
return Plugin_Handled;
}
else
{
char cWRTime[16];
TimerFormat(g_fWrTime, cWRTime, sizeof(cWRTime), true, false);
TimerPrintToChat(client, false, "%T", "WR", LANG_SERVER, g_sWrHolder, g_sMapName, cWRTime);
return Plugin_Handled;
}
}
else
{
char sMapName[129];
GetCmdArg(1, sMapName, sizeof(sMapName));
if (strlen(sMapName) > 64)
{
TimerPrintToChat(client, false, "%T", "MapNameTooLong", LANG_SERVER);
return Plugin_Handled;
}
g_hDatabase.Escape(sMapName, sMapName, sizeof(sMapName));
int userid = GetClientUserId(client);
RequestWR(userid, sMapName);
}
return Plugin_Handled;
}
public int Native_StopTime(Handle hPlugin, int numParams)
{
int client = GetNativeCell(1);
if (!isValidClient(client))
return;
if (g_iActivity[client] == -1)
return;
g_iActivity[client] = -1;
TimerPrintToChat(client, false, "%T", "TimerCheatStopped", LANG_SERVER);
return;
}

View File

@ -1,281 +0,0 @@
public void TimerAdminMenu(int client)
{
char buffer[16];
Menu menu = new Menu(TimerAdminMenuHandler);
menu.SetTitle("Timer Control Panel");
if (g_iEditor != -1)
menu.AddItem("zone", "Zones (Currently in use)", ITEMDRAW_DISABLED);
else
menu.AddItem("zone", "Zones");
menu.AddItem("tier", "Set Map Tier");
Format(buffer, sizeof(buffer), "%s map", g_bActive ? "Deactivate":"Activate");
menu.AddItem("active", buffer);
menu.ExitButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int TimerAdminMenuHandler(Handle menu, MenuAction action, int client, int choice)
{
switch(action)
{
case MenuAction_Select:
{
switch(choice)
{
case 0:
{
if (g_iEditor != -1)
{
PrintToChat(client, "Zone menu currently unavailable");
TimerAdminMenu(client);
}
else
{
g_iEditor = client;
g_iActivity[client] = -1;
g_bEditorComesFromMenu = true;
ZoneMenu(client, g_bEditorComesFromMenu);
}
}
case 1:
{
TierMenu(client);
}
case 2:
{
g_bActive = !g_bActive;
SetMapState(view_as<int>(g_bActive));
PrintToChat(client, "%s the map...", g_bActive ? "Activating":"Deactivating");
CS_TerminateRound(1.0, CSRoundEnd_Draw, true);
TimerAdminMenu(client);
}
}
}
case MenuAction_End:
{
delete menu;
}
}
}
public void ZoneMenu(int client, bool comesFromMenu)
{
Menu menu = new Menu(ZoneMenuHandler);
menu.SetTitle("Zone Menu");
menu.AddItem("start", "Set Start Zone");
menu.AddItem("end", "Set End Zone");
menu.AddItem("rr", "Respawn Zones");
menu.AddItem("save", "Save Zones");
menu.ExitButton = true;
if (comesFromMenu)
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int ZoneMenuHandler(Handle menu, MenuAction action, int client, int choice)
{
switch(action)
{
case MenuAction_Select:
{
switch(choice)
{
case 0:
CreateZoneMenu(client, STARTZONE, false);
case 1:
CreateZoneMenu(client, ENDZONE, false);
case 2:
{
CS_TerminateRound(1.0, CSRoundEnd_Draw, true);
ZoneMenu(client, g_bEditorComesFromMenu);
}
case 3:
{
SaveZones(client);
ZoneMenu(client, g_bEditorComesFromMenu);
}
}
}
case MenuAction_Cancel:
{
g_iEditor = -1;
g_bEditorComesFromMenu = false;
if (choice == MenuCancel_ExitBack)
{
TimerAdminMenu(client);
}
}
case MenuAction_End:
{
delete menu;
}
}
}
public void CreateZoneMenu(int client, int zone, bool point)
{
char buffer[32], zonePoint[5];
Menu menu = new Menu(CreateZoneMenuHandler);
Format(buffer, sizeof(buffer), "Set the %s position", point ? "second":"first");
//Format(zonePoint, sizeof(zonePoint), "%i|%s", zone, view_as<int>(point));
Format(zonePoint, sizeof(zonePoint), "%i|%s", zone, point ? "1":"0");
menu.AddItem(zonePoint, buffer);
menu.ExitBackButton = false;
menu.ExitButton = false;
menu.Display(client, MENU_TIME_FOREVER);
}
public int CreateZoneMenuHandler(Menu menu, MenuAction action, int client, int choice)
{
if (action == MenuAction_Select)
{
char buffer[5], array[2][2];
int zone, point;
menu.GetItem(0, buffer, sizeof(buffer));
ExplodeString(buffer, "|", array, 2, 2);
zone = StringToInt(array[0]);
point = StringToInt(array[1]);
//PrintToChatAll("%s - %s %s - %i %i", buffer, array[0], array[1], zone, point);
if (point == 0)
{
GetClientAbsOrigin(client, g_fStartOrigins[zone]);
g_iSnapToClient = zone;
CreateZoneMenu(client, zone, true);
}
if (point == 1)
{
GetClientAbsOrigin(client, g_fEndOrigins[zone]);
g_iSnapToClient = -1;
CreateTrigger(zone);
ZoneMenu(client, g_bEditorComesFromMenu);
}
}
if (action == MenuAction_End)
{
delete menu;
}
}
public void TierMenu(int client)
{
Menu menu = new Menu(TierMenuHandler);
menu.SetTitle("Choose a tier");
menu.AddItem("1", "Tier 1");
menu.AddItem("2", "Tier 2");
menu.AddItem("3", "Tier 3");
menu.AddItem("4", "Tier 4");
menu.AddItem("5", "Tier 5");
menu.AddItem("6", "Tier 6");
menu.ExitButton = true;
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int TierMenuHandler(Handle menu, MenuAction action, int client, int choice)
{
switch(action)
{
case MenuAction_Select:
{
g_iTier = choice + 1;
SetMapTier(g_iTier);
PrintToChat(client, "Setting the maps tier to %i", g_iTier);
TimerAdminMenu(client);
}
case MenuAction_Cancel:
{
if (choice == MenuCancel_ExitBack)
{
TimerAdminMenu(client);
}
}
case MenuAction_End:
{
delete menu;
}
}
}
public void SQL_RequestTop(Database db, int userid, int numQueries, DBResultSet[] results, any[] queryData)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
int client = GetClientOfUserId(userid);
if (!isValidClient(client))
return;
if (results[0].RowCount == 0)
{
TimerPrintToChat(client, false, "%T", "MapNotFound", LANG_SERVER);
return;
}
char cMap[64];
results[0].FetchRow();
results[0].FetchString(0, cMap, sizeof(cMap));
if (results[1].RowCount == 0)
{
TimerPrintToChat(client, false, "%T", "TimesNotFound", LANG_SERVER, cMap);
return;
}
char cBuffer[128], cTime[16], cTimeToWR[16], cName[64];
float fTime, fTimeToWR, fWR;
int timescompleted;
Menu menu = new Menu(TopTimeMenuHandler);
Format(cBuffer, sizeof(cBuffer), "Top Times for %s", cMap);
menu.SetTitle(cBuffer);
results[1].FetchRow();
results[1].FetchString(0, cName, sizeof(cName));
fTime = fWR = results[1].FetchFloat(1);
timescompleted = results[1].FetchInt(2);
TimerFormat(fTime, cTime, sizeof(cTime), true, false);
Format(cBuffer, sizeof(cBuffer), "%s\n%s (+00:00.00) (%i)", cName, cTime, timescompleted);
menu.AddItem("", cBuffer);
while (results[1].FetchRow())
{
results[1].FetchString(0, cName, sizeof(cName));
fTime = results[1].FetchFloat(1);
fTimeToWR = fTime - fWR;
timescompleted = results[1].FetchInt(2);
TimerFormat(fTime, cTime, sizeof(cTime), true, false);
TimerFormat(fTimeToWR, cTimeToWR, sizeof(cTimeToWR), true, true);
Format(cBuffer, sizeof(cBuffer), "%s\n%s (%s) (%i)", cName, cTime, cTimeToWR, timescompleted);
menu.AddItem("", cBuffer);
}
menu.ExitButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int TopTimeMenuHandler(Handle menu, MenuAction action, int client, int choice)
{
switch(action)
{
case MenuAction_End:
{
delete menu;
}
}
}

View File

@ -1,504 +0,0 @@
public void EstablishConnection()
{
if (SQL_CheckConfig("ctimer"))
Database.Connect(ConnectionCallback, "ctimer");
else
SetFailState("'ctimer' not found in 'sourcemod/configs/databases.cfg'");
}
public void ConnectionCallback(Database db, const char[] error, any data)
{
if (db == null)
{
SetFailState("Failed to connect to the database, will attempt to reconnect on map change");
return;
}
g_hDatabase = db;
LoadMapInfo();
}
public void GetPlayerInfo(client)
{
int steamid = GetTimerSteamId(client);
char query[512], username[65], ip[16];
GetClientName(client, username, sizeof(username));
g_hDatabase.Escape(username, username, sizeof(username));
GetClientIP(client, ip, sizeof(ip));
Format(query, sizeof(query), "INSERT INTO ctimer_users (userid, name, ip, lastconnected) values ('%i', '%s', INET_ATON('%s'), CURRENT_TIMESTAMP) ON DUPLICATE KEY UPDATE name = VALUES(name), ip = VALUES(ip), lastconnected = CURRENT_TIMESTAMP;", steamid, username, ip);
g_hDatabase.Query(SQL_InsertUser, query, DBPrio_High);
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid, can't load players time %N<%i>", client, client);
return;
}
int userid = GetClientUserId(client);
Format(query, sizeof(query), "SELECT time FROM ctimer_times WHERE mapid = %i AND userid = %i;", g_iMapID, GetTimerSteamId(client));
g_hDatabase.Query(SQL_GetUserTime, query, userid);
}
public void SQL_InsertUser(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on inserting user: %s", error);
return;
}
}
public void SQL_GetUserTime(Database db, DBResultSet results, const char[] error, int userid)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on getting user time: %s", error);
return;
}
int client = GetClientOfUserId(userid);
if (!isValidClient(client))
return;
if (results.RowCount == 0)
{
g_fMapTime[client] = 0.0;
return;
}
if (results.RowCount > 1)
{
LogError("Unexpected amount of rows: %i", results.RowCount);
return;
}
results.FetchRow();
g_fMapTime[client] = results.FetchFloat(0);
}
public void LoadMapInfo()
{
char query[512];
Format(query, sizeof(query), "INSERT INTO ctimer_maps (mapname, lastplayed) values ('%s', CURRENT_TIMESTAMP) ON DUPLICATE KEY UPDATE lastplayed = CURRENT_TIMESTAMP", g_sMapName);
g_hDatabase.Query(SQL_InsertMap, query, DBPrio_High); ///Insert map or update lastplayed
Format(query, sizeof(query), "SELECT mapid, tier, enabled FROM ctimer_maps WHERE mapname = '%s'", g_sMapName);
g_hDatabase.Query(SQL_GetMapInfo, query);
}
public void SQL_InsertMap(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on inserting map: %s", error);
return;
}
}
public void SQL_GetMapInfo(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on inserting map: %s", error);
return;
}
if (results.RowCount == 0)
{
LogError("Map not found");
return;
}
if (results.RowCount > 1)
{
LogError("Unexpected amount of rows: %i", results.RowCount);
return;
}
results.FetchRow();
g_iMapID = results.FetchInt(0);
g_iTier = results.FetchInt(1);
g_bActive = view_as<bool>(results.FetchInt(2));
LoadZones();
GetWRInfo();
if (g_bLateLoad)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i))
{
OnClientPostAdminCheck(i);
}
}
}
}
public void GetWRInfo()
{
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid");
return;
}
char query[512];
Format(query, sizeof(query), "SELECT u.name , wr.time FROM ctimer_users u, ctimer_times wr WHERE u.userid = wr.userid AND wr.mapid = %i AND u.userid = getWrUserId(%i);", g_iMapID, g_iMapID);
g_hDatabase.Query(SQL_GetWRInfo, query);
}
public void SQL_GetWRInfo(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on getting map WR info: %s", error);
return;
}
if (results.RowCount == 0)
{
g_fWrTime = 0.0;
return;
}
if (results.RowCount > 2)
{
LogError("Unexpected amount of rows: %i", results.RowCount);
return;
}
results.FetchRow();
results.FetchString(0, g_sWrHolder, sizeof(g_sWrHolder));
g_fWrTime = results.FetchFloat(1);
}
public void SaveZones(int client)
{
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid");
return;
}
char query[512], startcord[42], endcord[42];
for (int i = 0; i <= 1; i++)
{
VectorToString(startcord, sizeof(startcord), g_fStartOrigins[i]);
VectorToString(endcord, sizeof(endcord), g_fEndOrigins[i]);
Format(query, sizeof(query), "INSERT INTO ctimer_zones(mapid, zonetype, startcord, endcord) VALUES (%i, %i, '%s', '%s') ON DUPLICATE KEY UPDATE startcord = values(startcord), endcord = values(endcord)", g_iMapID, i, startcord, endcord);
g_hDatabase.Query(SQL_SaveZones, query);
}
PrintToChat(client, "Zones Saved");
}
public void SQL_SaveZones(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on saving zones: %s", error);
return;
}
}
public void LoadZones()
{
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid");
return;
}
char query[512];
Format(query, sizeof(query), "SELECT zonetype, startcord, endcord from ctimer_zones where mapid = %i ORDER BY zonetype", g_iMapID);
g_hDatabase.Query(SQL_LoadZones, query);
}
public void SQL_LoadZones(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on inserting map: %s", error);
return;
}
if (results.RowCount == 0)
{
return;
}
if (results.RowCount > 2)
{
LogError("Unexpected amount of rows: %i", results.RowCount);
return;
}
int zonetype;
char startcord[42], endcord[42];
float vec[3];
while (results.FetchRow())
{
zonetype = results.FetchInt(0);
results.FetchString(1, startcord, sizeof(startcord));
results.FetchString(2, endcord, sizeof(endcord));
StringToVector(vec, startcord);
g_fStartOrigins[zonetype] = vec;
StringToVector(vec, endcord);
g_fEndOrigins[zonetype] = vec;
CreateTrigger(zonetype);
//CreateTimer(1.0, Timer_CreateTrigger, zonetype);
}
//CS_TerminateRound(0.0, CSRoundEnd_Draw, true);
}
public void SetMapTier(int tier)
{
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid");
return;
}
char query[512];
Format(query, sizeof(query), "UPDATE ctimer_maps SET tier = %i WHERE mapname = '%s'", tier, g_sMapName);
g_hDatabase.Query(SQL_SetMapTier, query);
}
public void SQL_SetMapTier(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on setting map tier: %s", error);
return;
}
}
public void SetMapState(int state)
{
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid");
return;
}
char query[512];
Format(query, sizeof(query), "UPDATE ctimer_maps SET enabled = %i WHERE mapname = '%s'", state, g_sMapName);
g_hDatabase.Query(SQL_SetMapState, query);
}
public void SQL_SetMapState(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on setting map active state: %s", error);
return;
}
}
public void UpdateTime(int client)
{
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid");
return;
}
char query[512];
int userid = GetClientUserId(client);
Format(query, sizeof(query), "SELECT updateTime(%i, %i, %f), getTimeRank(%i, %i), getTimeComps(%i);", g_iMapID, GetTimerSteamId(client), g_fMapTime[client], g_iMapID, GetTimerSteamId(client), g_iMapID);
g_hDatabase.Query(SQL_UpdateTime, query, userid);
}
public void SQL_UpdateTime(Database db, DBResultSet results, const char[] error, int userid)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on updating time: %s", error);
return;
}
int client = GetClientOfUserId(userid);
if (!isValidClient(client))
return;
results.FetchRow();
int rank = results.FetchInt(1);
int total = results.FetchInt(2);
ProcessRankMessage(client, rank, total);
}
public void AddCompletion(int client)
{
if (g_iMapID == -1)
{
LogError("Error, map ID is invalid");
return;
}
char query[512];
Format(query, sizeof(query), "UPDATE ctimer_times SET timescompleted = timescompleted + 1 where mapid = %i AND userid = %i", g_iMapID, GetTimerSteamId(client));
g_hDatabase.Query(SQL_AddCompletion, query);
}
public void SQL_AddCompletion(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
if (results == null)
{
LogError("Error on setting map active state: %s", error);
return;
}
}
public void RequestTop(int userid, char[] mapname, int limit)
{
Transaction transaction = new Transaction();
char query[512];
Format(query, sizeof(query), "SELECT mapname FROM ctimer_maps WHERE enabled = 1 AND mapname LIKE '%%%s%%' ORDER BY mapname LIMIT 1", mapname);
transaction.AddQuery(query);
Format(query, sizeof(query), "SELECT u.name , times.time, times.timescompleted FROM ctimer_users u, ctimer_times times, ctimer_maps maps WHERE u.userid = times.userid AND times.mapid = maps.mapid AND maps.mapid = (SELECT mapid FROM ctimer_maps WHERE enabled = 1 AND mapname LIKE '%%%s%%' ORDER BY mapname LIMIT 1) ORDER BY time, runid LIMIT %i;", mapname, limit);
transaction.AddQuery(query);
g_hDatabase.Execute(transaction, SQL_RequestTop, SQL_RequestTopError, userid);
}
public void SQL_RequestTopError(Database db, int userid, int numQueries, const char[] error, int failIndex, any[] queryData)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
LogError("Error on requesting top time records on query %i: %s", failIndex, error);
}
public void RequestWR(int userid, char[] mapname)
{
Transaction transaction = new Transaction();
char query[512];
Format(query, sizeof(query), "SELECT mapname FROM ctimer_maps WHERE enabled = 1 AND mapname LIKE '%%%s%%' ORDER BY mapname LIMIT 1", mapname);
transaction.AddQuery(query);
Format(query, sizeof(query), "SELECT name, time FROM ctimer_times times INNER JOIN ctimer_users u ON u.userid = times.userid WHERE mapid=(SELECT mapid FROM ctimer_maps WHERE enabled = 1 AND mapname LIKE '%%%s%%' ORDER BY mapname LIMIT 1) ORDER BY time, runid LIMIT 1;", mapname);
transaction.AddQuery(query);
g_hDatabase.Execute(transaction, SQL_RequestWR, SQL_RequestWRError, userid);
}
public void SQL_RequestWRError(Database db, int userid, int numQueries, const char[] error, int failIndex, any[] queryData)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
LogError("Error on requesting world record time on query %i: %s", failIndex, error);
}
public void SQL_RequestWR(Database db, int userid, int numQueries, DBResultSet[] results, any[] queryData)
{
if (db == null)
{
SetFailState("Lost connection to the database, will attempt to reconnect on map change");
return;
}
int client = GetClientOfUserId(userid);
if (!isValidClient(client))
return;
if (results[0].RowCount == 0)
{
TimerPrintToChat(client, false, "%T", "MapNotFound", LANG_SERVER);
return;
}
char cMap[64];
results[0].FetchRow();
results[0].FetchString(0, cMap, sizeof(cMap));
if (results[1].RowCount == 0)
{
TimerPrintToChat(client, false, "%T", "TimesNotFound", LANG_SERVER, cMap);
return;
}
char cTime[16], cName[64];
float fTime;
results[1].FetchRow();
results[1].FetchString(0, cName, sizeof(cName));
fTime = results[1].FetchFloat(1);
TimerFormat(fTime, cTime, sizeof(cTime), true, false);
TimerPrintToChat(client, false, "%T", "WR", LANG_SERVER, cName, cMap, cTime);
}

View File

@ -1,210 +0,0 @@
public Action DrawFullZoneTimer(Handle timer)
{
int colorarray[][] = { { 124, 252, 0, 255 }, { 255, 0, 0, 255 } };
if (!g_bLasers || g_iEditor == -1)
return Plugin_Continue;
for (int i = 0; i <= 1; i++)
{
if (g_iSnapToClient == i)
{
float vec[3];
GetClientAbsOrigin(g_iEditor, vec);
DrawFullZone(vec, g_fStartOrigins[i], colorarray[i], 0.1);
continue;
}
DrawFullZone(g_fEndOrigins[i], g_fStartOrigins[i], colorarray[i], 0.2);
}
return Plugin_Continue;
}
public Action DrawZoneTimer(Handle timer)
{
if (!g_bLasers || !g_bActive)
return Plugin_Continue;
int colorarray[][] = { { 124, 252, 0, 255 }, { 255, 0, 0, 255 } };
if (g_iEditor != -1)
return Plugin_Continue;
float pos[3], eye[3];
int[] clients = new int[MaxClients];
int nClients = 0;
for (int i = 0; i <= 1; i++)
{
for (int j = 1; j <= MaxClients; j++)
{
if (isValidClient(j))
{
//https://github.com/InfluxTimer/sm-timer/blob/master/addons/sourcemod/scripting/influx_zones_beams.sp
GetClientEyePosition(j, eye);
GetMiddleOfABox(g_fEndOrigins[i], g_fStartOrigins[i], pos);
if (GetVectorDistance(eye, pos, true) < MAX_DIST_SQ)
{
clients[nClients++] = j;
}
else
{
TR_TraceRayFilter(eye, pos, CONTENTS_SOLID, RayType_EndPoint, TraceFilter_WorldOnly);
if (!TR_DidHit())
{
clients[nClients++] = j;
}
}
}
}
DrawZone(clients, nClients, g_fEndOrigins[i], g_fStartOrigins[i], colorarray[i], 1.0);
}
return Plugin_Continue;
}
public bool TraceFilter_WorldOnly( int ent, int mask )
{
return ( ent == 0 );
}
public Action HudLoop(Handle timer)
{
if (g_iMapID != -1 && g_bActive)
{
for (int i = 1; i <= MaxClients; i++)
{
if (isValidClient(i))
{
UpdateHUD(i);
}
}
return Plugin_Continue;
}
return Plugin_Continue;
}
public void UpdateHUD(int client)
{
int target = client;
if (IsClientObserver(client))
{
int mode = GetEntProp(client, Prop_Send, "m_iObserverMode");
if (mode == 4 || mode == 5)
{
target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if (!isValidClient(target))
return;
}
else
return;
}
if (g_iActivity[target] == -1)
{
return;
}
char HintTextBuffer[256];
if (client != target)
Format(HintTextBuffer, sizeof(HintTextBuffer), "Player: %N\n \n", target);
if (g_iActivity[target] == 1)
Format(HintTextBuffer, sizeof(HintTextBuffer), "%sIn Start Zone\n \n", HintTextBuffer);
if (g_iActivity[target] == 0)
{
char cTime[16];
float fTime;
fTime = GetEngineTime() - g_fStartTime[target];
TimerFormat(fTime, cTime, sizeof(cTime), true, false);
Format(HintTextBuffer, sizeof(HintTextBuffer), "%sTime: %s\n \n", HintTextBuffer, cTime);
}
Format(HintTextBuffer, sizeof(HintTextBuffer), "%sSpeed: %i u/s", HintTextBuffer, Get2VecVelocity(target));
PrintHintText(client, HintTextBuffer);
}
public Action SideHudLoop(Handle timer)
{
if (g_iMapID != -1 && g_bActive)
{
for (int i = 1; i <= MaxClients; i++)
{
if (isValidClient(i))
{
UpdateSideHUD(i);
}
}
return Plugin_Continue;
}
return Plugin_Continue;
}
public void UpdateSideHUD(int client)
{
int target = client;
if (IsClientObserver(client))
{
int mode = GetEntProp(client, Prop_Send, "m_iObserverMode");
if (mode == 4 || mode == 5)
{
target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if (!isValidClient(target))
return;
}
else
return;
}
if (g_iActivity[target] == -1)
{
return;
}
char KeyHintBuffer[254];
char cTimeLeft[16];
GetTimerTimeLeft(cTimeLeft, sizeof(cTimeLeft));
Format(KeyHintBuffer, sizeof(KeyHintBuffer), "Timeleft: %s\n \n", cTimeLeft);
if (g_fMapTime[target] <= 0.0)
Format(KeyHintBuffer, sizeof(KeyHintBuffer), "%sPR: None\n", KeyHintBuffer);
else
{
char cTime[16], cTimeToWR[16];
float fTimeToWR;
fTimeToWR = g_fMapTime[target] - g_fWrTime;
if (fTimeToWR == 0)
Format(cTimeToWR, sizeof(cTimeToWR), "WR");
else
TimerFormat(fTimeToWR, cTimeToWR, sizeof(cTimeToWR), true, true);
TimerFormat(g_fMapTime[target], cTime, sizeof(cTime), true, false);
Format(KeyHintBuffer, sizeof(KeyHintBuffer), "%sPR: %s (%s)\n", KeyHintBuffer, cTime, cTimeToWR);
}
if (g_fWrTime <= 0.0)
Format(KeyHintBuffer, sizeof(KeyHintBuffer), "%sWR: None\n \n", KeyHintBuffer);
else
{
char cWR[16];
TimerFormat(g_fWrTime, cWR, sizeof(cWR), true, false);
Format(KeyHintBuffer, sizeof(KeyHintBuffer), "%sWR: %s (%s)\n \n", KeyHintBuffer, cWR, g_sWrHolder);
}
Format(KeyHintBuffer, sizeof(KeyHintBuffer), "%sSpectators: %i", KeyHintBuffer, GetSpecCount(target));
PrintKeyHintText(client, KeyHintBuffer);
}
/*public Action Timer_CreateTrigger(Handle timer, int zonetype)
{
CreateTrigger(zonetype);
}*/

View File

@ -1,433 +0,0 @@
public bool isValidClient(int client) {
if (client <= 0
|| client > MaxClients
|| !IsValidEntity(client)
|| !IsClientConnected(client)
|| IsFakeClient(client)
|| !IsClientInGame(client)
|| !PM_IsPlayerSteam(client)){
return false;
}
return true;
}
public int GetTimerSteamId(int client)
{
char steamid[32];
GetClientAuthId(client, AuthId_Steam3, steamid, sizeof(steamid));
ReplaceString(steamid, sizeof(steamid), "[U:1:", "\0");
ReplaceString(steamid, sizeof(steamid), "]", "\0");
return StringToInt(steamid);
}
public void ClearPlayerCache(int client)
{
g_iActivity[client] = -1;
g_fStartTime[client] = -1.0;
g_fMapTime[client] = 0.0;
if (g_arrayRun[client] != INVALID_HANDLE)
g_arrayRun[client].Clear();
else
g_arrayRun[client] = new ArrayList(RUNDATA_MAX);
}
public void LowerString(char[] sString, int len)
{
char sTemp[PLATFORM_MAX_PATH];
Format(sTemp, sizeof(sTemp), "%s", sString);
for (int i = 0; i < len; i++)
{
if (!IsCharLower(sTemp[i]))
{
sTemp[i] = CharToLower(sTemp[i]);
}
}
Format(sString, len, "%s", sTemp);
}
public void DrawFullZone(float fMin[3], float fMax[3], int color[4], float life)
{
float point[8][3];
float size = 3.0;
point[0][0] = fMin[0];
point[0][1] = fMin[1];
point[0][2] = fMax[2];
point[1][0] = fMax[0];
point[1][1] = fMin[1];
point[1][2] = fMax[2];
point[2][0] = fMin[0];
point[2][1] = fMax[1];
point[2][2] = fMax[2];
point[3][0] = fMax[0];
point[3][1] = fMax[1];
point[3][2] = fMax[2];
point[4][0] = fMin[0];
point[4][1] = fMin[1];
point[4][2] = fMin[2]+100;
point[5][0] = fMax[0];
point[5][1] = fMin[1];
point[5][2] = fMin[2]+100;
point[6][0] = fMin[0];
point[6][1] = fMax[1];
point[6][2] = fMin[2]+100;
point[7][0] = fMax[0];
point[7][1] = fMax[1];
point[7][2] = fMin[2]+100;
if (g_iEditor == -1)
return;
TE_SetupBeamPoints(point[4],point[5],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[4],point[6],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[7],point[6],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[7],point[5],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[0],point[1],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[0],point[2],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[0],point[4],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[3],point[2],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[3],point[1],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[3],point[7],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[1],point[5],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
TE_SetupBeamPoints(point[2],point[6],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_SendToClient(g_iEditor, 0.0);
}
public void DrawZone(int[] clients, int numClients, float fMin[3], float fMax[3], int color[4], float life)
{
float point[4][3];
float size = 6.0;
point[0][0] = fMin[0];
point[0][1] = fMin[1];
point[1][0] = fMax[0];
point[1][1] = fMin[1];
point[2][0] = fMin[0];
point[2][1] = fMax[1];
point[3][0] = fMax[0];
point[3][1] = fMax[1];
if (fMax[2] <= fMin[2] + 100)
{
point[0][2] = fMax[2] + 2;
point[1][2] = fMax[2] + 2;
point[2][2] = fMax[2] + 2;
point[3][2] = fMax[2] + 2;
}
else
{
point[0][2] = fMin[2] + 102;
point[1][2] = fMin[2] + 102;
point[2][2] = fMin[2] + 102;
point[3][2] = fMin[2] + 102;
}
TE_SetupBeamPoints(point[0],point[1],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_Send(clients, numClients);
TE_SetupBeamPoints(point[0],point[2],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_Send(clients, numClients);
TE_SetupBeamPoints(point[3],point[2],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_Send(clients, numClients);
TE_SetupBeamPoints(point[3],point[1],g_iBeam, 0, 0, 30, life, size, size, 1, 0.0, color, 0);TE_Send(clients, numClients);
}
public void VectorToString(char[] buffer, int maxlength, float vector[3])
{
Format(buffer, maxlength, "%f|%f|%f", vector[0], vector[1], vector[2]);
}
public float StringToVector(float vector[3], char[] buffer){
char cords[3][24];
ExplodeString(buffer, "|", cords, sizeof cords, sizeof cords[]);
for (int i = 0; i < 3; i++)
vector[i] = StringToFloat(cords[i]);
}
public void TimerFormat(float fTime, char[] sBuffer, int len, bool showMS, bool addsymbol)
{
Format(sBuffer, len, "");
int Min, Sec;
float Ms;
if(fTime < 0)
{
fTime *= -1;
if (addsymbol)
Format(sBuffer, len, "-");
}
else
if (addsymbol)
Format(sBuffer, len, "+");
Min = RoundToFloor(fTime) / 60;
Sec = RoundToFloor(fTime) - (Min * 60);
if (showMS)
Ms = fTime - ((Min * 60) + Sec);
char Mins[3], Secs[3], MiliSecond[16];
if (Min < 10)
Format(Mins, sizeof(Mins), "0%i", Min);
else
Format(Mins, sizeof(Mins), "%i", Min);
if (Sec < 10)
Format(Secs, sizeof(Secs), "0%i", Sec);
else
Format(Secs, sizeof(Secs), "%i", Sec);
if (Ms < 10 && showMS)
Format(MiliSecond, sizeof(MiliSecond), "0%.2f", Ms);
else
Format(MiliSecond, sizeof(MiliSecond), "%.2f", Ms);
if (!showMS)
Format(sBuffer, len, "%s%s:%s", sBuffer, Mins, Secs);
else
Format(sBuffer, len, "%s%s:%s.%s", sBuffer, Mins, Secs, MiliSecond[3]);
}
public void GetTimerTimeLeft(char[] buffer, int maxlength)
{
int timeleft;
GetMapTimeLeft(timeleft);
if (timeleft <= 60)
{
if (timeleft < 1)
Format(buffer, maxlength, "Map ending", timeleft);
else if (timeleft == 1)
Format(buffer, maxlength, "1 second", timeleft);
else
Format(buffer, maxlength, "%i seconds", timeleft);
}
else
{
int iMinutes = (timeleft / 60);
Format(buffer, maxlength, "%i", iMinutes);
if (iMinutes == 1)
Format(buffer, maxlength, "%s minute", buffer);
else
Format(buffer, maxlength, "%s minutes", buffer);
}
}
public void TimerPrintToChat(int client, bool toall, char[] sText, any:...)
{
int[] targets = new int[MaxClients];
int numTargets;
if (toall)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
targets[numTargets] = i;
numTargets++;
}
}
}
else
{
targets[0] = client;
numTargets = 1;
}
char finalmessage[MAXLENGTH_MESSAGE], cBuffer[MAXLENGTH_MESSAGE];
strcopy(cBuffer, sizeof(cBuffer), sText);
VFormat(finalmessage, MAXLENGTH_MESSAGE, cBuffer, 4);
Format(cBuffer, MAXLENGTH_MESSAGE, "%T", "Tag", LANG_SERVER);
CFormat(finalmessage, MAXLENGTH_MESSAGE, "%s%s", cBuffer, finalmessage);
SayText2(targets, numTargets, client, finalmessage);
}
//forums.alliedmods.net/showpost.php?p=1709517&postcount=35?p=1709517&postcount=35
public void CFormat(char[] buffer, int maxlength, char[] sText, any:...)
{
char cBuffer[MAXLENGTH_MESSAGE];
strcopy(cBuffer, sizeof(cBuffer), sText);
VFormat(buffer, maxlength, cBuffer, 4);
ReplaceString(buffer, maxlength, "{default}", "\x01", false);
int iStart, iEnd, iTotal;
char sHex[9], sCodeBefore[12], sCodeAfter[10];
while ((iStart = StrContains(buffer[(iTotal)], "{#")) != -1)
{
if ((iEnd = StrContains(buffer[iTotal+iStart+2], "}")) != -1)
{
if (iEnd == 6 || iEnd == 8)
{
strcopy(sHex, iEnd+1, buffer[iTotal+iStart+2]);
Format(sCodeBefore, sizeof(sCodeBefore), "{#%s}", sHex);
Format(sCodeAfter, sizeof(sCodeAfter), (iEnd == 6 ? "\x07%s" : "\x08%s"), sHex);
ReplaceString(buffer, maxlength, sCodeBefore, sCodeAfter);
iTotal += iStart + iEnd + 1;
}
else {
iTotal += iStart + iEnd + 3;
}
}
else {
break;
}
}
}
public void SayText2(int[] targets, int numTargets, int author, char[] szMessage)
{
Handle hBuffer = StartMessage("SayText2", targets, numTargets, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS);
if(GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf)
{
PbSetInt(hBuffer, "ent_idx", author);
PbSetBool(hBuffer, "chat", true);
PbSetString(hBuffer, "msg_name", szMessage);
PbAddString(hBuffer, "params", "");
PbAddString(hBuffer, "params", "");
PbAddString(hBuffer, "params", "");
PbAddString(hBuffer, "params", "");
}
else
{
BfWriteByte(hBuffer, author);
BfWriteByte(hBuffer, true);
BfWriteString(hBuffer, szMessage);
}
EndMessage();
}
public void PrintKeyHintText(int client, char[] format, any:...)
{
Handle userMessage = StartMessageOne("KeyHintText", client);
if (userMessage == INVALID_HANDLE) {
return;
}
char buffer[254];
SetGlobalTransTarget(client);
VFormat(buffer, sizeof(buffer), format, 3);
if (GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available
&& GetUserMessageType() == UM_Protobuf) {
PbSetString(userMessage, "hints", buffer);
}
else {
BfWriteByte(userMessage, 1);
BfWriteString(userMessage, buffer);
}
EndMessage();
}
public int Get2VecVelocity(int client)
{
float vel[3];
GetEntPropVector(client, Prop_Data, "m_vecVelocity", vel);
for(int i = 0; i <= 2; i++)
vel[i] *= vel[i];
return RoundToFloor(SquareRoot(vel[0] + vel[1]));
}
//https://github.com/InfluxTimer/sm-timer/blob/master/addons/sourcemod/scripting/influx_prespeed.sp
public void CheckSpeed(int client)
{
float vel[3];
GetEntPropVector(client, Prop_Data, "m_vecVelocity", vel);
/*for(int i = 0; i <= 2; i++)
vel[i] *= vel[i];*/
float speed = SquareRoot(vel[0] * vel[0] + vel[1] * vel[1]);
//PrintToChatAll("Exit Vel: %.2f", speed);
if (speed > MAXVELOCITY)
{
float m = speed / MAXVELOCITY;
//PrintToChatAll("Max Velocity. Factor: %.2f", m);
vel[0] /= m;
vel[1] /= m;
vel[2] /= m;
TimerPrintToChat(client, false, "%T", "MaxVelocityWarning", LANG_SERVER);
//PrintToChatAll("Velocity reduced to: %i", RoundToFloor(SquareRoot(vel[0] * vel[0] + vel[1] * vel[1])));
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vel);
}
}
public int GetSpecCount(int client)
{
int count;
for (int i = 1; i <= MaxClients; i++)
{
if (isValidClient(i) && IsClientObserver(i))
{
int mode = GetEntProp( i, Prop_Send, "m_iObserverMode" );
if ( mode == 4 || mode == 5 )
{
int target = GetEntPropEnt( i, Prop_Send, "m_hObserverTarget");
if (target == client)
count++;
}
}
}
return count;
}
public void GetMiddleOfABox(float vec1[3], float vec2[3], float buffer[3])
{
float mid[3];
MakeVectorFromPoints(vec1, vec2, mid);
mid[0] = mid[0] / 2.0;
mid[1] = mid[1] / 2.0;
mid[2] = mid[2] / 2.0;
AddVectors(vec1, mid, buffer);
}
CSWeaponID GetWeaponID(int client)
{
CSWeaponID weaponID = CSWeapon_NONE;
int weaponIndex = GetEntDataEnt2(client, m_hActiveWeapon);
if (weaponIndex != -1)
{
static char classname[64];
GetEdictClassname(weaponIndex, classname, sizeof(classname));
ReplaceString(classname, sizeof(classname), "weapon_", "");
static char wepAlias[64];
CS_GetTranslatedWeaponAlias(classname, wepAlias, sizeof(wepAlias));
weaponID = CS_AliasToWeaponID(wepAlias);
}
return weaponID;
}

View File

@ -1,151 +0,0 @@
public void CreateTrigger(int zone)
{
if ((g_fStartOrigins[zone][0] == 0.0) && (g_fStartOrigins[zone][1] == 0.0) && (g_fStartOrigins[zone][2] == 0.0) && (g_fEndOrigins[zone][0] == 0.0) && (g_fEndOrigins[zone][1] == 0.0) && (g_fEndOrigins[zone][2] == 0.0))
return;
if (g_iTriggerEnt[zone] > -1)
{
if (IsValidEntity(g_iTriggerEnt[zone]))
{
AcceptEntityInput(g_iTriggerEnt[zone], "Kill");
}
g_iTriggerEnt[zone] = -1;
}
float max[3];
float min[3];
min = g_fStartOrigins[zone];
max = g_fEndOrigins[zone];
char name[12];
if (zone == 0)
Format(name, sizeof name, "start");
if (zone == 1)
Format(name, sizeof name, "end");
float mid[3] = 0.0;
max[2]+=100;
GetMiddleOfABox(max, min, mid);
min[0] = min[0] - mid[0];
if(min[0] > 0.0)
min[0] *= -1.0;
min[1] = min[1] - mid[1];
if(min[1] > 0.0)
min[1] *= -1.0;
min[2] = min[2] - mid[2];
if(min[2] > 0.0)
min[2] *= -1.0;
max[0] = max[0] - mid[0];
if(max[0] < 0.0)
max[0] *= -1.0;
max[1] = max[1] - mid[1];
if(max[1] < 0.0)
max[1] *= -1.0;
max[2] = max[2] - mid[2];
if(max[2] < 0.0)
max[2] *= -1.0;
g_iTriggerEnt[zone] = CreateEntityByName("trigger_multiple");
DispatchKeyValue(g_iTriggerEnt[zone], "spawnflags", "1");
DispatchKeyValue(g_iTriggerEnt[zone], "targetname", name);
DispatchKeyValue(g_iTriggerEnt[zone], "wait", "0");
DispatchSpawn(g_iTriggerEnt[zone]);
ActivateEntity(g_iTriggerEnt[zone]);
//PrintToServer("Dispatched and activated %s", name);
TeleportEntity(g_iTriggerEnt[zone], mid, NULL_VECTOR, NULL_VECTOR);
SetEntityModel(g_iTriggerEnt[zone], "models/error.mdl");
//PrintToServer("Teleported and set model %s", name);
SetEntPropVector(g_iTriggerEnt[zone], Prop_Send, "m_vecMins", min);
SetEntPropVector(g_iTriggerEnt[zone], Prop_Send, "m_vecMaxs", max);
SetEntProp(g_iTriggerEnt[zone], Prop_Send, "m_nSolidType", 2);
//PrintToServer("Set vecs and solidtype %s", name);
int iEffects = GetEntProp(g_iTriggerEnt[zone], Prop_Send, "m_fEffects");
iEffects |= 0x020;
SetEntProp(g_iTriggerEnt[zone], Prop_Send, "m_fEffects", iEffects);
//PrintToServer("Set effects %s", name);
SDKHook(g_iTriggerEnt[zone], SDKHook_StartTouch, zoneStartTouch);
SDKHook(g_iTriggerEnt[zone], SDKHook_EndTouch, zoneEndTouch);
//PrintToServer("Hooks Hooked %s", name);
}
public Action zoneEndTouch (int caller, int client)
{
if (!isValidClient(client) || client == g_iEditor || !g_bActive)
return;
char trigName[16];
GetEntPropString(caller, Prop_Data, "m_iName", trigName, sizeof trigName);
//Player is Exiting Start Zone
if (StrEqual(trigName, "start"))
{
//Player is on starzone state, start run
if (g_iActivity[client] == 1)
{
CheckSpeed(client);
g_iActivity[client] = 0;
g_fStartTime[client] = GetEngineTime();
g_arrayRun[client].Clear();
}
}
//Player is Exiting End Zone
if (StrEqual(trigName, "end"))
{
//Set Player Inactive
g_iActivity[client] = -1;
//EndZoneRoutine(client);
}
}
public Action zoneStartTouch (int caller, int client)
{
if (!isValidClient(client) || client == g_iEditor || !g_bActive)
return;
char trigName[16];
GetEntPropString(caller, Prop_Data, "m_iName", trigName, sizeof trigName);
//Player is Entering Start Zone
if (StrEqual(trigName, "start"))
{
//Player teleported from endzone, exec endzoneroutine before reset
if (g_iActivity[client] == 2)
{
//EndZoneRoutine(client);
}
//TODO: Reset record array;
g_iActivity[client] = 1;
}
if (StrEqual(trigName, "end"))
{
if (g_iActivity[client] == 0)
{
ProcessFinish(client);
g_iActivity[client] = 2;
}
}
}
/*public void EndZoneRoutine(int client)
{
//TODO: Save Bot if needed
}*/