AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect Reloading Weapons (https://forums.alliedmods.net/showthread.php?t=84570)

Mlk27 01-28-2009 07:49

Detect Reloading Weapons
 
how do we detect when weapon is actually being reloaded? this code kinda fail cause it checks for reload button press..weapons won't be reloaded when ammo is full..


Code:
public FwdPlayerPreThink(id) {     if(is_user_alive(id)     {         new button = pev(id, pev_button), old_button = pev(id, pev_oldbuttons)         if((button & IN_RELOAD) && !(old_button & IN_RELOAD))         {             // ....         }     } }

jim_yang 01-28-2009 08:01

Re: Detect Reloading Weapons
 
http://forums.alliedmods.net/showpos...38&postcount=9

Mlk27 01-29-2009 09:11

Re: Detect Reloading Weapons
 
sorry..but ven's codes look too complicated for me..can you show a simplified example?

Arkshine 01-29-2009 09:33

Re: Detect Reloading Weapons
 
You may want to try Ham using Ham_Weapon_Reload, if I understand what you want.

Mlk27 01-29-2009 12:53

Re: Detect Reloading Weapons
 
Quote:

Originally Posted by arkshine (Post 752188)
You may want to try Ham using Ham_Weapon_Reload, if I understand what you want.

yea..that's it but there's one problem..when weapon clips are full and players press reload button, the sound is played anyway although weapons aren not reloaded..how do i make it plays the sound only if weapons are reloaded?

Code:
#include <amxmodx> #include <hamsandwich> const MaxSounds = 3 new SoundList[MaxSounds][] = {     // bla bla... } new g_Weapons[ ][ ] = {   "weapon_p228", "weapon_scout", "weapon_xm1014", "weapon_mac10", "weapon_aug", "weapon_elite", "weapon_fiveseven", "weapon_ump45",     "weapon_sg550", "weapon_galil", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp","weapon_mp5navy", "weapon_m249",     "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_deagle", "weapon_sg552", "weapon_ak47", "weapon_p90" } public plugin_init() {     // register_plugin bla bla...     for(new i = 0 ; i< sizeof g_Weapons; i++)         RegisterHam(Ham_Weapon_Reload, g_Weapons[i], "Ham_Weapon_Reload_Post") } public plugin_precache() {     // bla bla... } public Ham_Weapon_Reload_Post(id) {     new i = random_num(0, MaxSounds - 1)     client_cmd(0, "spk %s", SoundList[i]) }

Arkshine 01-29-2009 13:46

Re: Detect Reloading Weapons
 
You can try that:

Code:
    #include <amxmodx>     #include <fakemeta>     #include <hamsandwich>     #define CANT_RELOAD_BITSUM  ( 1 << CSW_HEGRENADE | 1 << CSW_SMOKEGRENADE | 1<<CSW_FLASHBANG | 1 << CSW_KNIFE | 1 << CSW_C4 )     #define SHOTGUNS_BITSUM     ( 1 << CSW_XM1014 | 1 << CSW_M3 )     #define MAX_WEAPONS         30   // --| Max number of weapons. ( cs1.6/cz )         const sg_start_reload = 5;    // --| Shotgun start reload sequence.     const m_iId           = 43;   // --| Weapon offset. ( return CSW_* )     const m_fInReload     = 54;   // --| Weapon offset.     new const SoundList[][] =     {         " ",         " "     }     public plugin_init()     {         RegisterHamsReload ();     }         public Event_OnReload ( const i_Ent )     {         if ( UTIL_IsWeaponReloading ( pev ( i_Ent , pev_owner ), i_Ent ) )         {             client_cmd ( 0, "spk %s", SoundList[ random_num( 0, sizeof SoundList - 1 ) ] );         }     }       UTIL_IsWeaponReloading ( const id, const i_Ent )     {         // --| If we're holding a shotgun.         if ( 1 << get_pdata_int ( i_Ent, m_iId, 4 ) & SHOTGUNS_BITSUM )         {             // --| We check its animation instead of m_fInSpecialReload because             // --| Event_OnReload will be called 3 times by ball and it's a pain to             // --| deal with that when we want to play the sound one time.             if ( pev ( id, pev_weaponanim ) == sg_start_reload )  { return 1; }         }         // --| Other weapons.         return get_pdata_int ( i_Ent, m_fInReload, 4 );     }         RegisterHamsReload ()     {         // --| Need to loop through all weapons because Ham sucks. :p         // --| As 'post' is necessary, otherwise the offset will not work.         new s_WeaponName[ 24 ];         for ( new i_Wpid = 1; i_Wpid <= MAX_WEAPONS; i_Wpid++ )         {             // --| Don't register item/weapons which can not reload.             if ( !( ( 1 << i_Wpid ) & CANT_RELOAD_BITSUM ) && get_weaponname ( i_Wpid, s_WeaponName, charsmax ( s_WeaponName ) ) )             {                 RegisterHam ( Ham_Weapon_Reload, s_WeaponName, "Event_OnReload", 1 );             }         }     }

Mlk27 01-29-2009 14:30

Re: Detect Reloading Weapons
 
nice! thanks so much arshine! that works..

if i want to replace that spk command with emit sound, is this correct?

Code:

emit_sound(i_Ent, CHAN_AUTO, SoundList[ random_num( 0, sizeof SoundList - 1 ) ], 1.0, ATTN_NORM, 0, PITCH_NORM)
but i cannot hear any sound playing..

Arkshine 01-29-2009 15:12

Re: Detect Reloading Weapons
 
Use id instead. Also ; don't forget to precache the sounds and emit_sound supports only wavs.

Mlk27 01-30-2009 22:19

Re: Detect Reloading Weapons
 
how do i add ID in the Event_OnReload?

Code:
public Event_OnReload ( const i_Ent ) {     if ( UTIL_IsWeaponReloading ( pev ( i_Ent , pev_owner ), i_Ent ) && get_gametime() > g_NextReloadSound[id] )     {         emit_sound(id, CHAN_VOICE, SoundList[ random_num( 0, sizeof SoundList - 1 ) ], 1.0, ATTN_NORM, 0, PITCH_NORM) //id?                 g_NextReloadSound[id] = get_gametime() + 5.0     } }

but that failed to compile..and one more what's the diff CHAN_AUTO with CHAN_STATIC?

jim_yang 01-30-2009 22:26

Re: Detect Reloading Weapons
 
pev ( i_Ent , pev_owner )


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

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