Raised This Month: $12 Target: $400
 3% 

Switch between weapon slots


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 03-03-2018 , 19:01   Switch between weapon slots
Reply With Quote #1

Hello,
So I'm working on a project,
where you can buy 2 automatic guns, instead of one and a pistol..

But I got some wierd WeaponList Hud error,
sometimes weapon doesn't show up there, sometimes it does..

I try'd using Ham_Item_ItemSlot,
but that doesn't update the 'WeaponList'-hud on top..

so I hooked Ham_Item_AddToPlayer, and do it like Arkshine in his Custom Weapons,
but by switching weapons, sometimes an item doesn't show up on the Wepaonlist Hud anymore

Sometimes a M4A1 is Primary, sometimes Secondary, depending on what player 'buys' first,
so I'm looking for a way to get this working.

Code:
public HookItem_postAddToPlayer(const entity, const client)
{
	if(pev_valid(entity) && is_user_alive(client))
	{
		new listArmoury[enumArmarray]
		Armoury_get_array(entity, listArmoury)

		//client_print(0, print_chat, "Add %s to slot %i", g_listWeapon[ listArmoury[ARMARRAY_ARMTYPE] ][ARMOURY_NAME], listArmoury[ARMARRAY_CLIP] )

		client_print(0, print_chat, "Add to player slot %i (-1)", listArmoury[ARMARRAY_CLIP] )

		message_begin( MSG_ONE, g_msgidWeaponList, .player = client)
		{
				write_string( g_listWeapon[ listArmoury[ARMARRAY_ARMTYPE] ][ARMOURY_NAME] );  // WeaponName
				write_byte( 30 );                   // PrimaryAmmoID
				write_byte( 30 );                   // PrimaryAmmoMaxAmount
				write_byte( -1 );                   // SecondaryAmmoID
				write_byte( -1 );                   // SecondaryAmmoMaxAmount
				write_byte( listArmoury[ARMARRAY_CLIP] - 1);                    // SlotID (0...N)
				write_byte( 1 );                    // NumberInSlot (1...N)
				write_byte( g_listWeapon[ listArmoury[ARMARRAY_ARMTYPE] ][ARMOURY_CSW] );            // WeaponID
				write_byte( 0 );                    // Flags
		}
		message_end()
	}


Thanks
__________________
Retired.

Last edited by Xalus; 03-03-2018 at 19:01.
Xalus is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 03-04-2018 , 06:44   Re: Switch between weapon slots
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=175632

Have you read this one?
__________________
My plugin:
Celena Luna is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 03-04-2018 , 11:53   Re: Switch between weapon slots
Reply With Quote #3

Quote:
Originally Posted by Celena Luna View Post
As I said in my post:

"so I hooked Ham_Item_AddToPlayer, and do it like Arkshine in his Custom Weapons,
but by switching weapons, sometimes an item doesn't show up on the Wepaonlist Hud anymore"
__________________
Retired.

Last edited by Xalus; 03-04-2018 at 11:53.
Xalus is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 03-06-2018 , 12:19   Re: Switch between weapon slots
Reply With Quote #4

Let's me analyze the code a bit so I don't get the wrong ideas

PHP Code:
message_beginMSG_ONEg_msgidWeaponList, .player client)
{
    
write_stringg_listWeaponlistArmoury[ARMARRAY_ARMTYPE] ][ARMOURY_NAME] );  // ["weapon_m4a1"] . If it is not fast enough, try to put this on a statis first
    
write_byte30 );                   // All of them get the same type of Ammo?
    
write_byte30 );                   // Ammo Max Amount is 30
    
write_byte( -);                   // Skip
    
write_byte( -);                   // Skip
    
write_bytelistArmoury[ARMARRAY_CLIP] - 1);            // What is this listArmoury contain? It should be 0-Primary;1-Secondary;2-Knife;4-Bomb
    
write_byte);                    // NumberInSlot. Not sure what to do but for M4A1 is 6 not 1.
    
write_byteg_listWeaponlistArmoury[ARMARRAY_ARMTYPE] ][ARMOURY_CSW] );            // [CSW_M4A1] or something like that
    
write_byte);                    // Skip
    
message_end()

For all detail, check this link
https://wiki.alliedmods.net/CS_WeaponList_Message_Dump

Also I prefer using MSG_ONE_UNRELIABLE more than MSG_ONE

PHP Code:
public fw_Item_AddToPlayer_Post(entid)
{
message_begin(MSG_ONE_UNRELIABLEg_MsgWeaponList_id
P/S: Why const enity and const client btw?
__________________
My plugin:

Last edited by Celena Luna; 03-06-2018 at 12:24.
Celena Luna 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 00:04.


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