Raised This Month: $32 Target: $400
 8% 

Refresh hud information when manually change it


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
t0mi
Junior Member
Join Date: Jun 2020
Location: Argentina
Old 03-19-2023 , 14:52   Refresh hud information when manually change it
Reply With Quote #1

When a player reload a weapon, i set his clip ammo to 1 but the hud doesn't change until the refeshing. For example changing to knife and comeback to the weapon.

The code is in 'CurWeapon' hooked event:

Code:
public check_model(id){
	
	new iWeapon = read_data(2)

	if(iWeapon != NEWTON_GUN)
		return PLUGIN_HANDLED

	new iWeaponEnt = find_ent_by_owner(-1, SZ_NEWTON_GUN, id)

	new iClip = cs_get_weapon_ammo(iWeaponEnt)
	
	if(iClip > 1){
		cs_set_weapon_ammo(iWeaponEnt, 1)
		cs_set_user_bpammo(id, NEWTON_GUN, cs_get_user_bpammo(id, NEWTON_GUN) + iClip - 1)
	}

	return PLUGIN_CONTINUE
}
How can i update the hud?

Last edited by t0mi; 03-19-2023 at 14:54.
t0mi is offline
Dexon
Member
Join Date: Aug 2019
Old 03-19-2023 , 15:59   Re: Refresh hud information when manually change it
Reply With Quote #2

Use this stock after setting ammo:
PHP Code:
update_ammo_hud(idiAmmoAmountiBPAmmoAmount)
{
    
// Display the new antidotegun bullets
    
if(iAmmoAmount != -1)
    {
        
message_begin(MSG_ONE_UNRELIABLEg_msgCurWeapon_id)
        
write_byte(1// active
        
write_byte(CSW_GALIL// weapon
        
write_byte(iAmmoAmount// clip
        
message_end()
    }
   
    
// Display the new amount of BPAmmo
    
if(iBPAmmoAmount != -1)
    {
        
message_begin(MSG_ONE_UNRELIABLEg_msgAmmoX_id)
        
write_byte(AMMOID_GALIL// ammoid
        
write_byte(iBPAmmoAmount// ammo amount
        
message_end()
    }

__________________
[ExTasY] Zombie Mutation [ZOMBIE NPC]

Join now!

Video: https://www.youtube.com/watch?v=fNahCsS8DOU&t=328s
DC: https://discord.gg/swARTUZCZ4

Creating private plugins, reference above.
Dexon is offline
t0mi
Junior Member
Join Date: Jun 2020
Location: Argentina
Old 03-19-2023 , 18:09   Re: Refresh hud information when manually change it
Reply With Quote #3

Quote:
Originally Posted by Dexon View Post
Use this stock after setting ammo:
PHP Code:
update_ammo_hud(idiAmmoAmountiBPAmmoAmount)
{
    
// Display the new antidotegun bullets
    
if(iAmmoAmount != -1)
    {
        
message_begin(MSG_ONE_UNRELIABLEg_msgCurWeapon_id)
        
write_byte(1// active
        
write_byte(CSW_GALIL// weapon
        
write_byte(iAmmoAmount// clip
        
message_end()
    }
   
    
// Display the new amount of BPAmmo
    
if(iBPAmmoAmount != -1)
    {
        
message_begin(MSG_ONE_UNRELIABLEg_msgAmmoX_id)
        
write_byte(AMMOID_GALIL// ammoid
        
write_byte(iBPAmmoAmount// ammo amount
        
message_end()
    }

i have compiler error because g_msgCurWeapon and g_msgAmmoX is not defined (parameters of message_begin).

And where i can see the ammoid of the weapons? you use AMMOID_GALIL but i need for p228 for example.

I dont know how to use messages xd
Thank you
t0mi is offline
Dexon
Member
Join Date: Aug 2019
Old 03-20-2023 , 11:14   Re: Refresh hud information when manually change it
Reply With Quote #4

Sure. Here it is with better code and more explanation:
PHP Code:
update_ammo_hud(idiAmmoAmountiBPAmmoAmount)
{
    static 
msgCurWeapon

    
// Display the new antidotegun bullets
    
if(msgCurWeapon || (msgCurWeapon get_user_msgid("CurWeapon"))){ //Set the msg value once
        
if(iAmmoAmount != -1)
        {
            
message_begin(MSG_ONE_UNRELIABLEmsgCurWeapon_id)
            
write_byte(1// active
            
write_byte(CSW_GALIL// weaponID
            
write_byte(iAmmoAmount// clip
            
message_end()
        }
    }
    
    static 
msgAmmoX
    
    
if(msgAmmoX || (msgAmmoX get_user_msgid("AmmoX"))){   
        
// Display the new amount of BPAmmo
        
if(iBPAmmoAmount != -1)
        {
            
message_begin(MSG_ONE_UNRELIABLEmsgAmmoX_id)
            
write_byte(5// ammoid (see: https://wiki.alliedmods.net/Cs_weapons_information -> aid)
            
write_byte(iBPAmmoAmount// ammo amount
            
message_end()
        }
    }

__________________
[ExTasY] Zombie Mutation [ZOMBIE NPC]

Join now!

Video: https://www.youtube.com/watch?v=fNahCsS8DOU&t=328s
DC: https://discord.gg/swARTUZCZ4

Creating private plugins, reference above.

Last edited by Dexon; 03-20-2023 at 11:15.
Dexon is offline
t0mi
Junior Member
Join Date: Jun 2020
Location: Argentina
Old 03-20-2023 , 20:28   Re: Refresh hud information when manually change it
Reply With Quote #5

Quote:
Originally Posted by Dexon View Post
Sure. Here it is with better code and more explanation:
PHP Code:
update_ammo_hud(idiAmmoAmountiBPAmmoAmount)
{
    static 
msgCurWeapon

    
// Display the new antidotegun bullets
    
if(msgCurWeapon || (msgCurWeapon get_user_msgid("CurWeapon"))){ //Set the msg value once
        
if(iAmmoAmount != -1)
        {
            
message_begin(MSG_ONE_UNRELIABLEmsgCurWeapon_id)
            
write_byte(1// active
            
write_byte(CSW_GALIL// weaponID
            
write_byte(iAmmoAmount// clip
            
message_end()
        }
    }
    
    static 
msgAmmoX
    
    
if(msgAmmoX || (msgAmmoX get_user_msgid("AmmoX"))){   
        
// Display the new amount of BPAmmo
        
if(iBPAmmoAmount != -1)
        {
            
message_begin(MSG_ONE_UNRELIABLEmsgAmmoX_id)
            
write_byte(5// ammoid (see: https://wiki.alliedmods.net/Cs_weapons_information -> aid)
            
write_byte(iBPAmmoAmount// ammo amount
            
message_end()
        }
    }

Thanks!
t0mi is offline
Reply



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 08:59.


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