added HLstatsX CE - LogHelper
This commit is contained in:
parent
b250cb13fe
commit
83a49778e8
175
hlstatsx/scripting/hlstatsx_loghelper.sp
Normal file
175
hlstatsx/scripting/hlstatsx_loghelper.sp
Normal file
@ -0,0 +1,175 @@
|
||||
#pragma semicolon 1
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
#undef REQUIRE_PLUGIN
|
||||
#tryinclude <HappyHour>
|
||||
#define REQUIRE_PLUGIN
|
||||
|
||||
#pragma newdecls required
|
||||
|
||||
bool g_bHHLoaded;
|
||||
|
||||
char g_sTeamList[16][64];
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "HLstatsX CE - LogHelper",
|
||||
author = "Neon",
|
||||
description = "Custom HLstatsX Logging",
|
||||
version = "1.0.0"
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int errorSize)
|
||||
{
|
||||
CreateNative("LH_LogPlayerEvent", Native_LogPlayerEvent);
|
||||
|
||||
RegPluginLibrary("HlstatsXLogHelper");
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnAllPluginsLoaded()
|
||||
{
|
||||
g_bHHLoaded = LibraryExists("HappyHour");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnLibraryAdded(const char[] sName)
|
||||
{
|
||||
if (strcmp(sName, "HappyHour", false) == 0)
|
||||
g_bHHLoaded = true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnLibraryRemoved(const char[] sName)
|
||||
{
|
||||
if (strcmp(sName, "HappyHour", false) == 0)
|
||||
g_bHHLoaded = false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnMapStart()
|
||||
{
|
||||
GetTeams();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public int Native_LogPlayerEvent(Handle hPlugin, int numParams)
|
||||
{
|
||||
int iClient;
|
||||
char sVerb[64];
|
||||
char sEvent[256];
|
||||
bool bHH;
|
||||
|
||||
iClient = GetNativeCell(1);
|
||||
GetNativeString(2, sVerb, sizeof(sVerb));
|
||||
GetNativeString(3, sEvent, sizeof(sEvent));
|
||||
bHH = GetNativeCell(4);
|
||||
|
||||
if (iClient < 1 || iClient > MaxClients)
|
||||
{
|
||||
return ThrowNativeError(SP_ERROR_NATIVE, "Client index %d is invalid", iClient);
|
||||
}
|
||||
else if (!IsClientInGame(iClient))
|
||||
{
|
||||
return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not ingame", iClient);
|
||||
}
|
||||
|
||||
LogPlayerEventCustom(iClient, sVerb, sEvent, bHH);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock void LogPlayerEventCustom(int client, const char[] verb, const char[] event, bool hh)
|
||||
{
|
||||
if (!IsValidPlayer(client))
|
||||
return;
|
||||
|
||||
char player_authid[32];
|
||||
if (!GetClientAuthId(client, AuthId_Engine, player_authid, sizeof(player_authid), false))
|
||||
strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
|
||||
|
||||
|
||||
char sEvent[256];
|
||||
Format(sEvent, sizeof(sEvent), "%s", event);
|
||||
|
||||
if (g_bHHLoaded && HH_IsItHappyHour() && hh)
|
||||
Format(sEvent, sizeof(sEvent), "%s_hh", sEvent);
|
||||
|
||||
char sLog[512];
|
||||
Format(sLog, sizeof(sLog), "\"%N<%d><%s><%s>\" %s \"%s\"", client, GetClientUserId(client), player_authid, g_sTeamList[GetClientTeam(client)], verb, sEvent);
|
||||
|
||||
LogToGame(sLog);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock void GetTeams(bool insmod = false)
|
||||
{
|
||||
if (!insmod)
|
||||
{
|
||||
int max_teams_count = GetTeamCount();
|
||||
for (int team_index = 0; (team_index < max_teams_count); team_index++)
|
||||
{
|
||||
char team_name[64];
|
||||
GetTeamName(team_index, team_name, sizeof(team_name));
|
||||
|
||||
if (strcmp(team_name, "") != 0)
|
||||
{
|
||||
g_sTeamList[team_index] = team_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// they really need to get their act together... GetTeamName() would be awesome since they can't even keep their team indexes consistent
|
||||
char mapname[64];
|
||||
GetCurrentMap(mapname, sizeof(mapname));
|
||||
if (strcmp(mapname, "ins_karam") == 0 || strcmp(mapname, "ins_baghdad") == 0)
|
||||
{
|
||||
g_sTeamList[1] = "Iraqi Insurgents";
|
||||
g_sTeamList[2] = "U.S. Marines";
|
||||
}
|
||||
else
|
||||
{
|
||||
g_sTeamList[1] = "U.S. Marines";
|
||||
g_sTeamList[2] = "Iraqi Insurgents";
|
||||
}
|
||||
g_sTeamList[0] = "Unassigned";
|
||||
g_sTeamList[3] = "SPECTATOR";
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
static stock bool IsValidPlayer(int client)
|
||||
{
|
||||
if (client > 0 && client <= MaxClients && IsClientInGame(client))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
38
hlstatsx/scripting/include/hlstatsx_loghelper.inc
Normal file
38
hlstatsx/scripting/include/hlstatsx_loghelper.inc
Normal file
@ -0,0 +1,38 @@
|
||||
#if defined _HlstatsXLogHelper_included
|
||||
#endinput
|
||||
#endif
|
||||
|
||||
#define _HlstatsXLogHelper_included
|
||||
|
||||
/**
|
||||
* Logs a custom player event to the game.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @param verb The verb to log.
|
||||
* @param event The event to log.
|
||||
* @param happyhour If event should be altered during happy hour.
|
||||
*
|
||||
* @return True on success, false otherwise.
|
||||
* @error Invalid client index or not ingame.
|
||||
*/
|
||||
native bool LH_LogPlayerEvent(int client, char[] verb, char[] event, bool happyhour = false);
|
||||
|
||||
|
||||
public SharedPlugin __pl_HlstatsXLogHelper =
|
||||
{
|
||||
name = "HlstatsXLogHelper",
|
||||
file = "hlstatsx_loghelper.smx",
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1
|
||||
#else
|
||||
required = 0
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined REQUIRE_PLUGIN
|
||||
public void __pl_HlstatsXLogHelper_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("LH_LogPlayerEvent");
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user