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

Cmds taking wrong executor's id


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 06-30-2021 , 08:34   Cmds taking wrong executor's id
Reply With Quote #1

Sometimes (very rarely) when i'm starting lan server i can't use about half of custom commands. I'm playing with my brother and when i'm trying to enable noclip (code below) or entering other commands i'm receiving nothing (no messages, no noclip), but my bro is receiving "You have no access" messages in console. Commands runs from his client right as if he will run 'em by himself
Sorry for my bad English
noclip example

Last edited by kww; 06-30-2021 at 09:01.
kww is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 06-30-2021 , 17:06   Re: Cmds taking wrong executor's id
Reply With Quote #2

use register_clcmd()
jimaway is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-30-2021 , 21:57   Re: Cmds taking wrong executor's id
Reply With Quote #3

Are you using HLDS or a listen server (clicking "New Game")?
__________________
fysiks is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 07-01-2021 , 09:17   Re: Cmds taking wrong executor's id
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
Are you using HLDS or a listen server (clicking "New Game")?
listen server

i think no need to use HLDS to play together in one room

Quote:
Originally Posted by jimaway View Post
use register_clcmd()
it have the same behavior
used with bhop. When i'm entering "bh" it toggles bhop not for me but for my brother

Last edited by kww; 07-01-2021 at 10:28.
kww is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-01-2021 , 22:09   Re: Cmds taking wrong executor's id
Reply With Quote #5

Quote:
Originally Posted by kww View Post
listen server
Who is starting the game when this happens?

Quote:
Originally Posted by kww View Post
i think no need to use HLDS to play together in one room
I personally disagree but if you don't have a third computer then you don't have much of a choice (they recommend not running HLDS and the client on the same PC).

Quote:
Originally Posted by kww View Post
it have the same behavior
used with bhop. When i'm entering "bh" it toggles bhop not for me but for my brother
PHP Code:
public plugin_init() {
...
    
register_clcmd("bh""toggle_bhop"ACCESS_USER_)
...
}

public 
toggle_bhop(executorwho) {
    if(!
who)
        
who executor
    
    
if(get_pcvar_num(mp_bhop_ban)) {
        
client_print(whoprint_consoleBHOP_BANNED)
        return 
PLUGIN_HANDLED
    
}
    
    new 
pname[MAX_NAME_LENGTH]
    
get_user_name(whopnamecharsmax(pname))
    
    if(!
g_bhop[who])
        
g_bhop[who] = 1
    
else
        
g_bhop[who] = 0
        
    
new szPrefix[3]
    
szPrefix = (g_bhop[who] == "en" :"dis")
    
    
client_print(whoprint_console"Bhop %sabled"szPrefix)

    new 
pnum get_playersnum()
    for (new 
player 1player pnumplayer++) {
        if(
get_user_flags(player) & ACCESS_ADMIN) {
            
client_print(playerprint_console"[%s] %s (ID:%i) %sabled bh"PLUGIN_NAMEpnamewhoszPrefix)
            
client_print(playerprint_chat"[%s] %s (ID:%i) %sabled bh"PLUGIN_NAMEpnamewhoszPrefix)
        }
    }
    
    return 
PLUGIN_HANDLED

The second argument of the callback for register_clcmd() and register_concmd() is the admin flags requested by the command (the value set in cmdaccess.ini; defaults to the value you provided in the register_*cmd() command). For example, see here.

I suspect that that is messing things up.
__________________

Last edited by fysiks; 07-01-2021 at 22:10. Reason: removed completely unnecessary spoiler tags
fysiks is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 07-02-2021 , 15:51   Re: Cmds taking wrong executor's id
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Who is starting the game when this happens?
Me

Quote:
Originally Posted by fysiks View Post
The second argument of the callback for register_clcmd() and register_concmd() is the admin flags requested by the command (the value set in cmdaccess.ini; defaults to the value you provided in the register_*cmd() command). For example, see here.

I suspect that that is messing things up.
hmm... even if it is, how can it break other commands? btw usually it's working as i expected and very rare this error appears and i must restart the game to fix it ("restart" command isn't helping me)

how i using 2nd argument and idk why it is working then


whole code if you're disappointed

Last edited by kww; 07-02-2021 at 16:09.
kww is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 07-02-2021 , 17:36   Re: Cmds taking wrong executor's id
Reply With Quote #7

it works with bhop command but not with bh?
anyway stop using the inner player id as a command argument. the players have no way to find this information, use something that the players have access to (cmd_target() is a useful native to id players).
you also can't use get_playersnum() to reliably loop through all players in the server since player id's wont always be in order, use get_players() instead.

Last edited by jimaway; 07-02-2021 at 17:42.
jimaway is offline
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
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 07-03-2021 , 07:45   Re: Cmds taking wrong executor's id
Reply With Quote #9

Quote:
Originally Posted by jimaway View Post
it works with bhop command but not with bh?
anyway stop using the inner player id as a command argument. the players have no way to find this information, use something that the players have access to (cmd_target() is a useful native to id players).
you also can't use get_playersnum() to reliably loop through all players in the server since player id's wont always be in order, use get_players() instead.
hmm... first i used "plist" command and it printed all users ids in console, then i used any of provided ids in "bhop toggle" and it worked and i found nothing wrong. but thank you for remark

Quote:
Originally Posted by fysiks View Post
Spoiler
okay. I think i should rework entirely whole plugin because it was my first plugin and i was unexperienced. Thank you for helping and explanation!

Last edited by kww; 07-03-2021 at 07:50.
kww 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 22:28.


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