Raised This Month: $46 Target: $400
 11% 

Scripting Notification System for Grenades, TNT, and Molotovs in No More Room in Hell


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Memento
New Member
Join Date: Jan 2025
Old 03-26-2025 , 00:24   Scripting Notification System for Grenades, TNT, and Molotovs in No More Room in Hell
Reply With Quote #1

I created an SP file related to grenades, TNT, and Molotovs in No More Room in Hell.

However, even when I drop an item using the G key or right-click it in the inventory to drop it, a notification is still sent.

Did I make a mistake somewhere, or is there something I need to add?

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public Plugin myinfo =
{
name = "NMRiH Grenade Alert",
author = "Memento",
description = "Notifies players when someone throws a grenade, TNT, or Molotov.",
version = "1.1",
url = ""
};

public void OnPluginStart()
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
SDKHook(i, SDKHook_WeaponDrop, OnWeaponDrop);
}
}
}

public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_WeaponDrop, OnWeaponDrop);
}

public void OnWeaponDrop(int client, int weapon)
{
if (!IsValidEntity(weapon) || !IsClientInGame(client))
return;

// 현재 무기의 주인을 확인 (플레이어가 아직 소유 중인지 확인)
int owner = GetEntPropEnt(weapon, Prop_Send, "m_hOwnerEntity");

// 만약 무기의 주인이 없다면 (무작위로 떨어진 경우), 알림을 보내지 않음
if (owner == -1 || owner != client)
return;

char classname[64];
GetEdictClassname(weapon, classname, sizeof(classname));

char playerName[MAX_NAME_LENGTH];
GetClientName(client, playerName, sizeof(playerName));

if (StrContains(classname, "exp_grenade", false) != -1)
{
PrintToChatAll("\x04[알림] \x01%s 님이 수류탄을 던졌습니다!", playerName);
}
else if (StrContains(classname, "exp_tnt", false) != -1)
{
PrintToChatAll("\x04[알림] \x01%s 님이 TNT를 던졌습니다!", playerName);
}
else if (StrContains(classname, "exp_molotov", false) != -1)
{
PrintToChatAll("\x04[알림] \x01%s 님이 화염병을 던졌습니다!", playerName);
}
}
Memento is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 03-26-2025 , 12:31   Re: Scripting Notification System for Grenades, TNT, and Molotovs in No More Room in
Reply With Quote #2

Quote:
Originally Posted by Memento View Post
PHP Code:
#include <sdktools>
#include <sdkhooks>

public Plugin myinfo 
{
    
name "NMRiH Grenade Alert",
    
author "Memento",
    
description "Notifies players when someone throws a grenade, TNT, or Molotov.",
    
version "1.1",
    
url ""
};

public 
void OnPluginStart()
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
SDKHook(iSDKHook_WeaponDropOnWeaponDrop);
        }
    }
}

public 
void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_WeaponDropOnWeaponDrop);
}

public 
void OnWeaponDrop(int clientint weapon)
{
    if (!
IsValidEntity(weapon) || !IsClientInGame(client))
        return;

    
// 현재 무기의 주인을 확인 (플레이어가 아직 소유 중인지 확인)
    
int owner GetEntPropEnt(weaponProp_Send"m_hOwnerEntity");

    
// 만약 무기의 주인이 없다면 (무작위로 떨어진 경우), 알림을 보내지 않음
    
if (owner == -|| owner != client)
        return;

    
char classname[64];
    
GetEdictClassname(weaponclassnamesizeof(classname));

    
char playerName[MAX_NAME_LENGTH];
    
GetClientName(clientplayerNamesizeof(playerName));

    if (
StrContains(classname"exp_grenade"false) != -1)
    {
        
PrintToChatAll("\x04[알림] \x01%s 님이 수류탄을 던졌습니다!"playerName);
    }
    else if (
StrContains(classname"exp_tnt"false) != -1)
    {
        
PrintToChatAll("\x04[알림] \x01%s 님이 TNT를 던졌습니다!"playerName);
    }
    else if (
StrContains(classname"exp_molotov"false) != -1)
    {
        
PrintToChatAll("\x04[알림] \x01%s 님이 화염병을 던졌습니다!"playerName);
    }

please use tags for code
__________________
Grey83 is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 03-26-2025 , 13:04   Re: Scripting Notification System for Grenades, TNT, and Molotovs in No More Room in
Reply With Quote #3

Version with support of translation files
Attached Files
File Type: sp Get Plugin or Get Source (nmrih_grenade_alert 1.2.0_26.03.2025.sp - 21 views - 1.1 KB)
File Type: txt nmrih_grenade_alert.phrases.txt (624 Bytes, 18 views)
__________________
Grey83 is offline
Memento
New Member
Join Date: Jan 2025
Old 03-27-2025 , 00:49   Re: Scripting Notification System for Grenades, TNT, and Molotovs in No More Room in
Reply With Quote #4

Quote:
Originally Posted by Grey83 View Post
Version with support of translation files
Thank you for your help, but notification will be sent even if

I drop the item with a G key or right click (same issue) 😥
Memento is offline
helloworlds
Junior Member
Join Date: Oct 2022
Old 03-31-2025 , 18:50   Re: Scripting Notification System for Grenades, TNT, and Molotovs in No More Room in
Reply With Quote #5

Quote:
Originally Posted by Memento View Post
Thank you for your help, but notification will be sent even if

I drop the item with a G key or right click (same issue) ******************
I assume you wish to only capture the items being thrown, and not dropped?

I don't have the game, but one possible workaround could be listening for OnEntityCreated for the thrown projectile:

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    
// get the correct projectile classname from here
    
PrintToChatAll("Entity was created: %s"classname);

    
// change me to correct projectile classname
    
char[] grenade_projectile "example_projectile_classname";

    
// catch the projectile here
    
if (StrEqual(classnamegrenade_projectile))
    {
        
PrintToChatAll("It was a grenade projectile!");
    }

    
// then do the same for the TNT & molotov...

etc. (Although if these projectiles are not created at the moment of throwing the item, then this approach would not work.)

Last edited by helloworlds; 03-31-2025 at 18:54. Reason: code cleanup
helloworlds is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:58.


Powered by vBulletin®
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Theme made by Freecode