Raised This Month: $32 Target: $400
 8% 

Using SDKHook_Touch with grenades?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Beaverboys
Member
Join Date: Aug 2012
Old 05-17-2015 , 22:01   Using SDKHook_Touch with grenades?
Reply With Quote #1

I'm trying to use SDKHook_Touch to sense when a hegrenade_projectile touches a player but I can't get it to work. This is basically what my code looks like:

PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if(!
strcmp(classname"hegrenade_projectile"false))
    {
        new 
iReference EntIndexToEntRef(entity);
        
CreateTimer(0.0OnGrenadeCreatediReference);
    }
}

public 
Action:OnGrenadeCreated(Handle:timerany:ref)
{
    new 
entity EntRefToEntIndex(ref);
    if(
entity != INVALID_ENT_REFERENCE)
        
SetEntProp(entityProp_Data"m_nNextThinkTick", -1); // prevent the grenade from exploding
    
SDKHook(entity,SDKHook_Touch,GrenadeTouch);
}

public 
GrenadeTouch(entity,other)
{
    if (
<= other <= MaxClients// grenade touches a player
    
{
        
// Do stuff ...
    
}


Last edited by Beaverboys; 05-19-2015 at 16:35.
Beaverboys is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 05-17-2015 , 23:15   Re: Using SDKHook_Touch with grenades?
Reply With Quote #2

Can you not hook start touch without having to use a timer?
__________________
Neuro Toxin is offline
Beaverboys
Member
Join Date: Aug 2012
Old 05-18-2015 , 00:03   Re: Using SDKHook_Touch with grenades?
Reply With Quote #3

Quote:
Originally Posted by Neuro Toxin View Post
Can you not hook start touch without having to use a timer?
I used the timer to get the SetEntProp line to work
Beaverboys is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 05-18-2015 , 03:11   Re: Using SDKHook_Touch with grenades?
Reply With Quote #4

Um. Might be best to hook clients.

Check classname of other ;)
__________________
Neuro Toxin is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-18-2015 , 10:18   Re: Using SDKHook_Touch with grenades?
Reply With Quote #5

Out of curiosity, have you tried hooking SDKHook_SpawnPost in OnEntityCreated?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Beaverboys
Member
Join Date: Aug 2012
Old 05-18-2015 , 22:25   Re: Using SDKHook_Touch with grenades?
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
Out of curiosity, have you tried hooking SDKHook_SpawnPost in OnEntityCreated?
I tried this and it didn't work, it actually made the SetEntProp line not work anymore as well
PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if(!
strcmp(classname"hegrenade_projectile"false))
    {
        new 
iReference EntIndexToEntRef(entity);
        
SDKHook(iReference,SDKHook_SpawnPost,OnGrenadeCreated);
    }
}

public 
Action:OnGrenadeCreated(ref)
{
    new 
entity EntRefToEntIndex(ref);
    if(
entity != INVALID_ENT_REFERENCE)
        
SetEntProp(entityProp_Data"m_nNextThinkTick", -1); // prevent the grenade from exploding
    
SDKHook(entity,SDKHook_Touch,GrenadeTouch);
}

public 
GrenadeTouch(entity,other)
{
    if (
<= other <= MaxClients// grenade touches a player
        
PrintToServer("Player touched a grenade");

Beaverboys is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 05-19-2015 , 11:50   Re: Using SDKHook_Touch with grenades?
Reply With Quote #7

You could also use the event "grenade_bounce" similar to how Sticky Nades works... depending on your specific need/purpose

Or check out how Sticky Nades Lite works with SDKHooks - This plugin uses SDKHook_StartTouch as opposed to SDKHook_Touch in the timer callback.
__________________
View my Plugins | Donate

Last edited by TnTSCS; 05-19-2015 at 11:53.
TnTSCS is offline
Beaverboys
Member
Join Date: Aug 2012
Old 05-19-2015 , 16:30   Re: Using SDKHook_Touch with grenades?
Reply With Quote #8

Quote:
Originally Posted by TnTSCS View Post
You could also use the event "grenade_bounce" similar to how Sticky Nades works... depending on your specific need/purpose

Or check out how Sticky Nades Lite works with SDKHooks - This plugin uses SDKHook_StartTouch as opposed to SDKHook_Touch in the timer callback.
I looked at the Sticky Nades code for help, I tried using SDKHook_StartTouch and it did nothing for me. As far as I know, "grenade_bounce" will not accomplish what I'm trying to do.

Last edited by Beaverboys; 05-19-2015 at 16:32.
Beaverboys is offline
Beaverboys
Member
Join Date: Aug 2012
Old 05-19-2015 , 16:43   Re: Using SDKHook_Touch with grenades?
Reply With Quote #9

Quote:
Originally Posted by Neuro Toxin View Post
Um. Might be best to hook clients.

Check classname of other ;)
This isn't an option as I absolutely need to hook touch for the grenade for other features that I haven't added yet.

Last edited by Beaverboys; 05-19-2015 at 16:43.
Beaverboys is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 05-19-2015 , 17:36   Re: Using SDKHook_Touch with grenades?
Reply With Quote #10

Your code works fine for me. Does Sticky Nades Lite not work for you either?
Miu 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 21:59.


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