AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Force Weapon Switch: alternate way? (https://forums.alliedmods.net/showthread.php?t=85161)

MeRcyLeZZ 02-06-2009 16:50

Force Weapon Switch: alternate way?
 
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.

Arkshine 02-06-2009 17:09

Re: Force Weapon Switch: alternate way?
 
Maybe should you use Ham_ItemHolster before.

Btw, why engclient_cmd and not client_cmd ?

MeRcyLeZZ 02-06-2009 17:24

Re: Force Weapon Switch: alternate way?
 
Quote:

Originally Posted by arkshine (Post 757027)
Maybe should you use Ham_ItemHolster before.

I'll try that, thanks.

Quote:

Originally Posted by arkshine (Post 757027)
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)

Arkshine 02-06-2009 18:16

Re: Force Weapon Switch: alternate way?
 
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.

MeRcyLeZZ 02-07-2009 15:05

Re: Force Weapon Switch: alternate way?
 
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 02-07-2009 16:33

Re: Force Weapon Switch: alternate way?
 
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.

Arkshine 02-07-2009 17:55

Re: Force Weapon Switch: alternate way?
 
It doesn't matter here Dores, it was just test scripts.

jim_yang 02-07-2009 22:20

Re: Force Weapon Switch: alternate way?
 
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")


MeRcyLeZZ 02-08-2009 10:52

Re: Force Weapon Switch: alternate way?
 
Quote:

Originally Posted by jim_yang
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

Right, thanks for the explanation.

I still don't know what's up with method #2, take a look at this console dump:
Code:

] amx_forceknife 2
] cl_lw 0
] weapon_usp
[TEST] CurWeapon Message - player 1 - weapon weapon_usp
[TEST] CurWeapon Event - player 1 - weapon weapon_usp
[TEST] Forcing weapon change...
[TEST] CurWeapon Event - player 1 - weapon weapon_usp
[TEST] Forcing weapon change...

I attempted to change my weapon only once, still a second CurWeapon Event was called out of nowhere. Is that a bug in AMXX's event system or what? I didn't have any other plugins running besides the test script...

Quote:

Originally Posted by jim_yang
I tryied this to remove it
Code:

server_print("[TEST] Forcing weapon change...")
set_msg_block(35, BLOCK_ONCE)
engclient_cmd(id, "weapon_knife")


Alright, tested that...
For Method #1 I'm now getting kicked out with SVC_BAD when I switch weapons...
For method #2 it's still triggering an additional CurWeapon event out of nowhere.

ConnorMcLeod 02-08-2009 11:37

Re: Force Weapon Switch: alternate way?
 
Register your event with arg 1 = 1 ( "1=1 ), means the weapon is active.


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

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