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

Grenade Name return


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 22:20   Re: Grenade Name return
Reply With Quote #21

Yes, now the grenade is passed to the take health and killed by functions so you can react directly instead of assigning the grenade type to a global variable and reacting to it in each function. That could get messy if there are a lot of grenade simultaneously thrown.
__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 22:24   Re: Grenade Name return
Reply With Quote #22

Uh, thank you dude.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 22:30   Re: Grenade Name return
Reply With Quote #23

Quote:
Originally Posted by EFFx View Post
The last thing, how can I call the 114 at get_pdata_int()? m_pGrenade ?

PHP Code:
get_pdata_int(toucher114
https://forums.alliedmods.net/showpo...&postcount=175

114 is related to grenades events and a generic name would be : m_usEvent
  • 0 : Flashbang : Since there is no event for that, value is null.
  • 1 : HE grenade ; value by default returned from PRECACHE_EVENT( 1, "events/createexplo.sc" )
  • 2 : Smoke grenade : value by default returned from PRECACHE_EVENT( 1, "events/createsmoke.sc" )
__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 22:30   Re: Grenade Name return
Reply With Quote #24

Hey, can I do this?

PHP Code:
public plugin_precache()
{
    if(
get_pcvar_num(PluginEnabled))
    {
        for(new 
i;sizeof EmitSounds;i++)
        {
            
precache_sound(EmitSounds[i])
        }
    }

Or a check is needed only on fwd_touch() ?

Edit: I got what you said

PHP Code:
    new bits get_pdata_int(index114)
    if (
bits & (1<<0))
        return 
CSW_HEGRENADE
    
else if (bits & (1<<1))
        return 
CSW_SMOKEGRENADE
    
else if (!bits)
        return 
CSW_FLASHBANG

    
return 
Thats the code you were using to check what grenade has been threw.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-03-2017 at 22:32.
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 22:36   Re: Grenade Name return
Reply With Quote #25

Quote:
Originally Posted by EFFx View Post
Hey, can I do this?

PHP Code:
public plugin_precache()
{
    if(
get_pcvar_num(PluginEnabled))
    {
        for(new 
i;sizeof EmitSounds;i++)
        {
            
precache_sound(EmitSounds[i])
        }
    }

Or a check is needed only on fwd_touch() ?
[/php]

Thats the code you were using to check what grenade has been threw.
No, precache is called before init so your cvar pointer will be 0. You are better off letting precache get called..this way if the plugin is enabled during a game, it will begin working.

I see no harm in calling it on touch, but put the cvar check after you do the spam check.
__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 22:44   Re: Grenade Name return
Reply With Quote #26

Wait, I didn't get it.

So, I shouldn't add a check on plugin_precache(), the players will be forced to precache the sounds but the cvar will be 0 and these sounds will not be used. But it makes sense when someone want to turn the cvar 1 and him don't need to reset the map for the plugin become working.

The check on fwd_touch will be executed so much times per second, and milions times per map, right?
You told me to put the cvar after the check, you meant this

PHP Code:
public fwd_touch(touchedtoucher
{    
    new 
id pev(toucherpev_owner)
    
    if(
gLastTouched[id] != touched)
    {
        if(!
get_pcvar_num(PluginEnabled))
            return 
FMRES_IGNORED
            
        
new iGrenadeBits get_pdata_int(toucherm_usEvent)
        
        if(!(
iGrenadeBits & (<< 0)))
        {
            
takeHealth(touchedid, (iGrenadeBits & (<< 1)) ? SmokeGrenade Flashbang)
            
gLastTouched[id] = touched
        
}
    }
    return 
FMRES_IGNORED

Right? But will not be the same? the fwd_touch() will be executed so much times yet.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-03-2017 at 22:46.
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 22:51   Re: Grenade Name return
Reply With Quote #27

fwd_touch() will get executed, there's no way around that without pausing/stopping the entire plugin.

The goal is to prevent as much code, especially natives, from getting called when the plugin is disabled. Your code looks ok, you just have to move gLastTouched[id] = touched outside of that if statement. Your current code would allow HE grenades to spam.

Edit: This will not work, gLastTouched[id] = touched will not get reached when the plugin is disabled.
Edit2: Fixed
PHP Code:
public fwd_touch(touchedtoucher
{
    new 
id pev(toucherpev_owner)
    
    if ( 
gLastTouched[id] != touched )
    {
        if ( 
get_pcvar_numPluginEnabled ) ) 
        {
            new 
iGrenadeBits get_pdata_int(toucherm_usEvent)
            
            if(!(
iGrenadeBits & (<< 0)))
            {
                
takeHealth(touchedid, (iGrenadeBits & (<< 1)) ? SmokeGrenade Flashbang)
            }
        }
        
        
gLastTouched[id] = touched
    
}
    
    return 
FMRES_IGNORED

__________________

Last edited by Bugsy; 02-03-2017 at 22:55.
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 22:56   Re: Grenade Name return
Reply With Quote #28

Yes, I was thinking to pause the plugin. But I'll continue adding the check only on fwd_touch().

Then the cvar check should be before of any native/code for prevent any native/code gets called, right?

Yes, my code allow HE Grenade to spam.

PHP Code:
public fwd_touch(touchedtoucher
{    
    if(!
get_pcvar_num(PluginEnabled))
        return 
FMRES_IGNORED

    
new id pev(toucherpev_owner)
    
    if(
gLastTouched[id] != touched)
    {    
        new 
iGrenadeBits get_pdata_int(toucherm_usEvent)
        
        if(!(
iGrenadeBits & (<< 0)))
        {
            
takeHealth(touchedid, (iGrenadeBits & (<< 1)) ? SmokeGrenade Flashbang)
        }
    }
    
gLastTouched[id] = touched
    
return FMRES_IGNORED

That's the final code?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-03-2017 at 22:57.
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 22:59   Re: Grenade Name return
Reply With Quote #29

No, look at my edited post.

Edit: Nevermind, either way a native is being called. May as well just check the cvar instead of pev_owner. So yes, your code is fine, just move gLastTouched[id] = touched above that closing bracket.
__________________

Last edited by Bugsy; 02-03-2017 at 23:03.
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 23:04   Re: Grenade Name return
Reply With Quote #30

Wait,

this

PHP Code:
if(!(iGrenadeBits & (<< 0))) 
Is checking if the grenade bits isn't the HE grenade right?

So, cannot be like this?

PHP Code:
public fwd_touch(touchedtoucher
{
    new 
iGrenadeBits get_pdata_int(toucherm_usEvent)
            
    if(!(
iGrenadeBits & (<< 0)))
    {
        new 
id pev(toucherpev_owner)
    
        if(
gLastTouched[id] != touched)
        {
            if(
get_pcvar_num(PluginEnabled)) 
            {
                
takeHealth(touchedid, (iGrenadeBits & (<< 1)) ? SmokeGrenade Flashbang)
                
gLastTouched[id] = touched
            
}
        }
    }
    return 
FMRES_IGNORED

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx 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 17:57.


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