Senior Member
Join Date: Feb 2021
Location: Russia
|
07-02-2021
, 15:51
Re: Cmds taking wrong executor's id
|
#6
|
Quote:
Originally Posted by fysiks
Who is starting the game when this happens?
|
Me
Quote:
Originally Posted by fysiks
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
PHP Code:
// registering
register_concmd("bhop", "bhop_main", ACCESS_USER, _)
// 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
}
return PLUGIN_HANDLED
}
whole code if you're disappointed
WARNING! shitcoding
PHP Code:
#include <amxmodx>
#include <engine>
#include <fun>
#include <hamsandwich>
#include "_kww_main.inc"
#include <screenfade_util>
#define IsPlayer(%1) (1 <= %1 <= 32)
#define FL_WATERJUMP (1<<11)
#define FL_ONGROUND (1<<9)
#define ACCESS_USER ADMIN_ALL
#define ACCESS_ADMIN ADMIN_KICK
#define MAX_NAME_LENGTH 32
#define MAX_PLAYERS 32
#define PLUGIN_NAME "shitty coding"
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")
mp_bhop_ban = register_cvar("mp_bhop_ban", "0", FCVAR_SERVER)
RegisterHam(Ham_Player_Jump, "player", "onPlayerJump")
register_concmd("bhop", "xbhop_main", ACCESS_USER, _)
register_concmd("plist", "showListBhop", ACCESS_ADMIN, _)
register_concmd("plist2", "showListBhop2", ACCESS_ADMIN, _)
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
if(get_pcvar_num(mp_bhop_ban)) {
client_print(who, print_console, BHOP_BANNED)
return PLUGIN_HANDLED
}
new pname[MAX_NAME_LENGTH]
get_user_name(who, pname, charsmax(pname))
if(!g_bhop[who])
g_bhop[who] = 1
else
g_bhop[who] = 0
new szPrefix[3]
szPrefix = (g_bhop[who] == 1 ? "en" :"dis")
client_print(who, print_console, "Bhop %sabled", szPrefix)
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
}
public showListBhop(id) {
if(!(get_user_flags(id) & ACCESS_ADMIN)) {
client_print(id, print_console, NO_ACCESS)
return PLUGIN_HANDLED
}
client_print(id, print_console, "///---------Players list---------///^nID | Player name | Bhop state")
new players[32], playerCount, player
new playername[MAX_NAME_LENGTH]
get_players(players, playerCount)
for(new i = 0; i < playerCount; i++) {
player = players[i]
get_user_name(player, playername, charsmax(playername))
client_print(id, print_console, " %i | %s | %i", player, playername, g_bhop[player])
}
return PLUGIN_HANDLED
}
public onPlayerJump(id) {
if(get_pcvar_num(mp_bhop_ban)) {
g_bhop[id] = 0
return PLUGIN_HANDLED
}
if(g_bhop[id] == 1) {
new iFlags
entity_set_float(id, EV_FL_fuser2, 0.0)
iFlags = entity_get_int(id, EV_INT_flags)
if (!(iFlags & FL_WATERJUMP) && (iFlags & FL_ONGROUND) && (entity_get_int(id, EV_INT_waterlevel) < 2)) {
if (g_autojump[id] == 1) {
new Float:fVelocity[3]
entity_get_vector(id, EV_VEC_velocity, fVelocity)
fVelocity[2] += 250.0
entity_set_vector(id, EV_VEC_velocity, fVelocity)
}
}
entity_set_int(id, EV_INT_gaitsequence, 6)
}
return HAM_IGNORED
}
Last edited by kww; 07-02-2021 at 16:09.
|
|