entWatch4: Remove useless SMLib stuff, add template checking.

This commit is contained in:
zaCade 2019-04-08 12:19:03 +02:00
parent 3b023b2bbd
commit e27a663cf9
6 changed files with 184 additions and 12 deletions

View File

@ -12,6 +12,7 @@ methodmap CItem < Basic
myclass.SetHandle("dConfig", value); myclass.SetHandle("dConfig", value);
myclass.SetInt("iTempID", -1);
myclass.SetInt("iClient", INVALID_ENT_REFERENCE); myclass.SetInt("iClient", 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);
@ -37,6 +38,18 @@ methodmap CItem < Basic
} }
property int iTempID
{
public get()
{
return this.GetInt("iTempID");
}
public set(int value)
{
this.SetInt("iTempID", value);
}
}
property int iClient property int iClient
{ {
public get() public get()

View File

@ -5,14 +5,13 @@
// Description: Handle the core functions of [entWatch] // Description: Handle the core functions of [entWatch]
// //
//==================================================================================================== //====================================================================================================
#include <smlib>
#pragma newdecls required #pragma newdecls required
#include <sourcemod> #include <sourcemod>
#include <sdkhooks> #include <sdkhooks>
#include <sdktools> #include <sdktools>
#include <entWatch_core> #include <entWatch_core>
#include <entWatch_helpers>
/* BOOLS */ /* BOOLS */
bool g_bLate; bool g_bLate;
@ -207,11 +206,13 @@ public void OnEntitySpawned(int entity)
{ {
if (Entity_IsValid(entity) && g_hArray_Configs.Length) if (Entity_IsValid(entity) && g_hArray_Configs.Length)
{ {
int iHammerID = Entity_GetHammerID(entity);
for (int index; index < g_hArray_Configs.Length; index++) for (int index; index < g_hArray_Configs.Length; index++)
{ {
CConfig config = g_hArray_Configs.Get(index); CConfig config = g_hArray_Configs.Get(index);
if (config.iWeaponID && config.iWeaponID == Entity_GetHammerId(entity)) if (config.iWeaponID && config.iWeaponID == iHammerID)
{ {
if (!RegisterExistingItem(entity, REGISTER_WEAPON)) if (!RegisterExistingItem(entity, REGISTER_WEAPON))
{ {
@ -221,7 +222,7 @@ public void OnEntitySpawned(int entity)
g_hArray_Items.Push(item); g_hArray_Items.Push(item);
} }
} }
else if (config.iButtonID && config.iButtonID == Entity_GetHammerId(entity)) else if (config.iButtonID && config.iButtonID == iHammerID)
{ {
if (!RegisterExistingItem(entity, REGISTER_BUTTON)) if (!RegisterExistingItem(entity, REGISTER_BUTTON))
{ {
@ -231,7 +232,7 @@ public void OnEntitySpawned(int entity)
g_hArray_Items.Push(item); g_hArray_Items.Push(item);
} }
} }
else if (config.iTriggerID && config.iTriggerID == Entity_GetHammerId(entity)) else if (config.iTriggerID && config.iTriggerID == iHammerID)
{ {
if (!RegisterExistingItem(entity, REGISTER_TRIGGER)) if (!RegisterExistingItem(entity, REGISTER_TRIGGER))
{ {
@ -271,12 +272,17 @@ stock bool RegisterItemEntity(CItem item, int entity, int type)
{ {
if (Entity_IsValid(entity)) if (Entity_IsValid(entity))
{ {
int iOwner = Entity_GetOwner(entity);
int iParent = Entity_GetParent(entity);
int iTempID = Entity_GetTempID(entity);
switch(type) switch(type)
{ {
case REGISTER_WEAPON: case REGISTER_WEAPON:
{ {
if (!item.bWeapon && (Entity_GetOwner(entity) == INVALID_ENT_REFERENCE)) if (!item.bWeapon && item.iTempID == iTempID && (iOwner == INVALID_ENT_REFERENCE))
{ {
item.iTempID = iTempID;
item.iWeapon = entity; item.iWeapon = entity;
return true; return true;
@ -284,10 +290,11 @@ stock bool RegisterItemEntity(CItem item, int entity, int type)
} }
case REGISTER_BUTTON: case REGISTER_BUTTON:
{ {
if (!item.bButton && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) if (!item.bButton && item.iTempID == iTempID && (iParent == INVALID_ENT_REFERENCE || (item.bWeapon && iParent == item.iWeapon)))
{ {
SDKHook(entity, SDKHook_Use, OnButtonPress); SDKHook(entity, SDKHook_Use, OnButtonPress);
item.iTempID = iTempID;
item.iButton = entity; item.iButton = entity;
return true; return true;
@ -295,12 +302,13 @@ stock bool RegisterItemEntity(CItem item, int entity, int type)
} }
case REGISTER_TRIGGER: case REGISTER_TRIGGER:
{ {
if (!item.bTrigger && (Entity_GetParent(entity) == INVALID_ENT_REFERENCE || (item.bWeapon && Entity_GetParent(entity) == item.iWeapon))) if (!item.bTrigger && item.iTempID == iTempID && (iParent == INVALID_ENT_REFERENCE || (item.bWeapon && iParent == item.iWeapon)))
{ {
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);
item.iTempID = iTempID;
item.iTrigger = entity; item.iTrigger = entity;
return true; return true;

View File

@ -5,12 +5,11 @@
// Description: Handle the interface of [entWatch] // Description: Handle the interface of [entWatch]
// //
//==================================================================================================== //====================================================================================================
#include <smlib>
#pragma newdecls required #pragma newdecls required
#include <sourcemod> #include <sourcemod>
#include <entWatch_core> #include <entWatch_core>
#include <entWatch_helpers>
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:

View File

@ -5,13 +5,13 @@
// Description: Handle the chat messages of [entWatch] // Description: Handle the chat messages of [entWatch]
// //
//==================================================================================================== //====================================================================================================
#include <smlib>
#include <multicolors> #include <multicolors>
#pragma newdecls required #pragma newdecls required
#include <sourcemod> #include <sourcemod>
#include <entWatch_core> #include <entWatch_core>
#include <entWatch_helpers>
#define MESSAGEFORMAT "\x07%s[entWatch] \x07%s%s \x07%s(\x07%s%s\x07%s) %t \x07%6s%s" #define MESSAGEFORMAT "\x07%s[entWatch] \x07%s%s \x07%s(\x07%s%s\x07%s) %t \x07%6s%s"

View File

@ -5,7 +5,6 @@
// Description: Handle the restrictions of [entWatch] // Description: Handle the restrictions of [entWatch]
// //
//==================================================================================================== //====================================================================================================
#include <smlib>
#include <multicolors> #include <multicolors>
#pragma newdecls required #pragma newdecls required
@ -13,6 +12,7 @@
#include <sourcemod> #include <sourcemod>
#include <clientprefs> #include <clientprefs>
#include <entWatch_core> #include <entWatch_core>
#include <entWatch_helpers>
/* FORWARDS */ /* FORWARDS */
Handle g_hFwd_OnClientRestricted; Handle g_hFwd_OnClientRestricted;

View File

@ -0,0 +1,152 @@
#if defined entWatch_helpers_included
#endinput
#endif
#define entWatch_helpers_included
/**
* Converts the whole String to lower case.
* Only works with alphabetical characters (not ײִ) because Sourcemod suxx !
* The Output String can be the same as the Input String.
*
* @param input Input String.
* @param output Output String.
* @param size Max Size of the Output string
* @noreturn
*/
stock void String_ToLower(const char[] input, char[] output, int size)
{
size--;
int x;
while (input[x] != '\0' || x < size) {
if (IsCharUpper(input[x])) {
output[x] = CharToLower(input[x]);
}
else {
output[x] = input[x];
}
x++;
}
output[x] = '\0';
}
/**
* Checks if the specified index is a player and connected.
*
* @param entity An entity index.
* @param checkConnected Set to false to skip the IsClientConnected check
* @return Returns true if the specified entity index is a player connected, false otherwise.
*/
stock bool Client_IsValid(int client, bool checkConnected=true)
{
if (client > 4096) {
client = EntRefToEntIndex(client);
}
if (client < 1 || client > MaxClients) {
return false;
}
if (checkConnected && !IsClientConnected(client)) {
return false;
}
return true;
}
/**
* Gets the client's current observer target entity.
*
* @param client Client Index.
* @return Observed Entity Index.
*/
stock int Client_GetObserverTarget(int client)
{
return GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
}
/*
* Checks if an entity is valid and exists.
*
* @param entity Entity Index.
* @return True if the entity is valid, false otherwise.
*/
stock bool Entity_IsValid(int entity)
{
return IsValidEntity(entity);
}
/**
* Gets the Hammer-ID of an entity.
* The Hammer Editor gives every entity a unique ID.
* Note: Old maps don't have Hammer-ID's set for entities
*
* @param entity Entity index.
* @return Hammer ID.
*/
stock int Entity_GetHammerID(int entity)
{
return GetEntProp(entity, Prop_Data, "m_iHammerID");
}
/**
* Gets the owner of an entity.
* For example the owner of a weapon entity.
*
* @param entity Entity index.
* @return Ground Entity or -1
*/
stock int Entity_GetOwner(int entity)
{
return GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
}
/*
* Gets the parent entity of an entity.
*
* @param entity Entity Index.
* @return Entity Index of the parent.
*/
stock int Entity_GetParent(int entity)
{
return GetEntPropEnt(entity, Prop_Data, "m_pParent");
}
/**
* Gets the template id of an entity.
*
* @param entity Entity index.
* @return Template ID or -1
*/
stock int Entity_GetTempID(int entity)
{
char name[128];
GetEntPropString(entity, Prop_Data, "m_iName", name, sizeof(name));
int index
if ((index = FindCharInString(name, '&', true)) != -1)
{
return view_as<int>(StringToInt(name[index + 1]));
}
return -1;
}
/**
* Sets the Name of an entity.
*
* @param entity Entity index.
* @param name The name you want to give.
* @noreturn
*/
stock void Entity_SetName(int entity, const char[] name, any ...)
{
char format[128];
VFormat(format, sizeof(format), name, 3);
DispatchKeyValue(entity, "targetname", format);
}