AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cache get_user_weapon (https://forums.alliedmods.net/showthread.php?t=207080)

OvidiuS 01-29-2013 12:43

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

Backstabnoob 01-29-2013 14:55

Re: Cache get_user_weapon
 
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.

meTaLiCroSS 01-29-2013 18:16

Re: Cache get_user_weapon
 
Hook Ham_Item_Deploy on every weapon, would be enough for caching user's current weapon id

ConnorMcLeod 01-30-2013 01:53

Re: Cache get_user_weapon
 
What do you plain to do in PreThink ?

OvidiuS 01-30-2013 13:23

Re: Cache get_user_weapon
 
Quote:

Originally Posted by ConnorMcLeod (Post 1883331)
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; }

ConnorMcLeod 01-30-2013 14:00

Re: Cache get_user_weapon
 
find_ent_by_owner in CmdStart sucks
fm_find_ent_by_owner is worst

OvidiuS 01-30-2013 14:11

Re: Cache get_user_weapon
 
Quote:

Originally Posted by ConnorMcLeod (Post 1883608)
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


All times are GMT -4. The time now is 20:41.

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