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:
parent
8564ffcfc6
commit
a800e655eb
183
_entWatch4/scripting/CConfig.inc
Normal file
183
_entWatch4/scripting/CConfig.inc
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
@ -6,30 +6,17 @@
|
||||
|
||||
methodmap CItem < Basic
|
||||
{
|
||||
public CItem()
|
||||
public CItem(CConfig value = view_as<CConfig>(INVALID_HANDLE))
|
||||
{
|
||||
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.SetHandle("dConfig", value);
|
||||
|
||||
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);
|
||||
|
||||
@ -37,80 +24,15 @@ methodmap CItem < Basic
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
property CConfig dConfig
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
this.SetHandle("dConfig", 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
|
||||
{
|
||||
public get()
|
||||
@ -270,29 +142,4 @@ methodmap CItem < Basic
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <basic>
|
||||
|
||||
/* CLASSES */
|
||||
#include "CConfig.inc"
|
||||
#include "CItem.inc"
|
||||
|
||||
/* BOOLS */
|
||||
@ -142,7 +143,7 @@ public void OnMapStart()
|
||||
{
|
||||
do
|
||||
{
|
||||
CItem item = new CItem();
|
||||
CConfig config = new CConfig();
|
||||
|
||||
char sName[64], sShort[64], sColor[64], sFilter[64];
|
||||
hConfig.GetString("name", sName, sizeof(sName));
|
||||
@ -150,20 +151,20 @@ public void OnMapStart()
|
||||
hConfig.GetString("color", sColor, sizeof(sColor));
|
||||
hConfig.GetString("filter", sFilter, sizeof(sFilter));
|
||||
|
||||
item.SetName(sName);
|
||||
item.SetShort(sShort);
|
||||
item.SetColor(sColor);
|
||||
item.SetFilter(sFilter);
|
||||
config.SetName(sName);
|
||||
config.SetShort(sShort);
|
||||
config.SetColor(sColor);
|
||||
config.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");
|
||||
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");
|
||||
|
||||
g_hArray_Configs.Push(item);
|
||||
g_hArray_Configs.Push(config);
|
||||
}
|
||||
while (hConfig.GotoNextKey());
|
||||
}
|
||||
@ -213,7 +214,9 @@ public void OnEntitySpawned(int entity)
|
||||
{
|
||||
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);
|
||||
return;
|
||||
@ -222,9 +225,11 @@ public void OnEntitySpawned(int entity)
|
||||
|
||||
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);
|
||||
return;
|
||||
@ -236,11 +241,11 @@ public void OnEntitySpawned(int entity)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock bool RegisterItem(CItem item, int entity)
|
||||
stock bool RegisterItem(CItem item, CConfig config, int 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))
|
||||
{
|
||||
@ -248,7 +253,7 @@ stock bool RegisterItem(CItem item, int entity)
|
||||
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)))
|
||||
{
|
||||
@ -258,7 +263,7 @@ stock bool RegisterItem(CItem item, int entity)
|
||||
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)))
|
||||
{
|
||||
@ -446,6 +451,8 @@ public Action OnButtonPress(int button, int client)
|
||||
{
|
||||
CItem item = g_hArray_Items.Get(index);
|
||||
|
||||
CConfig config = item.dConfig;
|
||||
|
||||
if (item.bButton && item.iButton == button && item.bOwner && item.iOwner == client)
|
||||
{
|
||||
Action aResult;
|
||||
@ -456,19 +463,19 @@ public Action OnButtonPress(int button, int client)
|
||||
|
||||
if ((aResult == Plugin_Continue) || (aResult == Plugin_Changed))
|
||||
{
|
||||
switch(item.iMode)
|
||||
switch(config.iMode)
|
||||
{
|
||||
case(1):
|
||||
{
|
||||
if (item.iTimeReady < RoundToCeil(GetEngineTime()))
|
||||
{
|
||||
item.iTimeReady = RoundToCeil(GetEngineTime()) + item.iCooldown;
|
||||
item.iTimeReady = RoundToCeil(GetEngineTime()) + config.iCooldown;
|
||||
}
|
||||
else return Plugin_Handled;
|
||||
}
|
||||
case(2):
|
||||
{
|
||||
if (item.iTimesUsed < item.iMaxUses)
|
||||
if (item.iTimesUsed < config.iMaxUses)
|
||||
{
|
||||
item.iTimesUsed++;
|
||||
}
|
||||
@ -476,9 +483,9 @@ public Action OnButtonPress(int button, int client)
|
||||
}
|
||||
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++;
|
||||
}
|
||||
else return Plugin_Handled;
|
||||
@ -489,9 +496,9 @@ public Action OnButtonPress(int button, int client)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -500,7 +507,7 @@ public Action OnButtonPress(int button, int client)
|
||||
}
|
||||
|
||||
char sFilter[64];
|
||||
if (item.GetFilter(sFilter, sizeof(sFilter)))
|
||||
if (config.GetFilter(sFilter, sizeof(sFilter)))
|
||||
Entity_SetName(client, sFilter);
|
||||
|
||||
Call_StartForward(g_hFwd_OnClientItemActivate);
|
||||
|
Loading…
Reference in New Issue
Block a user