AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Ham_TraceAttack for Grenades? (https://forums.alliedmods.net/showthread.php?t=305883)

WAR3DM 03-08-2018 15:20

Ham_TraceAttack for Grenades?
 
Hello :)

Is it possible to trace grenade attacks on a brush entity? Ham_TraceAttack seems to only work for bullets.

Code:

/**
    * Description:    Usually called whenever an entity gets attacked by a hitscan (such as a gun) weapon.
    *                  Use the get/set tr2 natives in fakemeta to handle the traceresult data.
    *                  Do not use a handle of 0 as a traceresult in execution, use create_tr2() from Fakemeta
    *                  to pass a custom handle instead.  (Don't forget to free the handle when you're done.)
    * Forward params:  function(this, idattacker, Float:damage, Float:direction[3], traceresult, damagebits)
    * Return type:    None.
    * Execute params:  ExecuteHam(Ham_TraceAttack, this, idattacker, Float:damage, Float:direction[3], tracehandle, damagebits);
    */
    Ham_TraceAttack

I tried Ham_TakeDamage but that doesn't seem to work on brush entities.

Perhaps there's a way to detect grenade blasts within a radius around the brush entity?

Any help is greatly appreciated!

E1_531G 03-08-2018 17:19

Re: Ham_TraceAttack for Grenades?
 
Quote:

Perhaps there's a way to detect grenade blasts within a radius around the brush entity?
1. Hook takedamage on func_breakable?
2. On explode search ent in radius?

Celena Luna 03-09-2018 15:09

Re: Ham_TraceAttack for Grenades?
 
Hook grenade think then get dmgtime, when 1.0s before explode, do check brush entity

PHP Code:

RegisterHam(Ham_Think"grenade""fw_ThinkGrenade")

...

public 
fw_ThinkGrenade(Ent)
{
    if(!
pev_valid(Ent)) return HAM_IGNORED

    
static Float:dmgtime
    pev
(Entpev_dmgtimedmgtime)
    
    if(
dmgtime 1.0 <= get_gametime())
    {
        
//Check here
    
}



WAR3DM 03-09-2018 23:26

Re: Ham_TraceAttack for Grenades?
 
Thanks, that works perfect!

Any idea how to keep it from triggering multiple times for each grenade?

Celena Luna 03-10-2018 07:00

Re: Ham_TraceAttack for Grenades?
 
Quote:

Originally Posted by WAR3DM (Post 2582185)
Thanks, that works perfect!

Any idea how to keep it from triggering multiple times for each grenade?

What do you mean?

WAR3DM 03-10-2018 14:13

Re: Ham_TraceAttack for Grenades?
 
Quote:

Originally Posted by Celena Luna (Post 2582231)
What do you mean?

fw_ThinkGrenade triggers multiple times for every grenade, I only need it to trigger once.

E1_531G 03-10-2018 14:42

Re: Ham_TraceAttack for Grenades?
 
https://www.amxmodx.org/api/hamsandw...ableHamForward

HamletEagle 03-10-2018 16:25

Re: Ham_TraceAttack for Grenades?
 
Quote:

Originally Posted by WAR3DM (Post 2582315)
fw_ThinkGrenade triggers multiple times for every grenade, I only need it to trigger once.

It's a think event, it's going to be called again and again and again until this entity is removed. You can disable the forward or use some boolean to decide when you want to execute the code.

Celena Luna 03-10-2018 17:25

Re: Ham_TraceAttack for Grenades?
 
Quote:

Originally Posted by WAR3DM (Post 2582315)
fw_ThinkGrenade triggers multiple times for every grenade, I only need it to trigger once.

Like Hamlet said, you can disable forward but I suggest you not doing it if you don't know what are you doing.

Other way is the give a boolean but you need to make the g_Checked back to false somewhere to make the grenade check brush entity again

PHP Code:

new bool:g_Checked 

RegisterHam
(Ham_Think"grenade""fw_ThinkGrenade")

...

public 
fw_ThinkGrenade(Ent)
{
    if(!
pev_valid(Ent)) return HAM_IGNORED

    
static Float:dmgtime
    pev
(Entpev_dmgtimedmgtime)
    
    if(
dmgtime 1.0 <= get_gametime())
    {
        if(!
g_Checked)
        {
                
//Check here
                
g_Checked true
        
}
    }



WAR3DM 03-10-2018 21:38

Re: Ham_TraceAttack for Grenades?
 
Thanks guys, the bool global works perfectly. I set it back to false with a set_task.


All times are GMT -4. The time now is 23:31.

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