Raised This Month: $12 Target: $400
 3% 

Solved How to hook molotov touch (explosion)?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-21-2019 , 09:43   How to hook molotov touch (explosion)?
Reply With Quote #1

Hi,

I need to catch a moment of explosion and get molotov entity coordinates.

This code work for "pipe_bomb_projectile", but doesn't trigger for "weapon_molotov" (only "other" touch raise in some cases).

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public void OnEntityCreated(int entity, const char[] classname)
{
        
PrintToChatAll("Entity created: %s"classname);
    
        if(
StrEqual(classname"weapon_molotov"))
        
//if(StrEqual(classname, "pipe_bomb_projectile"))
        
{
            
SDKHook(entitySDKHook_StartTouchOnTouch);
        }
}

public 
void OnTouch(int entityint other)
{
    if (!
other)
    {
        
PrintToChatAll("touched");
    }
    else {
        
PrintToChatAll("Other touch");
    }
    
SDKUnhook(entitySDKHook_StartTouchOnTouch);

btw, what is mean "other" parameter?

Possibly, I could use HookSingleEntityOutput, but I can't see in valve dev. any docs about the list of output names. Any help?

Also, maybe, I could use OnEntityDestroyed, but I need somehow check the reason why molotov is destroyed to ensure it is happen due to explosion.

It is also, an "inferno" entity created after explosion, so as a final walkaround I could use its origin. However, it is required that I check inferno spawned due to molotov explosion.

Thanks.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 02-22-2019 at 10:34.
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-21-2019 , 09:49   Re: How to hook molotov touch (explosion)?
Reply With Quote #2

Ahh, found the mistake.

I should hook "molotov_projectile" entity.

lol
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-21-2019 , 11:36   Re: How to hook molotov touch (explosion)?
Reply With Quote #3

ok, SDKHook_StartTouch is not reliable here. It doesn't trigger when molotov hits the car.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 02-21-2019 , 14:12   Re: How to hook molotov touch (explosion)?
Reply With Quote #4

As I tested before, when molotov activates, entity with classname "inferno" is created.

Last edited by impossible_cc; 02-21-2019 at 14:17.
impossible_cc is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-21-2019 , 15:26   Re: How to hook molotov touch (explosion)?
Reply With Quote #5

Yes, I mentioned it above.
Question is: if we take this option as hook, how to identify "inferno" created due to molotov explosion rather than another reason.

Code:
public void OnEntityCreated(int entity, const char[] classname)
{
		if(StrEqual(classname, "inferno"))
		{
			PrintToChatAll("Inferno created");
		
			int hOwner = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
			int hEffect = GetEntPropEnt(entity, Prop_Data, "m_hEffectEntity");
			int iParent = GetEntProp(entity, Prop_Data, "m_iParentAttachment");
			
			PrintToChatAll("Inferno owner is: %i, effect: %i, parent: %i", hOwner, hEffect, iParent);
Quote:
Inferno owner is: -1, effect: -1, parent: 0
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 02-21-2019 , 16:28   Re: How to hook molotov touch (explosion)?
Reply With Quote #6

You can use a sound hook.

PHP Code:
public Action:HandheldSoundHook(iClients[64], &iNumClientsString:sSampleFile[PLATFORM_MAX_PATH], &iEntity, &iChannel, &Float:fVolume, &fLevel, &iPitch, &iFlags)
{    
    if(
iEntity || iEntity 2048 || !IsValidEntity(iEntity)
        return 
Plugin_Continue;

    static 
String:sClassname[32];
    
GetEntityClassname(iEntitysClassnamesizeof(sClassname));
    if(!
StrEqual(sClassname"molotov_projectile"))
        return 
Plugin_Continue;

    if(
StrContains(sSampleFile"molotov_detonate_3.wav"false))
    {
        
//code 
    
}

update:
Changed it to use break sound
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D

Last edited by Lux; 02-21-2019 at 16:55.
Lux is offline
quasemago
Senior Member
Join Date: Dec 2018
Location: Brazil
Old 02-21-2019 , 20:34   Re: How to hook molotov touch (explosion)?
Reply With Quote #7

Try inferno_startburn event. More details: https://wiki.alliedmods.net/Counter-...erno_startburn

Last edited by quasemago; 02-21-2019 at 20:59.
quasemago is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-21-2019 , 21:11   Re: How to hook molotov touch (explosion)?
Reply With Quote #8

OnEntityCreated is too early to get those properties, try requestframe or 2
__________________
Pelipoika is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-22-2019 , 09:39   Re: How to hook molotov touch (explosion)?
Reply With Quote #9

Lux, thank you, interesting solution.

quasemago, thanks, unfortunately, no "inferno_startburn" event for my game.

Pelipoika, thanks, it's work.
Quote:
Inferno owner is: 1 (player), effect: -1, parent: 0
However, no evidence about the molotov as a source of inferno.

So, I think I'll stop on Lux version, or I will track both entities and compare them through a global variable.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 02-22-2019 , 10:00   Re: How to hook molotov touch (explosion)?
Reply With Quote #10

Lux's solution would be the most accurate method i would think...however did u try onentitydestroyed and check for molotov projectile. I can remember messing with something similar in the past. Not sure if it worked though but it should.
MasterMind420 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:07.


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