entWatch4: Update to class instead of struct enum.

And some other cleanup stuff.
This commit is contained in:
zaCade 2018-11-13 17:34:17 +01:00
parent 5c37acb50e
commit 2238db206c
6 changed files with 421 additions and 200 deletions

View File

@ -0,0 +1,298 @@
#if defined entWatch_class_item_included
#endinput
#endif
#define entWatch_class_item_included
methodmap CItem < Basic
{
public CItem()
{
Basic myclass = new Basic();
myclass.SetString("sName", "");
myclass.SetString("sShort", "");
myclass.SetString("sColor", "");
myclass.SetString("sFilter", "");
myclass.SetInt("iButtonID", 0);
myclass.SetInt("iWeaponID", 0);
myclass.SetInt("iTriggerID", 0);
myclass.SetInt("iOwner", INVALID_ENT_REFERENCE);
myclass.SetInt("iButton", INVALID_ENT_REFERENCE);
myclass.SetInt("iWeapon", INVALID_ENT_REFERENCE);
myclass.SetInt("iTrigger", INVALID_ENT_REFERENCE);
myclass.SetInt("iDisplay", 0);
myclass.SetInt("iMode", 0);
myclass.SetInt("iMaxUses", 0);
myclass.SetInt("iCooldown", 0);
myclass.SetInt("iTimesUsed", 0);
myclass.SetInt("iTimeReady", 0);
return view_as<CItem>(myclass);
}
public bool GetName(char[] buffer, int length)
{
return this.GetString("sName", buffer, length);
}
public void SetName(const char[] buffer)
{
this.SetString("sName", buffer);
}
public bool GetShort(char[] buffer, int length)
{
return this.GetString("sShort", buffer, length);
}
public void SetShort(const char[] buffer)
{
this.SetString("sShort", buffer);
}
public bool GetColor(char[] buffer, int length)
{
return this.GetString("sColor", buffer, length);
}
public void SetColor(const char[] buffer)
{
this.SetString("sColor", buffer);
}
public bool GetFilter(char[] buffer, int length)
{
return this.GetString("sFilter", buffer, length);
}
public void SetFilter(const char[] buffer)
{
this.SetString("sFilter", buffer);
}
property int iButtonID
{
public get()
{
return this.GetInt("iButtonID");
}
public set(int value)
{
this.SetInt("iButtonID", value);
}
}
property int iWeaponID
{
public get()
{
return this.GetInt("iWeaponID");
}
public set(int value)
{
this.SetInt("iWeaponID", value);
}
}
property int iTriggerID
{
public get()
{
return this.GetInt("iTriggerID");
}
public set(int value)
{
this.SetInt("iTriggerID", value);
}
}
property int iOwner
{
public get()
{
return this.GetInt("iOwner");
}
public set(int value)
{
this.SetInt("iOwner", value);
}
}
property int iButton
{
public get()
{
return this.GetInt("iButton");
}
public set(int value)
{
this.SetInt("iButton", value);
}
}
property int iWeapon
{
public get()
{
return this.GetInt("iWeapon");
}
public set(int value)
{
this.SetInt("iWeapon", value);
}
}
property int iTrigger
{
public get()
{
return this.GetInt("iTrigger");
}
public set(int value)
{
this.SetInt("iTrigger", value);
}
}
property int iDisplay
{
public get()
{
return this.GetInt("iDisplay");
}
public set(int value)
{
this.SetInt("iDisplay", value);
}
}
property int iMode
{
public get()
{
return this.GetInt("iMode");
}
public set(int value)
{
this.SetInt("iMode", value);
}
}
property int iMaxUses
{
public get()
{
return this.GetInt("iMaxUses");
}
public set(int value)
{
this.SetInt("iMaxUses", value);
}
}
property int iCooldown
{
public get()
{
return this.GetInt("iCooldown");
}
public set(int value)
{
this.SetInt("iCooldown", value);
}
}
property int iTimesUsed
{
public get()
{
return this.GetInt("iTimesUsed");
}
public set(int value)
{
this.SetInt("iTimesUsed", value);
}
}
property int iTimeReady
{
public get()
{
return this.GetInt("iTimeReady");
}
public set(int value)
{
this.SetInt("iTimeReady", value);
}
}
property bool bOwner
{
public get()
{
return view_as<bool>(this.iOwner != INVALID_ENT_REFERENCE);
}
}
property bool bButton
{
public get()
{
return view_as<bool>(this.iButton != INVALID_ENT_REFERENCE);
}
}
property bool bWeapon
{
public get()
{
return view_as<bool>(this.iWeapon != INVALID_ENT_REFERENCE);
}
}
property bool bTrigger
{
public get()
{
return view_as<bool>(this.iTrigger != INVALID_ENT_REFERENCE);
}
}
property bool bDisplayEventMessages
{
public get()
{
return view_as<bool>(this.iDisplay & (1<<0));
}
}
property bool bDisplayActivateMessages
{
public get()
{
return view_as<bool>(this.iDisplay & (1<<1));
}
}
property bool bDisplayInterface
{
public get()
{
return view_as<bool>(this.iDisplay & (1<<2));
}
}
}

