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
//command handling
public fun_main(id) {
new arg[17]
read_argv(1, arg, charsmax(arg))
if (!arg[0]) client_print(id, print_console, "[%s] %s", PLUGIN_NAME, MESSAGE[FUN_USAGE])
else if (equali(arg, "noclip")) toggle_noclip(id)
else if (equali(arg, "god")) toggle_godmode(id) //not included here but it works as toggle_noclip
return PLUGIN_HANDLED
}
public toggle_noclip(id) {
if(get_user_flags(id) & ACCESS_ADMIN) {
if(is_user_alive(id)) {
new x = get_user_noclip(id)
set_user_noclip(id, x == 0 ? 1 : 0)
client_print(id, print_console, "Noclip %s", x == 0 ? "ON" : "OFF")
}
else client_print(id, print_console, "[%s] %s", PLUGIN_NAME, MESSAGE[DEAD_NOW])
}
else client_print(id, print_console, "[%s] %s", PLUGIN_NAME, MESSAGE[NO_ACCESS])
}
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
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(executor, who) { if(!who) who = executor
new pnum = get_playersnum() for (new player = 1; player < pnum; player++) { if(get_user_flags(player) & ACCESS_ADMIN) { client_print(player, print_console, "[%s] %s (ID:%i) %sabled bh", PLUGIN_NAME, pname, who, szPrefix) client_print(player, print_chat, "[%s] %s (ID:%i) %sabled bh", PLUGIN_NAME, pname, who, szPrefix) } }
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.
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
// handling
public bhop_main(id) {
new arg[17], arg2[17]
read_argv(1, arg, charsmax(arg))
read_argv(2, arg2, charsmax(arg2))
if (!arg[0]) client_print(id, print_console, BHOP2_USAGE)
else if (equali(arg, "toggle")) {
// syntax: bhop toggle [id]
new iArg2 = str_to_num(arg2)
// if player id is not specified
if(!arg2[0]) {
toggle_bhop(id, 0)
return PLUGIN_HANDLED
}
// if player id is wrong
else if(IsPlayer(iArg2)) {
client_print(id, print_console, INVALID_ID)
return PLUGIN_HANDLED
}
// if player id is correct
else {
toggle_bhop(id, iArg2)
}
}
else if (equali(arg, "autojump")) {
// syntax: bhop autojump [1|0]
switch(arg2[0])
{
case EOS: client_print(id, print_console, "%s", BHOP2_AJ_USAGE, g_autojump[id])
case '0': g_autojump[id] = 0
default: g_autojump[id] = 1
}
return PLUGIN_HANDLED
}
new const NO_ACCESS[] = "* You have no access to that command!"
new const INVALID_ID[] = "* You have entered invalid ID!"
new const BHOP_BANNED[] = "* This command is banned by admin!"
new const BHOP2_USAGE[] = "* Usage: bhop <toggle [playerid]|autojump|list>"
new const BHOP2_AJ_USAGE[] = "* Usage: bhop autojump <1|0> (now %i)"
new g_bhop[MAX_PLAYERS + 1], g_autojump[MAX_PLAYERS + 1]
new mp_bhop_ban
public plugin_init() {
register_plugin(PLUGIN_NAME, "latest", "kww")
register_clcmd("bh", "toggle_bhop", ACCESS_USER, _) //just an alias for "bhop toggle"
}
public client_putinserver(id) {
g_bhop[id] = 0 //bhop disabled by default
g_autojump[id] = 1 //autojump enabled by default
}
public xbhop_main(id) {
new arg[17], arg2[17]
read_argv(1, arg, charsmax(arg))
read_argv(2, arg2, charsmax(arg2))
if (!arg[0]) client_print(id, print_console, BHOP2_USAGE)
else if (equali(arg, "toggle")) {
new iArg2 = str_to_num(arg2)
// if player id is not specified
if(!arg2[0]) {
toggle_bhop(id, 0)
return PLUGIN_HANDLED
}
// if player id is wrong
else if(!IsPlayer(iArg2)) {
client_print(id, print_console, INVALID_ID)
return PLUGIN_HANDLED
}
// if player id is correct
else {
toggle_bhop(id, iArg2)
}
}
else if (equali(arg, "autojump")) {
switch(arg2[0])
{
case EOS: client_print(id, print_console, "%s", BHOP2_AJ_USAGE, g_autojump[id])
case '0': g_autojump[id] = 0
default: g_autojump[id] = 1
}
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public toggle_bhop(executor, who) {
if(!who)
who = executor
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... 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().
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
Spoiler
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().
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!