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

Nades Api


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Technical/Development        Approver:   Arkshine (91)
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-26-2013 , 02:10   Nades Api
Reply With Quote #1

Nades Api



.: Description :.


Little Api that let's you know by forwards when a grenade is bouncing or is exploding, is smoking after the explosion, or is simply thinking because it's not time to to something else yet.
This plugin also exposes some natives to retrieve those functions indexes (internally it is pointers but we can use them as integers) that are used with pdata m_pThink and m_pUse.



.: How does the game works :.


When a grenade is shot, its m_pfnTouch function is set to BounceTouch, this function is called internally each time a nade is touching the world (sound is only played on 5 first times).

At grenade shot, m_pfnThink is set to TumbleThink for flash and hegrenade, and to SG_TumbleThink for smokegrenade, this is default think and ends when pev->dmgtime <= gpGlobals->time (and for smoke if nade is on the ground)
Then, m_pfnThink is change to Detonate, Detonate3 and SG_Detonate for respectlively flashbangs, hegrenades and smokegrenades, this is during those functions that specific grenade actions are done (flash, explosion and smoke).
After those actions it is not complitely finished, m_pfnThink is change to Smoke, Smoke3_C and SG_Smoke (same nades types order), this is function where you gonnna see little black smoke before a nade is about to die.



.: Forwards :.


Code:
// Flash forwards forward OnFlashNadenadeBounceTouch(ent, pOther); forward OnFlashNadeTumbleThink(ent); forward OnFlashNadeDetonate(ent); forward OnFlashNadeSmoke(ent); // HeGrenade forwards forward OnHeNadenadeBounceTouch(ent, pOther); forward OnHeNadeTumbleThink(ent); forward OnHeNadeDetonate(ent); forward OnHeNadeSmoke(ent); // SmokeGrenade forwards forward OnSmokeNadenadeBounceTouch(ent, pOther); forward OnSmokeNadeTumbleThink(ent); forward OnSmokeNadeDetonate(ent); forward OnSmokeNadeSmoke(ent);



.: Natives :.


Code:
// Returns TumbleThink index        // FLASH    // HE native Get_Nade_TumbleThink(); // Returns BounceTouch index        // FLASH    // HE   // SMOKE native Get_Nade_BounceTouch(); // Returns Detonate index         // FLASH native Get_Nade_Detonate(); // Returns Smoke index        // FLASH native Get_Nade_Smoke(); // Returns Detonate3 index      // HE native Get_Nade_Detonate3(); // Returns Smoke3_C index         // HE native Get_Nade_Smoke3_C(); // Returns SG_TumbleThink index  // SMOKE native Get_Nade_SG_TumbleThink(); // Returns SG_Detonate index        // SMOKE native Get_Nade_SG_Detonate(); // Returns SG_Smoke index         // SMOKE native Get_Nade_SG_Smoke();



.: Notes :.


You need those includes in order to compile plugin : https://forums.alliedmods.net/showth...01#post1712101
!! NEW !! Experimental version with C4 forwards and natives here : https://forums.alliedmods.net/showth...20#post1923720



Attached Files
File Type: sma Get Plugin or Get Source (nades_api.sma - 1265 views - 10.1 KB)
File Type: inc nades_api.inc (1.3 KB, 909 views)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-31-2013 at 18:25.
ConnorMcLeod is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-26-2013 , 02:11   Re: Nades Api
Reply With Quote #2

Example on how to make a flashbang grenade explode as a smokegrenade instead of blinding players :

Code:
#include <amxmodx> #include <nades_api> #tryinclude <cstrike_pdatas> #if !defined _cbaseentity_included         #assert Cstrike Pdatas and Offsets library required! Read the below instructions:   \                 1. Download it at forums.alliedmods.net/showpost.php?p=1712101#post1712101   \                 2. Put it into amxmodx/scripting/include/ folder   \                 3. Compile this plugin locally, details: wiki.amxmodx.org/index.php/Compiling_Plugins_%28AMX_Mod_X%29   \                 4. Install compiled plugin, details: wiki.amxmodx.org/index.php/Configuring_AMX_Mod_X#Installing #endif #define PLUGIN "" #define VERSION "0.0.1" #define SetThink(%0,%1) set_pdata_int(%0, m_pfnThink, %1, 0) new SG_Detonate new g_iEvent_CreateSmoke public plugin_init() {     register_plugin( PLUGIN, VERSION, "ConnorMcLeod" )     g_iEvent_CreateSmoke = engfunc(EngFunc_PrecacheEvent, 1, "events/createsmoke.sc")     set_task(2.0, "Retrieve_Functions") } public Retrieve_Functions() {     SG_Detonate = Get_Nade_SG_Detonate() } public OnFlashNadeDetonate( ent ) {     if( pev(ent, pev_flags) & FL_ONGROUND )     {         SetThink(ent, SG_Detonate)         set_pdata_short(ent, m_usEvent_Grenade, g_iEvent_CreateSmoke)     }     set_pev(ent, pev_nextthink, get_gametime() + 0.1)     return PLUGIN_HANDLED }
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-26-2013 at 02:15.
ConnorMcLeod is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 03-26-2013 , 17:33   Re: Nades Api
Reply With Quote #3

Man that is amazing
__________________
Jhob94 is offline
quilhos
Veteran Member
Join Date: Jun 2010
Old 03-26-2013 , 20:53   Re: Nades Api
Reply With Quote #4

Nice one, just one thing, this shouldn't be on section: "Code Snippets/Tutorial" ?
__________________
ELO RATING SYSTEM - SQL [COMPLETE]
Quote:
Originally Posted by Liverwiz View Post
DDDRRRRAAAAMMMMAAAAA!!!???

