Raised This Month: $ Target: $400
 0% 

Cache get_user_weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 01-29-2013 , 12:43   Cache get_user_weapon
Reply With Quote #1

Is it enough to cache it in curweapon event? Is it reliable, because i plan to use cached value in prethink?

Last edited by OvidiuS; 01-29-2013 at 12:43.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 01-29-2013 , 14:55   Re: Cache get_user_weapon
Reply With Quote #2

CurWeapon gets called each time player changes their weapon, picks it up, gets it by any entity or is given on spawn.

The only time it couldn't be called properly is when Ham gives player a weapon or removes it from them, but I'm not sure about this.

Download drekes' StripWeapons HamSandwich library and try it out.
Backstabnoob is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 01-29-2013 , 18:16   Re: Cache get_user_weapon
Reply With Quote #3

Hook Ham_Item_Deploy on every weapon, would be enough for caching user's current weapon id
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-30-2013 , 01:53   Re: Cache get_user_weapon
Reply With Quote #4

What do you plain to do in PreThink ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 01-30-2013 , 13:23   Re: Cache get_user_weapon
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
What do you plain to do in PreThink ?
Good question. After some thinking, i managed to do the same thing in cmdstart. Still i used cached value from item deploy. I was creating eotech zoom for weapons.
Problem was with weapons which have silencer and burst.
Code:
public ham_weaponDeploy_post( iEntity ) {     new id = GetId( iEntity );         if( get_pdata_cbase( id, m_pActiveItem ) == iEntity )     {         global_HasWeapon[ id ] = get_pdata_int( iEntity, m_iId, 4 );         num_to_str( global_HasWeapon[ id ], global_sKey[ id ], charsmax( global_sKey[ ] ) );         set_pdata_float( iEntity, m_flNextPrimaryAttack, 9999.0, 4 );                 new sNewModel;         if( GetFlag( global_bitZoom, id ) && global_tWeaponModel && TrieGetCell( global_tWeaponModel, global_sKey[ id ], sNewModel ) )         {             set_pev( id, pev_viewmodel, sNewModel )         }         else if( global_tSightModel && TrieGetCell( global_tSightModel, global_sKey[ id ], sNewModel ) )         {             set_pev( id, pev_viewmodel, sNewModel )         }     } } public forward_cmdStart( id ) {     static iWeapon;     if( global_tChangedWeapons && TrieGetCell( global_tChangedWeapons, global_sKey[ id ], iWeapon ) )     {         if( !is_user_alive( id ) )             return FMRES_IGNORED;             new iButton = pev( id, pev_button );         new iOldButton = pev( id, pev_oldbuttons );             if( ( iButton & IN_ATTACK2 ) && !( iOldButton & IN_ATTACK2 ) )         {             if( GetFlag( global_bitZoom, id ) || GetFlag( global_bitReloading, id ) )             {                 ClearZoom( id );             }             else             {                 set_pdata_int( id, m_iFOV, 55, 5 );                                     SetFlag( global_bitZoom, id );             }               }         if( ( iButton & IN_USE ) && !( iOldButton & IN_USE ) )         {             static iEntity;             switch( global_HasWeapon[ id ] )             {                 case CSW_M4A1:                 {                     iEntity = fm_find_ent_by_owner( -1, "weapon_m4a1", id );                     if( GetFlag( global_bitSilencer, id ) )                     {                         cs_set_weapon_silen( iEntity, 0 );                         ClearFlag( global_bitSilencer, id );                     }                     else                     {                         cs_set_weapon_silen( iEntity, 1 );                         SetFlag( global_bitSilencer, id );                     }                 }                 case CSW_USP:                 {                     iEntity = fm_find_ent_by_owner( -1, "weapon_usp", id );                     if( GetFlag( global_bitSilencerUsp, id ) )                     {                         cs_set_weapon_silen( iEntity, 0 );                         ClearFlag( global_bitSilencerUsp, id );                     }                     else                     {                         cs_set_weapon_silen( iEntity, 1 );                         SetFlag( global_bitSilencerUsp, id );                     }                 }                 case CSW_FAMAS:                 {                     iEntity = fm_find_ent_by_owner( -1, "weapon_famas", id );                     if( GetFlag( global_bitBurst, id ) )                     {                         cs_set_weapon_burst( iEntity, 0 );                         ClearFlag( global_bitBurst, id );                     }                     else                     {                         cs_set_weapon_burst( iEntity, 1 );                         SetFlag( global_bitBurst, id );                     }                 }                 case CSW_GLOCK18:                 {                     iEntity = fm_find_ent_by_owner( -1, "weapon_glock18", id );                     if( GetFlag( global_bitBurstGlock, id ) )                     {                         cs_set_weapon_burst( iEntity, 0 );                         ClearFlag( global_bitBurstGlock, id );                     }                     else                     {                         cs_set_weapon_burst( iEntity, 1 );                         SetFlag( global_bitBurstGlock, id )                     }                 }             }         }     }     return FMRES_IGNORED; }

Last edited by OvidiuS; 01-30-2013 at 14:16. Reason: IN_ATTACK2
OvidiuS is offline
Send a message via Skype™ to OvidiuS
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-30-2013 , 14:00   Re: Cache get_user_weapon
Reply With Quote #6

find_ent_by_owner in CmdStart sucks
fm_find_ent_by_owner is worst
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 01-30-2013 , 14:11   Re: Cache get_user_weapon
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
find_ent_by_owner in CmdStart sucks
fm_find_ent_by_owner is worst
Well, you could give me some suggestion, what should i use? It's not problem to switch to engine.

EDIT: maybe to cache entity id, in item deploy, and use it later in cmdstart?
but i think that i shouldn't cache every possible value, it's cmdstart, not prethink :S

Last edited by OvidiuS; 01-30-2013 at 14:23.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Reply


Thread Tools
Display Modes

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 20:41.


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