AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Event fired when shield is used or not used? (https://forums.alliedmods.net/showthread.php?t=62273)

Mugwump 10-22-2007 13:48

Event fired when shield is used or not used?
 
Heya, is there an event I can hook for when the CT shield is used? CurWeapon does not seem to fire when the shield is used or not used...

Thanks,
Mugwump

Alka 10-22-2007 13:59

Re: Event fired when shield is used or not used?
 
Try this...
http://www.amxmodx.org/funcwiki.php?...ield&go=search

Mugwump 10-22-2007 14:04

Re: Event fired when shield is used or not used?
 
I don't know if that helps. The definition says if the user _has_ a shield, but not whether its in use mode or not.

When a player uses their shield (puts it in block mode) their default runspeed slow down, I want to be able to detect that they just used their shield so I can override the runspeed change...

Thanks,
Mugwump

Arkshine 10-22-2007 14:39

Re: Event fired when shield is used or not used?
 
You have to use IN_ATTACK2 button to use a shield. ( I believe :o )

So something like :

Code:
if( ( pev( id, pev_button ) & IN_ATTACK2 ) && cs_get_user_shield( id ) )

But to detect properly IN_ATTACK2 you have to use the PlayerPreThink forward or CmdStart, I think.

ConnorMcLeod 10-22-2007 16:02

Re: Event fired when shield is used or not used?
 
You can use this, may be make full tests before...

Code:
#include <amxmodx> #include <fakemeta> #define OFFSET_SHIELD   510 #define HAS_SHIELD      (1<<24) #define USES_SHIELD     (1<<16) #define MAXPLAYERS  32 enum ShieldState {     Hasnt = 0,     Has,     Uses } new ShieldState:has_shield[MAXPLAYERS+1] public plugin_init() {     register_plugin("shield test", "0.1", "ConnorMcLeod")       register_forward(FM_PlayerPreThink, "fwdPlayerPreThink") } public fwdPlayerPreThink(id) {     if(!is_user_alive(id) || !is_user_connected(id))         return     static shield_offset     shield_offset = get_pdata_int(id, OFFSET_SHIELD)     if(shield_offset & HAS_SHIELD)     {         if(shield_offset & USES_SHIELD && has_shield[id] != Uses)         {             // player has just used his shield, you can fire a forward             has_shield[id] = Uses         }         else if(has_shield[id] != Has)         {             // player doesn't use his shield anymore, you can fire a forward             has_shield[id] = Has         }               }     else if(has_shield[id])     {         // player droped his shield ?, respawn ?         has_shield[id] = Hasnt     }     return } //for a native public has_user_shield(id) {     new ShieldState:result, shield_offset = get_pdata_int(id, OFFSET_SHIELD)     if(shield_offset & HAS_SHIELD)         if(shield_offset & USES_SHIELD)             result = Uses         else             result = Has     else         result = Hasnt      return result }

Either you use this in a plugin, either you create a native, either you need the event when the player uses it and in this case i guess you need to create a forward.Well, i don't know yet how to deal with forward creation, but you seem to be skilled ;)

I guess this offset could be added in cstrike module.

Mugwump 10-22-2007 20:38

Re: Event fired when shield is used or not used?
 
The PreThink logic appears to work great, I can use a similar technique for what I need to accomplish. Thank you!

-Mugwump

Orangutanz 10-23-2007 08:41

Re: Event fired when shield is used or not used?
 
Quote:

Originally Posted by arkshine (Post 545126)
You have to use IN_ATTACK2 button to use a shield. ( I believe :o )

So something like :

Code:
if( ( pev( id, pev_button ) & IN_ATTACK2 ) && cs_get_user_shield( id ) )

But to detect properly IN_ATTACK2 you have to use the PlayerPreThink forward or CmdStart, I think.

CmdStart is the best method, since that is where the buttons are actually sent/received from.


All times are GMT -4. The time now is 01:12.

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