diff --git a/TriggerRewards/scripting/TriggerRewards.sp b/TriggerRewards/scripting/TriggerRewards.sp new file mode 100644 index 00000000..f93c8c6b --- /dev/null +++ b/TriggerRewards/scripting/TriggerRewards.sp @@ -0,0 +1,129 @@ +#include +#include +#include +#include +#include +#include "loghelper.inc" + +#pragma semicolon 1 +#pragma newdecls required + +bool g_bDisabled[2048]; +bool g_bOnCD = false; + +ConVar g_cCD; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Plugin myinfo = +{ + name = "Trigger Rewards", + author = "Neon", + description = "HLSTATS Trigger Rewards", + version = "1.0", + url = "https://steamcommunity.com/id/n3ontm" +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnPluginStart() +{ + g_cCD = CreateConVar("sm_trigger_reward_cd", "10.0", "Cooldown between HLSTATS Trigger rewards", 0, true, 0.1); + AutoExecConfig(true, "plugin.TriggerRewards"); + + HookEvent("round_start", OnRoundStart); + HookEntityOutput("trigger_once", "OnStartTouch", OnStartTouch); + HookEntityOutput("func_button", "OnPressed", OnPressed); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnMapStart() +{ + GetTeams(); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast) +{ + for(int i = 0; i < 2048; i++) + g_bDisabled[i] = false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnStartTouch(const char[] sOutput, int iCaller, int iActivator, float fDelay) +{ + if (!IsValidClient(iActivator)) + return; + + if (g_bDisabled[iCaller] || g_bOnCD) + return; + + if (!(ZR_IsClientHuman(iActivator))) + return; + + g_bDisabled[iCaller] = true; + g_bOnCD = true; + + CreateTimer(g_cCD.FloatValue, ResetCD); + + LogPlayerEvent(iActivator, "triggered", "trigger"); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnPressed(const char[] sOutput, int iCaller, int iActivator, float fDelay) +{ + if(!IsValidClient(iActivator)) + return; + + if (g_bDisabled[iCaller] || g_bOnCD) + return; + + if (!(ZR_IsClientHuman(iActivator))) + return; + + int iParent = INVALID_ENT_REFERENCE; + if ((iParent = GetEntPropEnt(iCaller, Prop_Data, "m_hMoveParent")) != INVALID_ENT_REFERENCE) + { + char sClassname[64]; + GetEdictClassname(iParent, sClassname, sizeof(sClassname)); + + if (strncmp(sClassname, "weapon_", 7, false) == 0) + return; + } + + g_bDisabled[iCaller] = true; + g_bOnCD = true; + + CreateTimer(g_cCD.FloatValue, ResetCD); + + LogPlayerEvent(iActivator, "triggered", "trigger"); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action ResetCD(Handle timer) +{ + g_bOnCD = false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public bool IsValidClient(int iClient) +{ + if ( !( 1 <= iClient <= MaxClients ) || !IsClientInGame(iClient) || !IsPlayerAlive(iClient)) + return false; + + return true; +} diff --git a/includes/loghelper.inc b/includes/loghelper.inc new file mode 120000 index 00000000..9b177baf --- /dev/null +++ b/includes/loghelper.inc @@ -0,0 +1 @@ +../hlstatsx/scripting/include/loghelper.inc \ No newline at end of file