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

Quote:
Originally Posted by Hunter-Digital View Post
eh ... ?


I got from your example... and what's with "user_" there ? the function is user_kill()

You can use [php]code here[/php] or [code]code here[/code] to post code.

And in your code, the user_health(target) function doesn't exist, use set_user_health() and get_user_health().
So yeah, this is what i got, what would i add?

Code:
#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
        {
            set_user_health // 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
}
Kurosaki12341 is offline