Error: I get no errors, but I get a 0kb output file, and/or the compiler crashes
Solution: Somewhere in your code, you forgot to close something. This is usually caused by forgetting to put a " at the end of text, but it can also be caused by forgetting a ) or }
Error: warning 202: number of arguments does not match defintion
Solution: On the line it says, you don't have enough paramaters. You forgot to put something in, and the compiler noticed. Just go to that line, compare the command you used to the one in the include file. It might be something as simple as you put a period instead of comma.
Error: error 035: argument type mismatch (argument X)
Solution: One of your arguments is the wrong type. This usually happens when the command is expecting a float, and you gave it an integer (I didn't go over floats here, they can be annoying). Or it could be the command expected a string, and you gave it an integer.
Let's start off with how to get some arguments from the commandline. We will create a basic amx_kick plugin.
Here's the code for it, I will explain it after.
Code: Select all
#include <amxmodx>
public plugin_init() {
register_plugin("Amx-Kick","0.1","devicenull")
register_concmd("amx_kick2","do_kick",ADMIN_KICK," user Kicks the specified user")
}
public do_kick(id) {
if (!(get_user_flags(id)&ADMIN_KICK)) {
console_print(id,"[AMXX] No access")
return PLUGIN_HANDLED
}
if (read_argc() == 0) {
console_print(id,"[AMXX] You must specify a user")
return PLUGIN_HANDLED
}
new user[32], uid
read_argv(1,user,32)
uid = find_player("bh",user)
if (uid == 0) {
console_print(id,"[AMXX] Invalid User Id")
return PLUGIN_HANDLED
}
client_cmd(uid,"echo Kicked from server!")
client_cmd(uid,"disconnect")
console_print(id,"Kicked player!")
return PLUGIN_HANDLED
}Code: Select all
#include <amxmodx>Code: Select all
public plugin_init() {
register_plugin("Amx-Kick","0.1","devicenull")
register_concmd("amx_kick2","do_kick",ADMIN_KICK," user Kicks the specified user")
}Next, in register_concmd, I tell AmxX that I am creating a new command called "amx_kick2", that it should call "do_kick" when a client uses this command. It also specifys the access level needed (ADMIN_KICK) and the help for the command. You almost always have several of these, and there are different types:
register_srvcmd() - This is used for commands that are only done in the server console (And over RCON)
register_clcmd() - This is used for commands that are only done on clients
register_concmd() - This is used for commands that can be done anywhere
Code: Select all
public do_kick(id) {Code: Select all
if (!(get_user_flags(id)&ADMIN_KICK)) {
console_print(id,"[AMXX] No access")
return PLUGIN_HANDLED
}Code: Select all
if (read_argc() == 0) {
console_print(id,"[AMXX] You must specify a user")
return PLUGIN_HANDLED
}Code: Select all
new user[32], uidCode: Select all
read_argv(1,user,32)Code: Select all
uid = find_player("bh",user)Code: Select all
if (uid == 0) {
console_print(id,"[AMXX] Invalid User Id")
return PLUGIN_HANDLED
}Code: Select all
client_cmd(uid,"echo Kicked from server!")
client_cmd(uid,"disconnect")Code: Select all
console_print(id,"Kicked player!")Code: Select all
return PLUGIN_HANDLED
}A note, the "return PLUGIN_HANDLED" prevents Half life from displaying "Command not found".
