AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cmds taking wrong executor's id (https://forums.alliedmods.net/showthread.php?t=333298)

kww 06-30-2021 08:34

Cmds taking wrong executor's id
 
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

jimaway 06-30-2021 17:06

Re: Cmds taking wrong executor's id
 
use register_clcmd()

fysiks 06-30-2021 21:57

Re: Cmds taking wrong executor's id
 
Are you using HLDS or a listen server (clicking "New Game")?

kww 07-01-2021 09:17

Re: Cmds taking wrong executor's id
 
Quote:

Originally Posted by fysiks (Post 2751637)
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 (Post 2751624)
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

fysiks 07-01-2021 22:09

Re: Cmds taking wrong executor's id
 
Quote:

Originally Posted by kww (Post 2751661)
listen server

Who is starting the game when this happens?

Quote:

Originally Posted by kww (Post 2751661)
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 (Post 2751661)
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.

kww 07-02-2021 15:51

Re: Cmds taking wrong executor's id
 
Quote:

Originally Posted by fysiks (Post 2751690)
Who is starting the game when this happens?

Me

Quote:

Originally Posted by fysiks (Post 2751690)
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

jimaway 07-02-2021 17:36

Re: Cmds taking wrong executor's id
 
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.

fysiks 07-02-2021 23:38

Re: Cmds taking wrong executor's id
 
Quote:

Originally Posted by kww (Post 2751739)
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().

kww 07-03-2021 07:45

Re: Cmds taking wrong executor's id
 
Quote:

Originally Posted by jimaway (Post 2751744)
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 (Post 2751752)
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!


All times are GMT -4. The time now is 02:34.

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