2017-03-01 21:05:40 +01:00
|
|
|
//====================================================================================================
|
|
|
|
//
|
|
|
|
// Name: [entWatch] Core
|
|
|
|
// Author: zaCade & Prometheum
|
|
|
|
// Description: Handle the core functions of [entWatch]
|
|
|
|
//
|
|
|
|
//====================================================================================================
|
|
|
|
#include <smlib>
|
|
|
|
|
|
|
|
#pragma newdecls required
|
|
|
|
|
|
|
|
#include <sourcemod>
|
|
|
|
#include <sdkhooks>
|
2017-10-12 21:53:17 +02:00
|
|
|
#include <sdktools>
|
2018-11-13 17:34:17 +01:00
|
|
|
#include <basic>
|
|
|
|
|
|
|
|
/* CLASSES */
|
2018-11-19 16:27:52 +01:00
|
|
|
#include "CConfig.inc"
|
2018-11-13 17:34:17 +01:00
|
|
|
#include "CItem.inc"
|
2017-03-01 21:05:40 +01:00
|
|
|
|
|
|
|
/* BOOLS */
|
|
|
|
bool g_bLate;
|
2018-08-08 17:31:50 +02:00
|
|
|
bool g_bIntermission;
|
2017-03-01 21:05:40 +01:00
|
|
|
|
2017-10-12 21:53:17 +02:00
|
|
|
/* ARRAYS */
|
2017-03-01 21:05:40 +01:00
|
|
|
ArrayList g_hArray_Items;
|
2018-11-13 17:34:17 +01:00
|
|
|
ArrayList g_hArray_Configs;
|
2017-03-01 21:05:40 +01:00
|
|
|
|
|
|
|
/* FORWARDS */
|
|
|
|
Handle g_hFwd_OnClientItemDrop;
|
|
|
|
Handle g_hFwd_OnClientItemDeath;
|
|
|
|
Handle g_hFwd_OnClientItemPickup;
|
|
|
|
Handle g_hFwd_OnClientItemActivate;
|
|
|
|
Handle g_hFwd_OnClientItemDisconnect;
|
|
|
|
|
|
|
|
/* HOOKS */
|
|
|
|
Handle g_hFwd_OnClientItemCanPickup;
|
|
|
|
Handle g_hFwd_OnClientItemCanActivate;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public Plugin myinfo =
|
|
|
|
{
|
|
|
|
name = "[entWatch] Core",
|
|
|
|
author = "zaCade & Prometheum",
|
|
|
|
description = "Handle the core functions of [entWatch]",
|
|
|
|
version = "4.0.0"
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int errorSize)
|
|
|
|
{
|
|
|
|
g_bLate = bLate;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
CreateNative("EW_GetItemCount", Native_GetItemCount);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
RegPluginLibrary("entWatch-core");
|
|
|
|
return APLRes_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnPluginStart()
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hFwd_OnClientItemDrop = CreateGlobalForward("EW_OnClientItemDrop", ET_Ignore, Param_Cell, Param_Cell);
|
|
|
|
g_hFwd_OnClientItemDeath = CreateGlobalForward("EW_OnClientItemDeath", ET_Ignore, Param_Cell, Param_Cell);
|
|
|
|
g_hFwd_OnClientItemPickup = CreateGlobalForward("EW_OnClientItemPickup", ET_Ignore, Param_Cell, Param_Cell);
|
|
|
|
g_hFwd_OnClientItemActivate = CreateGlobalForward("EW_OnClientItemActivate", ET_Ignore, Param_Cell, Param_Cell);
|
|
|
|
g_hFwd_OnClientItemDisconnect = CreateGlobalForward("EW_OnClientItemDisconnect", ET_Ignore, Param_Cell, Param_Cell);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hFwd_OnClientItemCanPickup = CreateGlobalForward("EW_OnClientItemCanPickup", ET_Hook, Param_Cell, Param_Cell);
|
|
|
|
g_hFwd_OnClientItemCanActivate = CreateGlobalForward("EW_OnClientItemCanActivate", ET_Hook, Param_Cell, Param_Cell);
|
2017-10-12 21:53:17 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items = new ArrayList();
|
|
|
|
g_hArray_Configs = new ArrayList();
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
HookEvent("player_death", OnClientDeath);
|
2017-10-12 21:53:17 +02:00
|
|
|
HookEvent("round_start", OnRoundStart);
|
2018-08-08 17:31:50 +02:00
|
|
|
HookEvent("round_end", OnRoundEnd);
|
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
if (g_bLate)
|
|
|
|
{
|
|
|
|
for (int client = 1; client <= MaxClients; client++)
|
|
|
|
{
|
|
|
|
if (!IsClientInGame(client) || IsFakeClient(client))
|
|
|
|
continue;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
SDKHook(client, SDKHook_WeaponEquipPost, OnWeaponPickup);
|
|
|
|
SDKHook(client, SDKHook_WeaponDropPost, OnWeaponDrop);
|
|
|
|
SDKHook(client, SDKHook_WeaponCanUse, OnWeaponTouch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnMapStart()
|
|
|
|
{
|
|
|
|
g_hArray_Items.Clear();
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Configs.Clear();
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
char sCurrentMap[128];
|
|
|
|
GetCurrentMap(sCurrentMap, sizeof(sCurrentMap));
|
2017-10-12 21:53:17 +02:00
|
|
|
String_ToLower(sCurrentMap, sCurrentMap, sizeof(sCurrentMap));
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
char sFilePathDefault[PLATFORM_MAX_PATH];
|
|
|
|
char sFilePathOverride[PLATFORM_MAX_PATH];
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-10-12 21:53:17 +02:00
|
|
|
BuildPath(Path_SM, sFilePathDefault, sizeof(sFilePathDefault), "configs/entwatch/%s.cfg", sCurrentMap);
|
|
|
|
BuildPath(Path_SM, sFilePathOverride, sizeof(sFilePathOverride), "configs/entwatch/%s.override.cfg", sCurrentMap);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
KeyValues hConfig = new KeyValues("items");
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
if (FileExists(sFilePathOverride))
|
|
|
|
{
|
|
|
|
if (!hConfig.ImportFromFile(sFilePathOverride))
|
|
|
|
{
|
|
|
|
LogMessage("Unable to load config \"%s\"!", sFilePathOverride);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
delete hConfig;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else LogMessage("Loaded config \"%s\"", sFilePathOverride);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!hConfig.ImportFromFile(sFilePathDefault))
|
|
|
|
{
|
|
|
|
LogMessage("Unable to load config \"%s\"!", sFilePathDefault);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
delete hConfig;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else LogMessage("Loaded config \"%s\"", sFilePathDefault);
|
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
if (hConfig.GotoFirstSubKey())
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2018-11-19 16:27:52 +01:00
|
|
|
CConfig config = new CConfig();
|
2018-11-13 17:34:17 +01:00
|
|
|
|
|
|
|
char sName[64], sShort[64], sColor[64], sFilter[64];
|
|
|
|
hConfig.GetString("name", sName, sizeof(sName));
|
|
|
|
hConfig.GetString("short", sShort, sizeof(sShort));
|
|
|
|
hConfig.GetString("color", sColor, sizeof(sColor));
|
|
|
|
hConfig.GetString("filter", sFilter, sizeof(sFilter));
|
|
|
|
|
2018-11-19 16:27:52 +01:00
|
|
|
config.SetName(sName);
|
|
|
|
config.SetShort(sShort);
|
|
|
|
config.SetColor(sColor);
|
|
|
|
config.SetFilter(sFilter);
|
2018-11-13 17:34:17 +01:00
|
|
|
|
2018-11-19 16:27:52 +01:00
|
|
|
config.iWeaponID = hConfig.GetNum("weaponid");
|
|
|
|
config.iButtonID = hConfig.GetNum("buttonid");
|
|
|
|
config.iTriggerID = hConfig.GetNum("triggerid");
|
|
|
|
config.iDisplay = hConfig.GetNum("display");
|
|
|
|
config.iMode = hConfig.GetNum("mode");
|
|
|
|
config.iMaxUses = hConfig.GetNum("maxuses");
|
|
|
|
config.iCooldown = hConfig.GetNum("cooldown");
|
2018-11-13 17:34:17 +01:00
|
|
|
|
2018-11-19 16:27:52 +01:00
|
|
|
g_hArray_Configs.Push(config);
|
2018-08-08 17:31:50 +02:00
|
|
|
}
|
2017-03-01 21:05:40 +01:00
|
|
|
while (hConfig.GotoNextKey());
|
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
delete hConfig;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-12 21:53:17 +02:00
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast)
|
|
|
|
{
|
2018-08-08 17:31:50 +02:00
|
|
|
g_bIntermission = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnRoundEnd(Event hEvent, const char[] sEvent, bool bDontBroadcast)
|
|
|
|
{
|
2017-10-12 21:53:17 +02:00
|
|
|
if (g_hArray_Items.Length)
|
2018-08-08 17:31:50 +02:00
|
|
|
g_hArray_Items.Clear();
|
2018-09-18 12:35:03 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_bIntermission = true;
|
2017-10-12 21:53:17 +02:00
|
|
|
}
|
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnEntityCreated(int entity, const char[] sClassname)
|
|
|
|
{
|
|
|
|
if (Entity_IsValid(entity))
|
|
|
|
{
|
|
|
|
SDKHook(entity, SDKHook_SpawnPost, OnEntitySpawned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnEntitySpawned(int entity)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
if (Entity_IsValid(entity) && g_hArray_Configs.Length)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
for (int index; index < g_hArray_Configs.Length; index++)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
CConfig config = g_hArray_Configs.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-12-02 16:03:53 +01:00
|
|
|
if (config.iWeaponID && config.iWeaponID == Entity_GetHammerId(entity))
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
if (PerformRegisterItem(config, entity, 1))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (config.iButtonID && config.iButtonID == Entity_GetHammerId(entity))
|
|
|
|
{
|
|
|
|
if (PerformRegisterItem(config, entity, 2))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (config.iTriggerID && config.iTriggerID == Entity_GetHammerId(entity))
|
|
|
|
{
|
|
|
|
if (PerformRegisterItem(config, entity, 3))
|
|
|
|
return;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-02 16:03:53 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-12-02 16:03:53 +01:00
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
stock bool PerformRegisterItem(CConfig config, int entity, int type)
|
|
|
|
{
|
|
|
|
bool bSuccessful;
|
|
|
|
|
|
|
|
if (Entity_IsValid(entity))
|
|
|
|
{
|
|
|
|
if (g_hArray_Items.Length)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
|
|
|
CItem item = g_hArray_Items.Get(index);
|
|
|
|
|
|
|
|
if (AttemptRegisterItem(item, entity, type))
|
|
|
|
{
|
|
|
|
g_hArray_Items.Set(index, item);
|
|
|
|
bSuccessful = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-19 16:27:52 +01:00
|
|
|
|
2018-12-02 16:03:53 +01:00
|
|
|
if (!bSuccessful)
|
|
|
|
{
|
|
|
|
CItem item = new CItem(config);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-12-02 16:03:53 +01:00
|
|
|
if (AttemptRegisterItem(item, entity, type))
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Push(item);
|
2018-12-02 16:03:53 +01:00
|
|
|
bSuccessful = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogError("Attempted to register new item, but failed! This should never happen.");
|
|
|
|
|
|
|
|
delete item;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-02 16:03:53 +01:00
|
|
|
|
|
|
|
return bSuccessful;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
2018-12-02 16:03:53 +01:00
|
|
|
stock bool AttemptRegisterItem(CItem item, int entity, int type)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
|
|
|
if (Entity_IsValid(entity))
|
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
switch(type)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
case(1):
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE))
|
|
|
|
{
|
|
|
|
item.iWeapon = entity;
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
2018-12-02 16:03:53 +01:00
|
|
|
case(2):
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
if (!item.bButton && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon)))
|
|
|
|
{
|
|
|
|
SDKHook(entity, SDKHook_Use, OnButtonPress);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-12-02 16:03:53 +01:00
|
|
|
item.iButton = entity;
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
2018-12-02 16:03:53 +01:00
|
|
|
case(3):
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-12-02 16:03:53 +01:00
|
|
|
if (!item.bTrigger && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon)))
|
|
|
|
{
|
|
|
|
SDKHook(entity, SDKHook_StartTouch, OnTriggerTouch);
|
|
|
|
SDKHook(entity, SDKHook_EndTouch, OnTriggerTouch);
|
|
|
|
SDKHook(entity, SDKHook_Touch, OnTriggerTouch);
|
|
|
|
|
|
|
|
item.iTrigger = entity;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
LogError("Attempted to register item with invalid type: %d! This should never happen.", type);
|
|
|
|
return false;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-02 16:03:53 +01:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnEntityDestroyed(int entity)
|
|
|
|
{
|
|
|
|
if (Entity_IsValid(entity) && g_hArray_Items.Length)
|
|
|
|
{
|
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bWeapon && item.iWeapon == entity)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
|
|
|
g_hArray_Items.Erase(index);
|
2018-12-02 16:03:53 +01:00
|
|
|
|
|
|
|
delete item;
|
2017-03-01 21:05:40 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-12-02 16:03:53 +01:00
|
|
|
else if (item.bButton && item.iButton == entity)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iButton = INVALID_ENT_REFERENCE;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-12-02 16:03:53 +01:00
|
|
|
else if (item.bTrigger && item.iTrigger == entity)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iTrigger = INVALID_ENT_REFERENCE;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnClientPutInServer(int client)
|
|
|
|
{
|
|
|
|
if (!IsFakeClient(client))
|
|
|
|
{
|
|
|
|
SDKHook(client, SDKHook_WeaponEquipPost, OnWeaponPickup);
|
|
|
|
SDKHook(client, SDKHook_WeaponDropPost, OnWeaponDrop);
|
|
|
|
SDKHook(client, SDKHook_WeaponCanUse, OnWeaponTouch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnClientDisconnect(int client)
|
|
|
|
{
|
2017-10-12 21:53:17 +02:00
|
|
|
if (!IsFakeClient(client) && g_hArray_Items.Length)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bOwner && item.iOwner == client)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iOwner = INVALID_ENT_REFERENCE;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
Call_StartForward(g_hFwd_OnClientItemDisconnect);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish();
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast)
|
|
|
|
{
|
2017-10-12 21:53:17 +02:00
|
|
|
int client = GetClientOfUserId(hEvent.GetInt("userid"));
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
if (Client_IsValid(client) && !IsFakeClient(client) && g_hArray_Items.Length)
|
|
|
|
{
|
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bOwner && item.iOwner == client)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iOwner = INVALID_ENT_REFERENCE;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
Call_StartForward(g_hFwd_OnClientItemDeath);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish();
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public Action OnWeaponPickup(int client, int weapon)
|
|
|
|
{
|
|
|
|
if (Client_IsValid(client) && Entity_IsValid(weapon) && g_hArray_Items.Length)
|
|
|
|
{
|
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bWeapon && item.iWeapon == weapon)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iOwner = client;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
Call_StartForward(g_hFwd_OnClientItemPickup);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish();
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public Action OnWeaponDrop(int client, int weapon)
|
|
|
|
{
|
|
|
|
if (Client_IsValid(client) && Entity_IsValid(weapon) && g_hArray_Items.Length)
|
|
|
|
{
|
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bWeapon && item.iWeapon == weapon)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iOwner = INVALID_ENT_REFERENCE;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
Call_StartForward(g_hFwd_OnClientItemDrop);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish();
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public Action OnButtonPress(int button, int client)
|
|
|
|
{
|
|
|
|
if (Client_IsValid(client) && Entity_IsValid(button) && g_hArray_Items.Length)
|
|
|
|
{
|
2017-10-12 21:53:17 +02:00
|
|
|
if (HasEntProp(button, Prop_Data, "m_bLocked") &&
|
|
|
|
GetEntProp(button, Prop_Data, "m_bLocked"))
|
|
|
|
return Plugin_Handled;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-19 16:27:52 +01:00
|
|
|
CConfig config = item.dConfig;
|
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bButton && item.iButton == button && item.bOwner && item.iOwner == client)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-08-08 17:31:50 +02:00
|
|
|
Action aResult;
|
|
|
|
Call_StartForward(g_hFwd_OnClientItemCanActivate);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish(aResult);
|
|
|
|
|
|
|
|
if ((aResult == Plugin_Continue) || (aResult == Plugin_Changed))
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-19 16:27:52 +01:00
|
|
|
switch(config.iMode)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-08-08 17:31:50 +02:00
|
|
|
case(1):
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.iTimeReady < RoundToCeil(GetEngineTime()))
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-19 16:27:52 +01:00
|
|
|
item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
else return Plugin_Handled;
|
|
|
|
}
|
|
|
|
case(2):
|
|
|
|
{
|
2018-11-19 16:27:52 +01:00
|
|
|
if (item.iTimesUsed < config.iMaxUses)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iTimesUsed++;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
else return Plugin_Handled;
|
|
|
|
}
|
|
|
|
case(3):
|
|
|
|
{
|
2018-11-19 16:27:52 +01:00
|
|
|
if (item.iTimeReady < RoundToCeil(GetEngineTime()) && item.iTimesUsed < config.iMaxUses)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-19 16:27:52 +01:00
|
|
|
item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iTimesUsed++;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
else return Plugin_Handled;
|
|
|
|
}
|
|
|
|
case(4):
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.iTimeReady < RoundToCeil(GetEngineTime()))
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iTimesUsed++;
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-19 16:27:52 +01:00
|
|
|
if (item.iTimesUsed >= config.iMaxUses)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-11-19 16:27:52 +01:00
|
|
|
item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
|
2018-11-13 17:34:17 +01:00
|
|
|
item.iTimesUsed = 0;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
else return Plugin_Handled;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
char sFilter[64];
|
2018-11-19 16:27:52 +01:00
|
|
|
if (config.GetFilter(sFilter, sizeof(sFilter)))
|
2018-11-13 17:34:17 +01:00
|
|
|
Entity_SetName(client, sFilter);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
|
|
|
Call_StartForward(g_hFwd_OnClientItemActivate);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish();
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2018-08-08 17:31:50 +02:00
|
|
|
return aResult;
|
2017-03-01 21:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public Action OnTriggerTouch(int trigger, int client)
|
|
|
|
{
|
|
|
|
if (Client_IsValid(client) && Entity_IsValid(trigger) && g_hArray_Items.Length)
|
|
|
|
{
|
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bTrigger && item.iTrigger == trigger)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-08-08 17:31:50 +02:00
|
|
|
if (g_bIntermission)
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
Action aResult;
|
|
|
|
Call_StartForward(g_hFwd_OnClientItemCanPickup);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish(aResult);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
return aResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public Action OnWeaponTouch(int client, int weapon)
|
|
|
|
{
|
|
|
|
if (Client_IsValid(client) && Entity_IsValid(weapon) && g_hArray_Items.Length)
|
|
|
|
{
|
|
|
|
for (int index; index < g_hArray_Items.Length; index++)
|
|
|
|
{
|
2018-11-13 17:34:17 +01:00
|
|
|
CItem item = g_hArray_Items.Get(index);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
if (item.bWeapon && item.iWeapon == weapon)
|
2017-03-01 21:05:40 +01:00
|
|
|
{
|
2018-08-08 17:31:50 +02:00
|
|
|
if (g_bIntermission)
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
2017-03-01 21:05:40 +01:00
|
|
|
Action aResult;
|
|
|
|
Call_StartForward(g_hFwd_OnClientItemCanPickup);
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(index);
|
|
|
|
Call_Finish(aResult);
|
2018-08-08 17:31:50 +02:00
|
|
|
|
2018-11-13 17:34:17 +01:00
|
|
|
g_hArray_Items.Set(index, item);
|
2017-03-01 21:05:40 +01:00
|
|
|
return aResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public int Native_GetItemCount(Handle hPlugin, int numParams)
|
|
|
|
{
|
|
|
|
return g_hArray_Items.Length;
|
|
|
|
}
|