View File

@ -12,7 +12,10 @@
#include <sourcemod> #include <sourcemod>
#include <sdkhooks> #include <sdkhooks>
#include <sdktools> #include <sdktools>
#include <entWatch_core> #include <basic>
/* CLASSES */
#include "CItem.inc"
/* BOOLS */ /* BOOLS */
bool g_bLate; bool g_bLate;
@ -20,7 +23,7 @@ bool g_bIntermission;
/* ARRAYS */ /* ARRAYS */
ArrayList g_hArray_Items; ArrayList g_hArray_Items;
ArrayList g_hArray_Config; ArrayList g_hArray_Configs;
/* FORWARDS */ /* FORWARDS */
Handle g_hFwd_OnClientItemDrop; Handle g_hFwd_OnClientItemDrop;
@ -52,8 +55,6 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int erro
g_bLate = bLate; g_bLate = bLate;
CreateNative("EW_GetItemCount", Native_GetItemCount); CreateNative("EW_GetItemCount", Native_GetItemCount);
CreateNative("EW_GetItemArray", Native_GetItemArray);
CreateNative("EW_SetItemArray", Native_SetItemArray);
RegPluginLibrary("entWatch-core"); RegPluginLibrary("entWatch-core");
return APLRes_Success; return APLRes_Success;
@ -64,17 +65,17 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int erro
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnPluginStart() public void OnPluginStart()
{ {
g_hFwd_OnClientItemDrop = CreateGlobalForward("EW_OnClientItemDrop", ET_Ignore, Param_Array, Param_Cell, Param_Cell); g_hFwd_OnClientItemDrop = CreateGlobalForward("EW_OnClientItemDrop", ET_Ignore, Param_Cell, Param_Cell);
g_hFwd_OnClientItemDeath = CreateGlobalForward("EW_OnClientItemDeath", ET_Ignore, Param_Array, 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_Array, 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_Array, 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_Array, Param_Cell, Param_Cell); g_hFwd_OnClientItemDisconnect = CreateGlobalForward("EW_OnClientItemDisconnect", ET_Ignore, Param_Cell, Param_Cell);
g_hFwd_OnClientItemCanPickup = CreateGlobalForward("EW_OnClientItemCanPickup", ET_Hook, Param_Array, Param_Cell, Param_Cell); g_hFwd_OnClientItemCanPickup = CreateGlobalForward("EW_OnClientItemCanPickup", ET_Hook, Param_Cell, Param_Cell);
g_hFwd_OnClientItemCanActivate = CreateGlobalForward("EW_OnClientItemCanActivate", ET_Hook, Param_Array, Param_Cell, Param_Cell); g_hFwd_OnClientItemCanActivate = CreateGlobalForward("EW_OnClientItemCanActivate", ET_Hook, Param_Cell, Param_Cell);
g_hArray_Items = new ArrayList(512); g_hArray_Items = new ArrayList();
g_hArray_Config = new ArrayList(512); g_hArray_Configs = new ArrayList();
HookEvent("player_death", OnClientDeath); HookEvent("player_death", OnClientDeath);
HookEvent("round_start", OnRoundStart); HookEvent("round_start", OnRoundStart);
@ -100,7 +101,7 @@ public void OnPluginStart()
public void OnMapStart() public void OnMapStart()
{ {
g_hArray_Items.Clear(); g_hArray_Items.Clear();
g_hArray_Config.Clear(); g_hArray_Configs.Clear();
char sCurrentMap[128]; char sCurrentMap[128];
GetCurrentMap(sCurrentMap, sizeof(sCurrentMap)); GetCurrentMap(sCurrentMap, sizeof(sCurrentMap));
@ -141,21 +142,28 @@ public void OnMapStart()
{ {
do do
{ {
any itemArray[items]; CItem item = new CItem();
hConfig.GetString("name", itemArray[item_name], sizeof(itemArray[item_name]));
hConfig.GetString("short", itemArray[item_short], sizeof(itemArray[item_short]));
hConfig.GetString("color", itemArray[item_color], sizeof(itemArray[item_color]));
hConfig.GetString("filter", itemArray[item_filter], sizeof(itemArray[item_filter]));
itemArray[item_weaponid] = hConfig.GetNum("weaponid"); char sName[64], sShort[64], sColor[64], sFilter[64];
itemArray[item_buttonid] = hConfig.GetNum("buttonid"); hConfig.GetString("name", sName, sizeof(sName));
itemArray[item_triggerid] = hConfig.GetNum("triggerid"); hConfig.GetString("short", sShort, sizeof(sShort));
itemArray[item_display] = hConfig.GetNum("display"); hConfig.GetString("color", sColor, sizeof(sColor));
itemArray[item_mode] = hConfig.GetNum("mode"); hConfig.GetString("filter", sFilter, sizeof(sFilter));
itemArray[item_maxuses] = hConfig.GetNum("maxuses");
itemArray[item_cooldown] = hConfig.GetNum("cooldown");
g_hArray_Config.PushArray(itemArray, sizeof(itemArray)); item.SetName(sName);
item.SetShort(sShort);
item.SetColor(sColor);
item.SetFilter(sFilter);
item.iWeaponID = hConfig.GetNum("weaponid");
item.iButtonID = hConfig.GetNum("buttonid");
item.iTriggerID = hConfig.GetNum("triggerid");
item.iDisplay = hConfig.GetNum("display");
item.iMode = hConfig.GetNum("mode");
item.iMaxUses = hConfig.GetNum("maxuses");
item.iCooldown = hConfig.GetNum("cooldown");
g_hArray_Configs.Push(item);
} }
while (hConfig.GotoNextKey()); while (hConfig.GotoNextKey());
} }
@ -180,7 +188,7 @@ public void OnRoundEnd(Event hEvent, const char[] sEvent, bool bDontBroadcast)
if (g_hArray_Items.Length) if (g_hArray_Items.Length)
g_hArray_Items.Clear(); g_hArray_Items.Clear();
G_bIntermission = true; g_bIntermission = true;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -199,28 +207,26 @@ public void OnEntityCreated(int entity, const char[] sClassname)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnEntitySpawned(int entity) public void OnEntitySpawned(int entity)
{ {
if (Entity_IsValid(entity) && g_hArray_Config.Length) if (Entity_IsValid(entity) && g_hArray_Configs.Length)
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (RegisterItem(itemArray, entity)) if (RegisterItem(item, entity))
{ {
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return; return;
} }
} }
for (int index; index < g_hArray_Config.Length; index++) for (int index; index < g_hArray_Configs.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Configs.Get(index);
g_hArray_Config.GetArray(index, itemArray, sizeof(itemArray));
if (RegisterItem(itemArray, entity)) if (RegisterItem(item, entity))
{ {
g_hArray_Items.PushArray(itemArray, sizeof(itemArray)); g_hArray_Items.Push(item);
return; return;
} }
} }
@ -230,39 +236,37 @@ public void OnEntitySpawned(int entity)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
stock bool RegisterItem(any[] itemArray, int entity) stock bool RegisterItem(CItem item, int entity)
{ {
if (Entity_IsValid(entity)) if (Entity_IsValid(entity))
{ {
if (itemArray[item_weaponid] && itemArray[item_weaponid] == Entity_GetHammerId(entity)) if (item.iWeaponID && item.iWeaponID == Entity_GetHammerId(entity))
{ {
if (!itemArray[item_weapon] && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE)) if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE))
{ {
itemArray[item_weapon] = entity; item.iWeapon = entity;
return true; return true;
} }
} }
else if (itemArray[item_buttonid] && itemArray[item_buttonid] == Entity_GetHammerId(entity)) else if (item.iButtonID && item.iButtonID == Entity_GetHammerId(entity))
{ {
if (!itemArray[item_button] && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || if (!item.bButton && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon)))
(itemArray[item_weapon] && Entity_GetParent(entity) == itemArray[item_weapon])))
{ {
SDKHook(entity, SDKHook_Use, OnButtonPress); SDKHook(entity, SDKHook_Use, OnButtonPress);
itemArray[item_button] = entity; item.iButton = entity;
return true; return true;
} }
} }
else if (itemArray[item_triggerid] && itemArray[item_triggerid] == Entity_GetHammerId(entity)) else if (item.iTriggerID && item.iTriggerID == Entity_GetHammerId(entity))
{ {
if (!itemArray[item_trigger] && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || if (!item.bTrigger && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon)))
(itemArray[item_weapon] && Entity_GetParent(entity) == itemArray[item_weapon])))
{ {
SDKHook(entity, SDKHook_StartTouch, OnTriggerTouch); SDKHook(entity, SDKHook_StartTouch, OnTriggerTouch);
SDKHook(entity, SDKHook_EndTouch, OnTriggerTouch); SDKHook(entity, SDKHook_EndTouch, OnTriggerTouch);
SDKHook(entity, SDKHook_Touch, OnTriggerTouch); SDKHook(entity, SDKHook_Touch, OnTriggerTouch);
itemArray[item_trigger] = entity; item.iTrigger = entity;
return true; return true;
} }
} }
@ -279,28 +283,27 @@ public void OnEntityDestroyed(int entity)
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_weapon] && itemArray[item_weapon] == entity) if (item.bWeapon && item.iWeapon == entity)
{ {
g_hArray_Items.Erase(index); g_hArray_Items.Erase(index);
return; return;
} }
if (itemArray[item_button] && itemArray[item_button] == entity) if (item.bButton && item.iButton == entity)
{ {
itemArray[item_button] = INVALID_ENT_REFERENCE; item.iButton = INVALID_ENT_REFERENCE;
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return; return;
} }
if (itemArray[item_trigger] && itemArray[item_trigger] == entity) if (item.bTrigger && item.iTrigger == entity)
{ {
itemArray[item_trigger] = INVALID_ENT_REFERENCE; item.iTrigger = INVALID_ENT_REFERENCE;
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return; return;
} }
} }
@ -329,21 +332,18 @@ public void OnClientDisconnect(int client)
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_owned] && itemArray[item_owner] == client) if (item.bOwner && item.iOwner == client)
{ {
itemArray[item_owner] = INVALID_ENT_REFERENCE; item.iOwner = INVALID_ENT_REFERENCE;
itemArray[item_owned] = false;
Call_StartForward(g_hFwd_OnClientItemDisconnect); Call_StartForward(g_hFwd_OnClientItemDisconnect);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(); Call_Finish();
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
} }
} }
} }
@ -360,21 +360,18 @@ public void OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_owned] && itemArray[item_owner] == client) if (item.bOwner && item.iOwner == client)
{ {
itemArray[item_owner] = INVALID_ENT_REFERENCE; item.iOwner = INVALID_ENT_REFERENCE;
itemArray[item_owned] = false;
Call_StartForward(g_hFwd_OnClientItemDeath); Call_StartForward(g_hFwd_OnClientItemDeath);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(); Call_Finish();
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
} }
} }
} }
@ -389,21 +386,18 @@ public Action OnWeaponPickup(int client, int weapon)
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_weapon] && itemArray[item_weapon] == weapon) if (item.bWeapon && item.iWeapon == weapon)
{ {
itemArray[item_owner] = client; item.iOwner = client;
itemArray[item_owned] = true;
Call_StartForward(g_hFwd_OnClientItemPickup); Call_StartForward(g_hFwd_OnClientItemPickup);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(); Call_Finish();
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return; return;
} }
} }
@ -419,21 +413,18 @@ public Action OnWeaponDrop(int client, int weapon)
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_weapon] && itemArray[item_weapon] == weapon) if (item.bWeapon && item.iWeapon == weapon)
{ {
itemArray[item_owner] = INVALID_ENT_REFERENCE; item.iOwner = INVALID_ENT_REFERENCE;
itemArray[item_owned] = false;
Call_StartForward(g_hFwd_OnClientItemDrop); Call_StartForward(g_hFwd_OnClientItemDrop);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(); Call_Finish();
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return; return;
} }
} }
@ -453,75 +444,72 @@ public Action OnButtonPress(int button, int client)
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_button] && itemArray[item_button] == button && if (item.bButton && item.iButton == button && item.bOwner && item.iOwner == client)
itemArray[item_owned] && itemArray[item_owner] == client)
{ {
Action aResult; Action aResult;
Call_StartForward(g_hFwd_OnClientItemCanActivate); Call_StartForward(g_hFwd_OnClientItemCanActivate);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(aResult); Call_Finish(aResult);
if ((aResult == Plugin_Continue) || (aResult == Plugin_Changed)) if ((aResult == Plugin_Continue) || (aResult == Plugin_Changed))
{ {
switch(itemArray[item_mode]) switch(item.iMode)
{ {
case(1): case(1):
{ {
if (itemArray[item_nextuse] < RoundToCeil(GetEngineTime())) if (item.iTimeReady < RoundToCeil(GetEngineTime()))
{ {
itemArray[item_nextuse] = RoundToCeil(GetEngineTime()) + itemArray[item_cooldown]; item.iTimeReady = RoundToCeil(GetEngineTime()) + item.iCooldown;
} }
else return Plugin_Handled; else return Plugin_Handled;
} }
case(2): case(2):
{ {
if (itemArray[item_uses] < itemArray[item_maxuses]) if (item.iTimesUsed < item.iMaxUses)
{ {
itemArray[item_uses]++; item.iTimesUsed++;
} }
else return Plugin_Handled; else return Plugin_Handled;
} }
case(3): case(3):
{ {
if (itemArray[item_nextuse] < RoundToCeil(GetEngineTime()) && itemArray[item_uses] < itemArray[item_maxuses]) if (item.iTimeReady < RoundToCeil(GetEngineTime()) && item.iTimesUsed < item.iMaxUses)
{ {
itemArray[item_nextuse] = RoundToCeil(GetEngineTime()) + itemArray[item_cooldown]; item.iTimeReady = RoundToCeil(GetEngineTime()) + item.iCooldown;
itemArray[item_uses]++; item.iTimesUsed++;
} }
else return Plugin_Handled; else return Plugin_Handled;
} }
case(4): case(4):
{ {
if (itemArray[item_nextuse] < RoundToCeil(GetEngineTime())) if (item.iTimeReady < RoundToCeil(GetEngineTime()))
{ {
itemArray[item_uses]++; item.iTimesUsed++;
if (itemArray[item_uses] >= itemArray[item_maxuses]) if (item.iTimesUsed >= item.iMaxUses)
{ {
itemArray[item_nextuse] = RoundToCeil(GetEngineTime()) + itemArray[item_cooldown]; item.iTimeReady = RoundToCeil(GetEngineTime()) + item.iCooldown;
itemArray[item_uses] = 0; item.iTimesUsed = 0;
} }
} }
else return Plugin_Handled; else return Plugin_Handled;
} }
} }
if (itemArray[item_filter][0]) char sFilter[64];
Entity_SetName(client, itemArray[item_filter]); if (item.GetFilter(sFilter, sizeof(sFilter)))
Entity_SetName(client, sFilter);
Call_StartForward(g_hFwd_OnClientItemActivate); Call_StartForward(g_hFwd_OnClientItemActivate);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(); Call_Finish();
} }
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return aResult; return aResult;
} }
} }
@ -538,22 +526,20 @@ public Action OnTriggerTouch(int trigger, int client)
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_trigger] && itemArray[item_trigger] == trigger) if (item.bTrigger && item.iTrigger == trigger)
{ {
if (g_bIntermission) if (g_bIntermission)
return Plugin_Handled; return Plugin_Handled;
Action aResult; Action aResult;
Call_StartForward(g_hFwd_OnClientItemCanPickup); Call_StartForward(g_hFwd_OnClientItemCanPickup);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(aResult); Call_Finish(aResult);
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return aResult; return aResult;
} }
} }
@ -570,22 +556,20 @@ public Action OnWeaponTouch(int client, int weapon)
{ {
for (int index; index < g_hArray_Items.Length; index++) for (int index; index < g_hArray_Items.Length; index++)
{ {
any itemArray[items]; CItem item = g_hArray_Items.Get(index);
g_hArray_Items.GetArray(index, itemArray, sizeof(itemArray));
if (itemArray[item_weapon] && itemArray[item_weapon] == weapon) if (item.bWeapon && item.iWeapon == weapon)
{ {
if (g_bIntermission) if (g_bIntermission)
return Plugin_Handled; return Plugin_Handled;
Action aResult; Action aResult;
Call_StartForward(g_hFwd_OnClientItemCanPickup); Call_StartForward(g_hFwd_OnClientItemCanPickup);
Call_PushArray(itemArray, sizeof(itemArray));
Call_PushCell(client); Call_PushCell(client);
Call_PushCell(index); Call_PushCell(index);
Call_Finish(aResult); Call_Finish(aResult);
g_hArray_Items.SetArray(index, itemArray, sizeof(itemArray)); g_hArray_Items.Set(index, item);
return aResult; return aResult;
} }
} }
@ -600,33 +584,3 @@ public int Native_GetItemCount(Handle hPlugin, int numParams)
{ {
return g_hArray_Items.Length; return g_hArray_Items.Length;
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int Native_GetItemArray(Handle hPlugin, int numParams)
{
any itemArray[items];
int index = GetNativeCell(1);
int size = GetNativeCell(3);
g_hArray_Items.GetArray(index, itemArray, size);
SetNativeArray(2, itemArray, size);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int Native_SetItemArray(Handle hPlugin, int numParams)
{
any itemArray[items];
int index = GetNativeCell(1);
int size = GetNativeCell(3);
GetNativeArray(2, itemArray, size);
g_hArray_Items.SetArray(index, itemArray, size);
}

View File

@ -34,35 +34,35 @@ public void OnPluginStart()
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void EW_OnClientItemDrop(any[] itemArray, int client, int index) public void EW_OnClientItemDrop(int client, int index)
{ {
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void EW_OnClientItemDeath(any[] itemArray, int client, int index) public void EW_OnClientItemDeath(int client, int index)
{ {
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void EW_OnClientItemPickup(any[] itemArray, int client, int index) public void EW_OnClientItemPickup(int client, int index)
{ {
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void EW_OnClientItemDisconnect(any[] itemArray, int client, int index) public void EW_OnClientItemDisconnect(int client, int index)
{ {
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void EW_OnClientItemActivate(any[] itemArray, int client, int index) public void EW_OnClientItemActivate(int client, int index)
{ {
} }

View File

@ -160,7 +160,7 @@ public Action Command_ClientUnrestrict(int client, int args)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action EW_OnClientItemCanPickup(any[] itemArray, int client, int index) public Action EW_OnClientItemCanPickup(int client, int index)
{ {
return ClientRestricted(client)?Plugin_Handled:Plugin_Continue; return ClientRestricted(client)?Plugin_Handled:Plugin_Continue;
} }
@ -168,7 +168,7 @@ public Action EW_OnClientItemCanPickup(any[] itemArray, int client, int index)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action EW_OnClientItemCanActivate(any[] itemArray, int client, int index) public Action EW_OnClientItemCanActivate(int client, int index)
{ {
return ClientRestricted(client)?Plugin_Handled:Plugin_Continue; return ClientRestricted(client)?Plugin_Handled:Plugin_Continue;
} }

View File

@ -4,46 +4,6 @@
#define entWatch_core_included #define entWatch_core_included
#define DISPLAY_CHAT (1 << 0)
#define DISPLAY_HUD (1 << 1)
#define DISPLAY_USE (1 << 2)
enum items
{
String:item_name[32],
String:item_short[32],
String:item_color[32],
String:item_filter[32],
bool:item_owned,
item_buttonid,
item_weaponid,
item_triggerid,
item_owner,
item_button,
item_weapon,
item_trigger,
item_display,
item_mode,
item_uses,
item_maxuses,
item_nextuse,
item_cooldown,
};
native int EW_GetItemCount();
native void EW_GetItemArray(int index, any[] itemArray, int size);
native void EW_SetItemArray(int index, any[] itemArray, int size);
forward void EW_OnClientItemDrop(any[] itemArray, int client, int index);
forward void EW_OnClientItemDeath(any[] itemArray, int client, int index);
forward void EW_OnClientItemPickup(any[] itemArray, int client, int index);
forward void EW_OnClientItemActivate(any[] itemArray, int client, int index);
forward void EW_OnClientItemDisconnect(any[] itemArray, int client, int index);
forward Action EW_OnClientItemCanPickup(any[] itemArray, int client, int index);
forward Action EW_OnClientItemCanActivate(any[] itemArray, int client, int index);
public SharedPlugin __pl_entWatch_core = public SharedPlugin __pl_entWatch_core =
{ {
name = "entWatch-core", name = "entWatch-core",
@ -60,7 +20,16 @@ public SharedPlugin __pl_entWatch_core =
public void __pl_entWatch_core_SetNTVOptional() public void __pl_entWatch_core_SetNTVOptional()
{ {
MarkNativeAsOptional("EW_GetItemCount"); MarkNativeAsOptional("EW_GetItemCount");
MarkNativeAsOptional("EW_GetItemArray");
MarkNativeAsOptional("EW_SetItemArray");
} }
#endif #endif
native int EW_GetItemCount();
forward void EW_OnClientItemDrop(int client, int index);
forward void EW_OnClientItemDeath(int client, int index);
forward void EW_OnClientItemPickup(int client, int index);
forward void EW_OnClientItemActivate(int client, int index);
forward void EW_OnClientItemDisconnect(int client, int index);
forward Action EW_OnClientItemCanPickup(int client, int index);
forward Action EW_OnClientItemCanActivate(int client, int index);