AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Using SDKHook_Touch with grenades? (https://forums.alliedmods.net/showthread.php?t=263056)

Beaverboys 05-17-2015 22:01

Using SDKHook_Touch with grenades?
 
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 ...
    
}



Neuro Toxin 05-17-2015 23:15

Re: Using SDKHook_Touch with grenades?
 
Can you not hook start touch without having to use a timer?

Beaverboys 05-18-2015 00:03

Re: Using SDKHook_Touch with grenades?
 
Quote:

Originally Posted by Neuro Toxin (Post 2298115)
Can you not hook start touch without having to use a timer?

I used the timer to get the SetEntProp line to work

Neuro Toxin 05-18-2015 03:11

Re: Using SDKHook_Touch with grenades?
 
Um. Might be best to hook clients.

Check classname of other ;)

Powerlord 05-18-2015 10:18

Re: Using SDKHook_Touch with grenades?
 
Out of curiosity, have you tried hooking SDKHook_SpawnPost in OnEntityCreated?

Beaverboys 05-18-2015 22:25

Re: Using SDKHook_Touch with grenades?
 
Quote:

Originally Posted by Powerlord (Post 2298276)
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");



TnTSCS 05-19-2015 11:50

Re: Using SDKHook_Touch with grenades?
 
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.

Beaverboys 05-19-2015 16:30

Re: Using SDKHook_Touch with grenades?
 
Quote:

Originally Posted by TnTSCS (Post 2298647)
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.

Beaverboys 05-19-2015 16:43

Re: Using SDKHook_Touch with grenades?
 
Quote:

Originally Posted by Neuro Toxin (Post 2298156)
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.

Miu 05-19-2015 17:36

Re: Using SDKHook_Touch with grenades?
 
Your code works fine for me. Does Sticky Nades Lite not work for you either?


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

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