View Single Post
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-02-2021 , 23:38   Re: Cmds taking wrong executor's id
Reply With Quote #8

Quote:
Originally Posted by kww View Post
hmm... even if it is, how can it break other commands?
Indeed, not really sure then. But, if we have a command that causes it reliable, we can use that for debugging but you'll need to fix all the errors in the code for that command to make sure that it's not just a mistake in the code.


If we start with the "bh" client command (which I believe you're saying has the issue) then we need to fix it up first. Since toggle_bhop() is designed to work as a function call from other functions and not hooks, we'll need to make a middleman function:

Code:
public toggle_bhop_clcmd(id)
{
	toggle_bhop(id, id)
}
Then use "toggle_bhop_clcmd" in you regsiter_clcmd() for "bh". You could even add to that to take in an argument that would be your target like this:

Code:
public toggle_bhop_clcmd(id)
{
	new szArg[32]
	read_argv(1, szArg, charsmax(szArg))

	new player = cmd_target(id, szArg, CMDTARGET_ALLOW_SELF)
	
	if( player )
	{
		toggle_bhop(id, player)
	}
}
which allows you to test it more thoroughly being able to select which of you to use the command on. Test using it on yourself (e.g. "bh fysiks") and someone else. If after these fixes it still doesn't work then we will add debug messages to it. I would probably start with adding debug messages to this new function like printing the values of "id" and "player" probably with client_print(0, print_console, "...") to see if the values are what you would normally expect.




P.S. It is not correct to use client_print() in a function that is called by a hook that is registered with register_concmd(). You must use console_print(). client_print() should be used in hooks registered by register_clcmd().
__________________
fysiks is offline