Thread: ! commands
View Single Post
Kurosaki12341
Junior Member
Join Date: Aug 2010
Old 08-30-2011 , 08:22   Re: ! commands
Reply With Quote #6

#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
// other stuff here like register_plugin()

register_clcmd("say", "cmd_say") // hook the "say" command with "cmd_say" callback
}

public cmd_say(id, level, cid) // the callback for "say" command"
{
new szCmd[24] // a 24-cell array for the command string (argument 1)

read_argv(1, szCmd, charsmax(szCmd)) // argument 1 assigned to szCmd, charsmax() is sizeof szCmd - 1, meaning 23, but it's good to use charsmax() instead of hardcoded sizes.

if(equali(szCmd, "!heal")) // check if it's "!slay" (case insensitive, equal() is case sensitive)
{
if(!(get_user_flags(id) & ADMIN_SLAY)) // a simple way to check if admin doesn't have a specific access flag
{
client_print(id, print_chat, "You don't have access to that command") // print a message

return PLUGIN_HANDLED // block the command from showing in chat
}

new szTarget[32] // a 32-cell array for the target player (argument 2)

read_argv(2, szTarget, charsmax(szTarget)) // argument 2 assigned to szTarget

new target = cmd_target(id, szTarget, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF) // create variable target and find a player with the string in szTarget, the 3rd argument are flags for what players to find... this one doesn't return immune players and allows you to specify your own name.

if(target > 0) // checks if player is 1 or more, that means cmd_target() found a valid player
{
user_health(target) // heals the target player

new szName[32] // string for a name

get_user_name(id, szName, charsmax(szName)) // get the admin name

client_print(target, print_chat, "You've been healed by %d", szName) // print a message to the healed target

return PLUGIN_HANDLED // returning this blocks the command, so it won't show you saying "!heal player" that in chat.
}
}

return PLUGIN_CONTINUE // if the say message isn't a command, just leave it alone
}


Is what i got, i copied most from yours so of course i'd do shit wrong, but please help

EDIT: How did you make it so you put the code in the "PHP CODE:" thing? and white background
Kurosaki12341 is offline