Put this shit on pause while i go get some popcorn!!
quilhos is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-27-2013 , 01:35   Re: Nades Api
Reply With Quote #5

Quote:
Originally Posted by quilhos View Post
Nice one, just one thing, this shouldn't be on section: "Code Snippets/Tutorial" ?
It is not a snippet or a tutorial, it is an api.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
quilhos
Veteran Member
Join Date: Jun 2010
Old 03-27-2013 , 06:42   Re: Nades Api
Reply With Quote #6

Then isnt exacly one plugin
__________________
ELO RATING SYSTEM - SQL [COMPLETE]
Quote:
Originally Posted by Liverwiz View Post
DDDRRRRAAAAMMMMAAAAA!!!???

Put this shit on pause while i go get some popcorn!!
quilhos is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-27-2013 , 12:13   Re: Nades Api
Reply With Quote #7

sma to amxx : plugin
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
quilhos
Veteran Member
Join Date: Jun 2010
Old 03-28-2013 , 08:15   Re: Nades Api
Reply With Quote #8

Quote:
Originally Posted by ConnorMcLeod View Post
sma to amxx : plugin
It depends the point of view xb
But great work by the way
__________________
ELO RATING SYSTEM - SQL [COMPLETE]
Quote:
Originally Posted by Liverwiz View Post
DDDRRRRAAAAMMMMAAAAA!!!???

Put this shit on pause while i go get some popcorn!!
quilhos is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-31-2013 , 07:48   Re: Nades Api
Reply With Quote #9

Experimental version with new forwards and natives :
Make sure you have latest cstrike_pdata includes files, some weapon_c4 pdatas were missing, i've edited attachment today.

.: Forwards :.


Code:
// C4 forwards forward OnC4C4Touch(ent, pOther); forward OnC4C4Think(ent); forward OnC4Detonate2(ent); forward OnC4Smoke2(ent);



.: Natives :.


Code:
// Returns C4Think index            // C4 native Get_C4_C4Think(); // Returns Detonate2 index      // C4 native Get_C4_Detonate2(); // Returns C4Touch index            // C4 native Get_C4_C4Touch(); // Returns Smoke2 index   // C4 native Get_C4_Smoke2();



.: Test Plugin :.


PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <nades_api>

#tryinclude <cstrike_pdatas>

#if !defined _cbaseentity_included
        #assert Cstrike Pdatas and Offsets library required! Read the below instructions:   \
                
1. Download it at forums.alliedmods.net/showpost.php?p=1712101#post1712101   \
                
2. Put it into amxmodx/scripting/include/ folder   \
                
3. Compile this plugin locallydetailswiki.amxmodx.org/index.php/Compiling_Plugins_%28AMX_Mod_X%29   \
                
4. Install compiled plugindetailswiki.amxmodx.org/index.php/Configuring_AMX_Mod_X#Installing
#endif

#define PLUGIN ""
#define VERSION "0.0.1"

#define GetThink(%0) get_pdata_int(%0, m_pfnThink, 0)
#define GetTouch(%0) get_pdata_int(%0, m_pfnTouch, 1)
#define GetUse(%0) get_pdata_int(%0, m_pfnUse, 2)
#define GetBlocked(%0) get_pdata_int(%0, m_pfnBlocked, 3)
#define GetCallWhenMoveDone(%0) get_pdata_int(%0, m_pfnCallWhenMoveDone, 4)

#define SetThink(%0,%1) set_pdata_int(%0, m_pfnThink, %1, 0)
#define SetTouch(%0,%1) set_pdata_int(%0, m_pfnTouch, %1, 1)
#define SetUse(%0,%1) set_pdata_int(%0, m_pfnUse, %1, 2)
#define SetBlocked(%0,%1) set_pdata_int(%0, m_pfnBlocked, %1, 3)
#define SetCallWhenMoveDone(%0,%1) set_pdata_int(%0, m_pfnCallWhenMoveDone, %1, 4)

new SG_DetonateDetonate2Detonate3
new g_iEvent_CreateSmoke

public plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" )

    
g_iEvent_CreateSmoke engfunc(EngFunc_PrecacheEvent1"events/createsmoke.sc")
}

public 
plugin_cfg()
{
    
SG_Detonate Get_Nade_SG_Detonate()
    
Detonate2 Get_C4_Detonate2()
    
Detonate3 Get_Nade_Detonate3()
}

public 
OnFlashNadeDetonateent )
{
    if( 
pev(entpev_flags) & FL_ONGROUND )
    {
        
ExecuteHam(Ham_Thinkent// make explode as flash

        
SetThink(entDetonate3)
        
ExecuteHam(Ham_Thinkent// make explode as HE

        
SetThink(entSG_Detonate)
        
set_pdata_short(entm_usEvent_Grenadeg_iEvent_CreateSmoke// set Smoke explosion so on this think game makes it explode as a smoke grenade
        
return PLUGIN_CONTINUE
    
}
    
set_pev(entpev_nextthinkget_gametime() + 0.1)
    return 
PLUGIN_HANDLED
}

public 
OnHeNadeDetonateent )
{
    
SetThink(entDetonate2// make HE detonate as planted c4 (terminates round on de_ maps)

Attached Files
File Type: inc nades_api.inc (1.6 KB, 284 views)
File Type: sma Get Plugin or Get Source (nades_api.sma - 425 views - 14.9 KB)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-31-2013 at 18:24.
ConnorMcLeod is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 03-27-2013 , 13:56   Re: Nades Api
Reply With Quote #10

Great Work Connor, it's very useful and saves me a lot of time.
__________________
Kia 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:40.


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