diff --git a/_entWatch4/scripting/classes/CItem.inc b/_entWatch4/scripting/classes/CItem.inc index 26dcae80..886c9abb 100644 --- a/_entWatch4/scripting/classes/CItem.inc +++ b/_entWatch4/scripting/classes/CItem.inc @@ -12,6 +12,7 @@ methodmap CItem < Basic myclass.SetHandle("dConfig", value); + myclass.SetInt("iTempID", -1); myclass.SetInt("iClient", INVALID_ENT_REFERENCE); myclass.SetInt("iButton", 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 { public get() diff --git a/_entWatch4/scripting/entWatch-core.sp b/_entWatch4/scripting/entWatch-core.sp index e2778e3a..3cd386db 100644 --- a/_entWatch4/scripting/entWatch-core.sp +++ b/_entWatch4/scripting/entWatch-core.sp @@ -5,14 +5,13 @@ // Description: Handle the core functions of [entWatch] // //==================================================================================================== -#include - #pragma newdecls required #include #include #include #include +#include /* BOOLS */ bool g_bLate; @@ -207,11 +206,13 @@ public void OnEntitySpawned(int entity) { if (Entity_IsValid(entity) && g_hArray_Configs.Length) { + int iHammerID = Entity_GetHammerID(entity); + for (int index; index < g_hArray_Configs.Length; 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)) { @@ -221,7 +222,7 @@ public void OnEntitySpawned(int entity) 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)) { @@ -231,7 +232,7 @@ public void OnEntitySpawned(int entity) 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)) { @@ -271,12 +272,17 @@ stock bool RegisterItemEntity(CItem item, int entity, int type) { if (Entity_IsValid(entity)) { + int iOwner = Entity_GetOwner(entity); + int iParent = Entity_GetParent(entity); + int iTempID = Entity_GetTempID(entity); + switch(type) { 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; return true; @@ -284,10 +290,11 @@ stock bool RegisterItemEntity(CItem item, int entity, int type) } 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); + item.iTempID = iTempID; item.iButton = entity; return true; @@ -295,12 +302,13 @@ stock bool RegisterItemEntity(CItem item, int entity, int type) } 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_EndTouch, OnTriggerTouch); SDKHook(entity, SDKHook_Touch, OnTriggerTouch); + item.iTempID = iTempID; item.iTrigger = entity; return true; diff --git a/_entWatch4/scripting/entWatch-interface.sp b/_entWatch4/scripting/entWatch-interface.sp index 8fa39c32..ad5e2541 100644 --- a/_entWatch4/scripting/entWatch-interface.sp +++ b/_entWatch4/scripting/entWatch-interface.sp @@ -5,12 +5,11 @@ // Description: Handle the interface of [entWatch] // //==================================================================================================== -#include - #pragma newdecls required #include #include +#include //---------------------------------------------------------------------------------------------------- // Purpose: diff --git a/_entWatch4/scripting/entWatch-messages.sp b/_entWatch4/scripting/entWatch-messages.sp index 162a5c04..e6323a56 100644 --- a/_entWatch4/scripting/entWatch-messages.sp +++ b/_entWatch4/scripting/entWatch-messages.sp @@ -5,13 +5,13 @@ // Description: Handle the chat messages of [entWatch] // //==================================================================================================== -#include #include #pragma newdecls required #include #include +#include #define MESSAGEFORMAT "\x07%s[entWatch] \x07%s%s \x07%s(\x07%s%s\x07%s) %t \x07%6s%s" diff --git a/_entWatch4/scripting/entWatch-restrictions.sp b/_entWatch4/scripting/entWatch-restrictions.sp index 54876ae6..6aa919c2 100644 --- a/_entWatch4/scripting/entWatch-restrictions.sp +++ b/_entWatch4/scripting/entWatch-restrictions.sp @@ -5,7 +5,6 @@ // Description: Handle the restrictions of [entWatch] // //==================================================================================================== -#include #include #pragma newdecls required @@ -13,6 +12,7 @@ #include #include #include +#include /* FORWARDS */ Handle g_hFwd_OnClientRestricted; diff --git a/_entWatch4/scripting/include/entWatch_helpers.inc b/_entWatch4/scripting/include/entWatch_helpers.inc new file mode 100644 index 00000000..273a1b24 --- /dev/null +++ b/_entWatch4/scripting/include/entWatch_helpers.inc @@ -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(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); +} \ No newline at end of file