Raised This Month: $ Target: $400
 0% 

Force Weapon Switch: alternate way?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 02-06-2009 , 16:50   Force Weapon Switch: alternate way?
Reply With Quote #1

Is there any other way to force a player to use a specific weapon, besides:
Code:
engclient_cmd(id, "weapon_knife")
I ask because I'm getting some weird bugs with that sometimes...

Already tried Ham_ItemDeploy but it's probably not meant for that, and it doesn't switch weapons properly.
__________________
MeRcyLeZZ is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-06-2009 , 17:09   Re: Force Weapon Switch: alternate way?
Reply With Quote #2

Maybe should you use Ham_ItemHolster before.

Btw, why engclient_cmd and not client_cmd ?
Arkshine is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 02-06-2009 , 17:24   Re: Force Weapon Switch: alternate way?
Reply With Quote #3

Quote:
Originally Posted by arkshine View Post
Maybe should you use Ham_ItemHolster before.
I'll try that, thanks.

Quote:
Originally Posted by arkshine View Post
Btw, why engclient_cmd and not client_cmd ?
engclient_cmd tells the engine to execute the comand right away (instantly)
client_cmd needs a message to be sent to the player, then the player would send a message back to the server with the command to switch the weapon (not instantly, especially if he has a high latency)
__________________

Last edited by MeRcyLeZZ; 02-07-2009 at 11:14.
MeRcyLeZZ is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-06-2009 , 18:16   Re: Force Weapon Switch: alternate way?
Reply With Quote #4

I tried to set m_pActiveItem (373) before :

Code:
set_pdata_cbase ( id, 373, ActiveWpn ); ExecuteHam ( Ham_Item_Deploy, ActiveWpn );
It works fine for me now. I'm not sure if m_pClientActiveItem (374) is needed, though.
Arkshine is offline
Old 02-07-2009, 15:03
MeRcyLeZZ
This message has been deleted by MeRcyLeZZ. Reason: damn
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 02-07-2009 , 15:05   Re: Force Weapon Switch: alternate way?
Reply With Quote #6

Oh, and for those wondering what problems I had with the engclient_cmd code, test the following script with amx_forceknife set to 1 and 2. Then set your client-side cl_lw cvar to 0 and test again.

Method #1 makes the server crash with "New message started when msg 35 has not been sent yet".
Method #2 results in an additional CurWeapon Event call, but no matching CurWeapon Message pair for it (weird, huh?).

Code:
#include <amxmodx> #include <fakemeta> new cvar_method, g_msgCurWeapon enum {     CVAR_DISABLE = 0, // 0 - disable knife forcing     CVAR_PRE_HOOK, // 1 - force change at pre-hook     CVAR_POST_HOOK // 2 - force change at post-hook } public plugin_init() {     register_plugin("Force Knife", "0.1", "Test")         cvar_method = register_cvar("amx_forceknife", "0")         g_msgCurWeapon = get_user_msgid("CurWeapon")         // CurWeapon Message (pre-hook)     register_message(g_msgCurWeapon, "message_cur_weapon")         // CurWeapon Event (post-hook)     register_event("CurWeapon", "event_cur_weapon", "b") } public message_cur_weapon(msg_id, msg_dest, msg_entity) {     // Player not alive or not an active weapon     if (!is_user_alive(msg_entity) || get_msg_arg_int(1) != 1)         return;         // Get current weapon's id and name     static weapon, wname[32]     weapon = get_msg_arg_int(2)     get_weaponname(weapon, wname, sizeof wname - 1)         // Print some debug info     server_print("[TEST] CurWeapon Message - player %d - weapon %s", msg_entity, wname)         // Check method setting     if (get_pcvar_num(cvar_method) != CVAR_PRE_HOOK)         return;         // Check if holding a knife     if (weapon == CSW_KNIFE)         return;         // If not, force a change     server_print("[TEST] Forcing weapon change...")     engclient_cmd(msg_entity, "weapon_knife") } public event_cur_weapon(id) {     // Player not alive or not an active weapon     if (!is_user_alive(id) || read_data(1) != 1)         return;         // Get current weapon's id and name     static weapon, wname[32]     weapon = read_data(2)     get_weaponname(weapon, wname, sizeof wname - 1)         // Print some debug info     server_print("[TEST] CurWeapon Event - player %d - weapon %s", id, wname)         // Check method setting     if (get_pcvar_num(cvar_method) != CVAR_POST_HOOK)         return;         // Check if holding a knife     if (weapon == CSW_KNIFE)         return;         // If not, force a change     server_print("[TEST] Forcing weapon change...")     engclient_cmd(id, "weapon_knife") }
__________________
MeRcyLeZZ is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 02-07-2009 , 16:33   Re: Force Weapon Switch: alternate way?
Reply With Quote #7

Quote:
set_pdata_cbase ( id, 373, ActiveWpn );
ExecuteHam ( Ham_Item_Deploy, ActiveWpn );
EDIT:
Hold on, this one is also crashing the server when setting cl_lw to 0. Damn it.
__________________
MeRcyLeZZ is offline
Old 02-07-2009, 17:46
Dores
This message has been deleted by Dores. Reason: Oh nvm...
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-07-2009 , 17:55   Re: Force Weapon Switch: alternate way?
Reply With Quote #9

It doesn't matter here Dores, it was just test scripts.
Arkshine is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 02-07-2009 , 22:20   Re: Force Weapon Switch: alternate way?
Reply With Quote #10

seems that when cl_lw 0 it will fire another message SVC_WEAPONANIM
so method 1 will get that error because it's still in hooking msg curweapon
for method 2, I tryied this to remove it
Code:
server_print("[TEST] Forcing weapon change...")
set_msg_block(35, BLOCK_ONCE)
engclient_cmd(id, "weapon_knife")
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
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 01:38.


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