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

[CSS] How to detect when player has thrown grenade


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
keygens
Senior Member
Join Date: Mar 2010
Location: Somewhere
Old 03-02-2015 , 04:26   [CSS] How to detect when player has thrown grenade
Reply With Quote #1

Hello guys. How i can detect players, when they has thrown they grenades? Thanks in advance
keygens is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-02-2015 , 08:02   Re: [CSS] How to detect when player has thrown grenade
Reply With Quote #2

SDKTools - OnEntityCreated

PHP Code:
public OnEntityCreated(entity, const char[] classname)
{
    if (
strcmp(classname"hegrenade_projectile"false) == 0)
    {
        
int owner GetEntPropEnt(entityProp_Send"m_hThrower");
        
        if (
owner != -1)
        {
            
// owner is the player who threw the grenade (entity)
        
}
        
    }

__________________
View my Plugins | Donate

Last edited by TnTSCS; 03-02-2015 at 12:23.
TnTSCS is offline
keygens
Senior Member
Join Date: Mar 2010
Location: Somewhere
Old 03-02-2015 , 08:19   Re: [CSS] How to detect when player has thrown grenade
Reply With Quote #3

Quote:
Originally Posted by TnTSCS View Post
SDKTools - OnEntityCreated

PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if (
strcmp(classname"hegrenade_projectile"false) == 0)
    {
        new 
owner GetEntPropEnt(entityProp_Send"m_hThrower");
        
        if (
owner != -1)
        {
            
// owner is the player who threw the grenade (entity)
        
}
        
    }

Thanks for that. Also, i need event of thrown grenade. Its something like weapon_fire or what?
keygens is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-02-2015 , 09:53   Re: [CSS] How to detect when player has thrown grenade
Reply With Quote #4

I think that's as close as you can get to a weapon_fire event for nades. I don't know if the weapon_fire event happens for nade throwing - never tested it... but it references "Every time a client fires their 'weapon'"
__________________
View my Plugins | Donate

Last edited by TnTSCS; 03-02-2015 at 09:54.
TnTSCS is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-02-2015 , 11:55   Re: [CSS] How to detect when player has thrown grenade
Reply With Quote #5

OnEntityCreated fires before the game has a chance to set any properties on an entity, so checking m_hThrower there will always give you -1.

You're going to want to add an SDKHooks_SpawnPost hook if you want to read m_hThrower:

PHP Code:
#include <sdkhooks>

public OnEntityCreated(entity, const String:classname[])
{
    if (
strcmp(classname"hegrenade_projectile"false) == 0)
    {
        
SDKHook(entitySDKHook_SpawnPostGrenade_SpawnPost);
    }
}

public 
Grenade_SpawnPost(entity)
{
        new 
owner GetEntPropEnt(entityProp_Send"m_hThrower");
        
        if (
owner != -1)
        {
            
// owner is the player who threw the grenade (entity)
        
}


Note: I haven't tested this. The reason I say this is because for some entities, Valve doesn't set the properties prior to dispatch, so you may need a 0.1 second timer from SpawnPost.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-02-2015 at 11:57. Reason: Hook, not event
Powerlord is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-02-2015 , 12:03   Re: [CSS] How to detect when player has thrown grenade
Reply With Quote #6

The way stickynades does it - of course, this is for a specific purpose and may not apply to your needs. This code would run every game frame. The OnEntityCreated with a timer or SpawnPost hook (possibly with a timer) is your best option - unless you have other needs.

code


Small edit to my original reply with code to be Sourcemod 1.7+ compliant with new syntax
__________________
View my Plugins | Donate

Last edited by TnTSCS; 03-02-2015 at 12:21.
TnTSCS is offline
keygens
Senior Member
Join Date: Mar 2010
Location: Somewhere
Old 03-03-2015 , 02:39   Re: [CSS] How to detect when player has thrown grenade
Reply With Quote #7

Quote:
Originally Posted by TnTSCS View Post
The way stickynades does it - of course, this is for a specific purpose and may not apply to your needs. This code would run every game frame. The OnEntityCreated with a timer or SpawnPost hook (possibly with a timer) is your best option - unless you have other needs.

code


Small edit to my original reply with code to be Sourcemod 1.7+ compliant with new syntax
Thank you!
keygens 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 06:15.


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