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

[L4D2] detecting when a player uses a throwable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dustinandband
Senior Member
Join Date: May 2015
Old 05-23-2019 , 08:11   [L4D2] detecting when a player uses a throwable
Reply With Quote #1

Is there a preferred way to detect when a player uses a throwable (molly, pipe, bile)? I'm wanting to count how many of each have been used (total, not per-player).

I was originally thinking on map start i'd count them then subtract the current difference, but that's spammy since it'll be happening every 3 seconds and display on a spectator info-panel. Plus it'll be for survival so some maps have those survivor zombies that drop supplies including throwables, so that method wouldn't work.

Last edited by dustinandband; 05-23-2019 at 08:12.
dustinandband is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 05-23-2019 , 08:46   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #2

You can check for the _projectile in the classname in OnEntityCreated and the count how many of which type were used. pipe_bomb_projectile, molotov_projectile and vomitjar_projectile.
xerox8521 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-23-2019 , 09:17   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #3

Depends if you need to know the second it's thrown. weapon_fire event.

Or read the Prop_Data values:
Quote:
Member: m_checkpointMolotovsUsed (offset 14660) (type integer) (bits 32) ()
Member: m_missionMolotovsUsed (offset 14664) (type integer) (bits 32) ()
Member: m_checkpointPipebombsUsed (offset 14668) (type integer) (bits 32) ()
Member: m_missionPipebombsUsed (offset 14672) (type integer) (bits 32) ()
Member: m_checkpointBoomerBilesUsed (offset 14676) (type integer) (bits 32) ()
Member: m_missionBoomerBilesUsed (offset 14680) (type integer) (bits 32) ()
__________________

Last edited by Silvers; 05-23-2019 at 09:17.
Silvers is offline
Alexmy
Senior Member
Join Date: Oct 2014
Location: Russian Federation
Old 05-24-2019 , 05:25   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #4

Quote:
Originally Posted by Silvers View Post
Depends if you need to know the second it's thrown. weapon_fire event.

Or read the Prop_Data values:
No, these offsets refer to Prop_Send
Alexmy is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-24-2019 , 08:59   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #5

Quote:
Originally Posted by Alexmy View Post
No, these offsets refer to Prop_Send
Oops that's what I meant.

The problem with this method is that thats are cleared by any plugin using SM Respawn by Atomic. Unless the more advanced one I helped put together which saves and restores player stats actually works and is public, I've no idea.
__________________
Silvers is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 05-24-2019 , 11:10   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #6

onentitycreated hook the projectile.... sdkhook spawnpost then u can access the entprops...i believe m_hthrower is the client that threw it. either that get the ownerentity entprop. I do this in my backpack plugin to get when they're thrown and who threw them.
MasterMind420 is offline
dustinandband
Senior Member
Join Date: May 2015
Old 05-24-2019 , 17:15   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #7

Works but the only problem is that for some reason, propane tank explosions are incrementing the pipe bomb count. I'm wondering if there could be any other false positive detections

https://youtu.be/68WHVd1PX6w

PHP Code:
int g_iMollies;
int g_iPipes;
int g_iBiles;

// throwables
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrEqual(classname"molotov_projectile"))
    {
        
SDKHook(entitySDKHook_SpawnPostIncrementMolly);
    }
    else if (
StrEqual(classname"pipe_bomb_projectile"))
    {
        
SDKHook(entitySDKHook_SpawnPostIncrementPipeBomb);
    }
    else if (
StrEqual(classname"vomitjar_projectile"))
    {
        
SDKHook(entitySDKHook_SpawnPostIncrementBileCount);
    }
    
    else return;
}

public 
void IncrementMolly(int entity)
{
    
SDKUnhook(entitySDKHook_SpawnPostIncrementMolly);
    
g_iMollies++;
}
public 
void IncrementPipeBomb(int entity)
{
    
SDKUnhook(entitySDKHook_SpawnPostIncrementPipeBomb);
    
g_iPipes++;
}
public 
void IncrementBileCount(int entity)
{
    
SDKUnhook(entitySDKHook_SpawnPostIncrementBileCount);
    
g_iBiles++;

dustinandband is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 05-24-2019 , 19:08   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #8

get the m_hthrower entprop like i said and increment there �� propane tanks i believe wont have a thrower...

Last edited by MasterMind420; 05-24-2019 at 19:08.
MasterMind420 is offline
dustinandband
Senior Member
Join Date: May 2015
Old 05-25-2019 , 02:09   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #9

tried including some additional checks that this guy also used but can't find a way to differentiate between an actual pipe and propane tank.
(his code snippet, "only proceed if it's really a pipe" https://github.com/Tabbernaut/L4D2-R...andom.sp#L3509 )

tests wern't useful
pipe bomb:
thrower value: 1 | IsValidEntity value: 1
Classname value: pipe_bomb_projectile

propane tank:
thrower value: 1 | IsValidEntity value: 1
Classname value: pipe_bomb_projectile

script :
Spoiler


Quote:
Originally Posted by MasterMind420 View Post
onentitycreated hook the projectile.... sdkhook spawnpost then u can access the entprops...i believe m_hthrower is the client that threw it. either that get the ownerentity entprop. I do this in my backpack plugin to get when they're thrown and who threw them.
I don't see m_hthrower in your backpack plugin.

However hooking onto the weapon_fire event (which I see you did originally but commented it out) works just fine for me.

Thx nice workaround.
Spoiler
dustinandband is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-25-2019 , 04:37   Re: [L4D2] detecting when a player uses a throwable
Reply With Quote #10

Theres no need for
PHP Code:
    if(item[0] != 'm' && item[0] != 'p' && item[0] != 'v')
        return; 
since you have the switch below doing the same basically.
__________________
Silvers is offline
Reply



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 01:35.


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