entWatch4: Actually make it work.

Since pushing the configurated 'item' as an item would break stuff, so now the configs and items are split between 2 classes.
This commit is contained in:
zaCade 2018-11-19 16:27:52 +01:00
parent 8564ffcfc6
commit a800e655eb
3 changed files with 224 additions and 187 deletions

View File

@ -0,0 +1,183 @@
#if defined entWatch_class_config_included
#endinput
#endif
#define entWatch_class_config_included
methodmap CConfig < Basic
{
public CConfig()
{
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("iDisplay", 0);
myclass.SetInt("iMode", 0);
myclass.SetInt("iMaxUses", 0);
myclass.SetInt("iCooldown", 0);
return view_as<CConfig>(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 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 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

@ -6,30 +6,17 @@
methodmap CItem < Basic methodmap CItem < Basic
{ {
public CItem() public CItem(CConfig value = view_as<CConfig>(INVALID_HANDLE))
{ {
Basic myclass = new Basic(); Basic myclass = new Basic();
myclass.SetString("sName", ""); myclass.SetHandle("dConfig", value);
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("iOwner", INVALID_ENT_REFERENCE);
myclass.SetInt("iButton", INVALID_ENT_REFERENCE); myclass.SetInt("iButton", INVALID_ENT_REFERENCE);
myclass.SetInt("iWeapon", INVALID_ENT_REFERENCE); myclass.SetInt("iWeapon", INVALID_ENT_REFERENCE);
myclass.SetInt("iTrigger", 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("iTimesUsed", 0);
myclass.SetInt("iTimeReady", 0); myclass.SetInt("iTimeReady", 0);
@ -37,80 +24,15 @@ methodmap CItem < Basic
} }
public bool GetName(char[] buffer, int length) property CConfig dConfig
{
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() public get()
{ {
return this.GetInt("iButtonID"); return view_as<CConfig>(this.GetHandle("dConfig"));
} }
public set(int value) public set(CConfig value)
{ {
this.SetInt("iButtonID", value); this.SetHandle("dConfig", 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);
} }
} }
@ -164,56 +86,6 @@ methodmap CItem < Basic
} }
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 property int iTimesUsed
{ {
public get() public get()
@ -270,29 +142,4 @@ methodmap CItem < Basic
return view_as<bool>(this.iTrigger != INVALID_ENT_REFERENCE); 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

@ -15,6 +15,7 @@
#include <basic> #include <basic>
/* CLASSES */ /* CLASSES */
#include "CConfig.inc"
#include "CItem.inc" #include "CItem.inc"
/* BOOLS */ /* BOOLS */
@ -142,7 +143,7 @@ public void OnMapStart()
{ {
do do
{ {
CItem item = new CItem(); CConfig config = new CConfig();
char sName[64], sShort[64], sColor[64], sFilter[64]; char sName[64], sShort[64], sColor[64], sFilter[64];
hConfig.GetString("name", sName, sizeof(sName)); hConfig.GetString("name", sName, sizeof(sName));
@ -150,20 +151,20 @@ public void OnMapStart()
hConfig.GetString("color", sColor, sizeof(sColor)); hConfig.GetString("color", sColor, sizeof(sColor));
hConfig.GetString("filter", sFilter, sizeof(sFilter)); hConfig.GetString("filter", sFilter, sizeof(sFilter));
item.SetName(sName); config.SetName(sName);
item.SetShort(sShort); config.SetShort(sShort);
item.SetColor(sColor); config.SetColor(sColor);
item.SetFilter(sFilter); config.SetFilter(sFilter);
item.iWeaponID = hConfig.GetNum("weaponid"); config.iWeaponID = hConfig.GetNum("weaponid");
item.iButtonID = hConfig.GetNum("buttonid"); config.iButtonID = hConfig.GetNum("buttonid");
item.iTriggerID = hConfig.GetNum("triggerid"); config.iTriggerID = hConfig.GetNum("triggerid");
item.iDisplay = hConfig.GetNum("display"); config.iDisplay = hConfig.GetNum("display");
item.iMode = hConfig.GetNum("mode"); config.iMode = hConfig.GetNum("mode");
item.iMaxUses = hConfig.GetNum("maxuses"); config.iMaxUses = hConfig.GetNum("maxuses");
item.iCooldown = hConfig.GetNum("cooldown"); config.iCooldown = hConfig.GetNum("cooldown");
g_hArray_Configs.Push(item); g_hArray_Configs.Push(config);
} }
while (hConfig.GotoNextKey()); while (hConfig.GotoNextKey());
} }
@ -213,7 +214,9 @@ public void OnEntitySpawned(int entity)
{ {
CItem item = g_hArray_Items.Get(index); CItem item = g_hArray_Items.Get(index);
if (RegisterItem(item, entity)) CConfig config = item.dConfig;
if (RegisterItem(item, config, entity))
{ {
g_hArray_Items.Set(index, item); g_hArray_Items.Set(index, item);
return; return;
@ -222,9 +225,11 @@ public void OnEntitySpawned(int entity)
for (int index; index < g_hArray_Configs.Length; index++) for (int index; index < g_hArray_Configs.Length; index++)
{ {
CItem item = g_hArray_Configs.Get(index); CItem item = new CItem(g_hArray_Configs.Get(index));
if (RegisterItem(item, entity)) CConfig config = item.dConfig;
if (RegisterItem(item, config, entity))
{ {
g_hArray_Items.Push(item); g_hArray_Items.Push(item);
return; return;
@ -236,11 +241,11 @@ public void OnEntitySpawned(int entity)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
stock bool RegisterItem(CItem item, int entity) stock bool RegisterItem(CItem item, CConfig config, int entity)
{ {
if (Entity_IsValid(entity)) if (Entity_IsValid(entity))
{ {
if (item.iWeaponID && item.iWeaponID == Entity_GetHammerId(entity)) if (config.iWeaponID && config.iWeaponID == Entity_GetHammerId(entity))
{ {
if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE)) if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE))
{ {
@ -248,7 +253,7 @@ stock bool RegisterItem(CItem item, int entity)
return true; return true;
} }
} }
else if (item.iButtonID && item.iButtonID == Entity_GetHammerId(entity)) else if (config.iButtonID && config.iButtonID == Entity_GetHammerId(entity))
{ {
if (!item.bButton && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) if (!item.bButton && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon)))
{ {
@ -258,7 +263,7 @@ stock bool RegisterItem(CItem item, int entity)
return true; return true;
} }
} }
else if (item.iTriggerID && item.iTriggerID == Entity_GetHammerId(entity)) else if (config.iTriggerID && config.iTriggerID == Entity_GetHammerId(entity))
{ {
if (!item.bTrigger && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) if (!item.bTrigger && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon)))
{ {
@ -446,6 +451,8 @@ public Action OnButtonPress(int button, int client)
{ {
CItem item = g_hArray_Items.Get(index); CItem item = g_hArray_Items.Get(index);
CConfig config = item.dConfig;
if (item.bButton && item.iButton == button && item.bOwner && item.iOwner == client) if (item.bButton && item.iButton == button && item.bOwner && item.iOwner == client)
{ {
Action aResult; Action aResult;
@ -456,19 +463,19 @@ public Action OnButtonPress(int button, int client)
if ((aResult == Plugin_Continue) || (aResult == Plugin_Changed)) if ((aResult == Plugin_Continue) || (aResult == Plugin_Changed))
{ {
switch(item.iMode) switch(config.iMode)
{ {
case(1): case(1):
{ {
if (item.iTimeReady < RoundToCeil(GetEngineTime())) if (item.iTimeReady < RoundToCeil(GetEngineTime()))
{ {
item.iTimeReady = RoundToCeil(GetEngineTime()) + item.iCooldown; item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
} }
else return Plugin_Handled; else return Plugin_Handled;
} }
case(2): case(2):
{ {
if (item.iTimesUsed < item.iMaxUses) if (item.iTimesUsed < config.iMaxUses)
{ {
item.iTimesUsed++; item.iTimesUsed++;
} }
@ -476,9 +483,9 @@ public Action OnButtonPress(int button, int client)
} }
case(3): case(3):
{ {
if (item.iTimeReady < RoundToCeil(GetEngineTime()) && item.iTimesUsed < item.iMaxUses) if (item.iTimeReady < RoundToCeil(GetEngineTime()) && item.iTimesUsed < config.iMaxUses)
{ {
item.iTimeReady = RoundToCeil(GetEngineTime()) + item.iCooldown; item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
item.iTimesUsed++; item.iTimesUsed++;
} }
else return Plugin_Handled; else return Plugin_Handled;
@ -489,9 +496,9 @@ public Action OnButtonPress(int button, int client)
{ {
item.iTimesUsed++; item.iTimesUsed++;
if (item.iTimesUsed >= item.iMaxUses) if (item.iTimesUsed >= config.iMaxUses)
{ {
item.iTimeReady = RoundToCeil(GetEngineTime()) + item.iCooldown; item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
item.iTimesUsed = 0; item.iTimesUsed = 0;
} }
} }
@ -500,7 +507,7 @@ public Action OnButtonPress(int button, int client)
} }
char sFilter[64]; char sFilter[64];
if (item.GetFilter(sFilter, sizeof(sFilter))) if (config.GetFilter(sFilter, sizeof(sFilter)))
Entity_SetName(client, sFilter); Entity_SetName(client, sFilter);
Call_StartForward(g_hFwd_OnClientItemActivate); Call_StartForward(g_hFwd_OnClientItemActivate);