AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Event Hooking (https://forums.alliedmods.net/showthread.php?t=101025)

Twelve-60 08-20-2009 01:55

Event Hooking
 
Is it possible to hook events such as player_blind (flashed) and player_abort_defuse?

So far I've just been using register_logevent, but these obviously don't get logged, and it doesn't appear in the event listing here http://wiki.amxmodx.org/Half-Life_1_Game_Events

Thanks

- Twelve-60

Exolent[jNr] 08-20-2009 02:12

Re: Event Hooking
 
For defuse/bomb scripting:
http://forums.alliedmods.net/showthread.php?t=40164

For flash blind:
Code:
#include < amxmodx > public plugin_init( ) {     register_message( get_user_msgid( "ScreenFade" ), "MessageScreenFade" ); } public MessageScreenFade( iMsgId, iDest, iReceiver ) {     if( get_msg_arg_int( 4 ) == 255     && get_msg_arg_int( 5 ) == 255     && get_msg_arg_int( 6 ) == 255 )     {         new iAlpha = get_msg_arg_int( 7 );         if( iAlpha == 200 || iAlpha == 255 )         {             // iReceiver was flashed         }     } }
OR
Code:
#include < amxmodx > public plugin_init( ) {     register_event( "ScreenFade", "EventFlashbang", "b", "4=255", "5=255", "6=255", "7=200", "7=255" ); } public EventFlashbang( client ) {     // client was flashed }

Twelve-60 08-20-2009 02:33

Re: Event Hooking
 
Great, awesome :D

I also forgot one, grenade_detonate (i.e. when a grenade detonates (flash/smoke/he), and detect who threw it?

Thanks again!

- Twelve-60

Exolent[jNr] 08-20-2009 02:44

Re: Event Hooking
 
Code:
#include < amxmodx > #include < engine > public plugin_init( ) {     register_think( "grenade", "FwdGrenadeThink" ); } public FwdGrenadeThink( iEntity ) {     if( is_valid_ent( iEntity ) )     {         static Float:fExplodeTime;         fExplodeTime = entity_get_float( iEntity, EV_FL_dmgtime );                 if( fExplodeTime <= get_gametime( ) )         {             // iEntity is exploding                         new iOwner = entity_get_edict( iEntity, EV_ENT_owner );             // iOwner = the person who threw it         }     } }

Twelve-60 08-20-2009 02:57

Re: Event Hooking
 
Hmm, what exactly is going on there? e.g. how many times is FwdGrenadeThink being called?

Trying to be faily efficient :D

Thanks

- Twelve-60

Exolent[jNr] 08-20-2009 03:03

Re: Event Hooking
 
The grenade's think after it has been throw is like a player's PreThink.
Therefore, we have to filter out its explode time so we can get the explosion.

Twelve-60 08-20-2009 03:09

Re: Event Hooking
 
Ah okay.

So how would I hook the throwing event itself? (i.e. before detonating), and how do I know what type of grenade it is? :D

Thanks

- Twelve-60

Exolent[jNr] 08-20-2009 03:58

Re: Event Hooking
 
Code:
#include < amxmodx > #include < fakemeta > new const g_iNadeConstants[ 3 ] = {     CSW_HEGRENADE,     CSW_FLASHBANG,     CSW_SMOKEGRENADE }; new const g_szNadeModels[ 3 ][ ] = {     "models/w_hegrenade.mdl",     "models/w_flashbang.mdl",     "models/w_smokegrenade.mdl"; }; new Trie:g_tNadeModels; public plugin_init( ) {     g_tNadeModels = TrieCreate( );         for( new i = 0; i < 3; i++ )     {         TrieSetCell( g_tNadeModels, g_szNadeModels[ i ], i );     }         register_forward( FM_SetModel, "FwdSetModel", 1 ); } public plugin_end( ) {     TrieDestroy( g_tNadeModels ); } public FwdSetModel( iEntity, const szModel[ ] ) {     if( pev_vaild( iEntity ) )     {         new iOwner = pev( iEntity, pev_owner );                 if( is_user_connected( iOwner ) )         {             static Float:fExplodeTime;             pev( iEntity, pev_dmgtime, fExplodeTime );                         if( fExplodeTime > 0.0 )             {                 static iIndex;                 if( TrieGetCell( g_tNadeModels, szModel, iIndex ) )                 {                     new CSW_nadetype = g_iNadeConstants[ iIndex ];                                         // iEntity = the grenade entity                     // CSW_nadetype = the CSW_* constant for the nade type                     // iOwner = the thrower                 }             }         }     } }

Twelve-60 08-20-2009 06:52

Re: Event Hooking
 
Awesome thanks :D
- Twelve-60

Twelve-60 08-20-2009 07:01

Re: Event Hooking
 
hmmm I seem to having trouble with the bomb planted event, I posted it in that thread:

http://forums.alliedmods.net/showpos...2&postcount=46

I don't see how I can find out who is planting :( Without maybe tracking it through bomb_drop/pickup/spawn events

- Twelve-60


All times are GMT -4. The time now is 15:13.

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