CommandHelper

CommandHelper

46.5k Downloads

A way to add aliases from a function.

LadyCailinBot opened this issue ยท 7 comments

commented

CMDHELPER-3058 - Reported by Hazae41

For example:
/bind = >>>
add_alias(
/whatsup = >>>
broadcast('Whats up?')
<<<
)
<<<

commented

Comment by Hazae41

Or a way to include commands from a file.

commented

Comment by LadyCailin

This is already possible. register_command() is the function you're looking for.

commented

Comment by PseudoKnight

For dynamic commands you can also bind player_command. It depends on what you're doing.

commented

Comment by Hazae41

@LadyCailin How to do my example using register_command() ?

commented

Comment by PseudoKnight

Here's an example:

/bind = >>>
    register_command('whatsup', array(
        'description': 'Broadcasts "Whats up?"',
        'executor': closure(){ 
            broadcast('Whats up?') 
        }
    ));
<<<
commented

Comment by Hazae41

and if I want to do:

    add_alias(
        /whatsup [$player] = >>>
            if($player == '',
                broadcast('Whats up?')
            ,
                tmsg($player, 'Whats up?')
            )
        <<<
    )
<<<```
commented

Comment by PseudoKnight

This series of questions could be endless. I'd suggest you look at the register_command() docs and infer from here.

/bind = >>>
    register_command('whatsup', array(
        'description': 'Broadcasts "Whats up?"',
        'executor': closure(@alias, @sender, @args, @info) {
            if(array_size(@args) < 1) {
                broadcast('Whats up?');
            } else {
                tmsg(@args[0], 'Whats up?');
            }
        }
    ));
<<<