-
Notifications
You must be signed in to change notification settings - Fork 149
Registering Custom Chat Commands
Commands are registered with CBA_fnc_registerChatCommand
.
Parameters:
_command - Chat command <STRING>
_code - Code to execute after command was entered. <CODE>
_availableFor - "all", "admin" or "adminLogged" (optional, default: "admin") <STRING>
The function has local effects and has to be executed on every machine (e.g. postInit or init.sqf). The function should be executed everywhere, even if the chat command is meant to be available to admins only. Restrictions are checked when the command was entered. Chat commands are case insensitive and not cross-compatible with serverCommand
or serverCommandAvailable
.
The code block is executed locally on the machine where the registered chat command was entered. The chat command is registered without the leading #, but when used ingame the command has to be prefixed with #.
Example:
registered command:
customCommand
usage:
#customCommand argument
"argument"
is passed as STRING inside the _this
variable ARRAY.
Chat commands cannot be unregistered, but the same command can be overwritten with an empty function ({}
) by using CBA_fnc_registerChatCommand
again if necessary.
Depending on the third parameter of CBA_fnc_registerChatCommand
, the chat command can only be executed by:
- "admin": Voted or logged in admins (default)
- "adminLogged": Logged in admins only
- "all": Everyone
The restriction is checked every time after the chat command was entered. A local hosted MP client is treated as logged in admin.
["hint", {
hint (_this select 0);
}, "all"] call CBA_fnc_registerChatCommand;
Usage:
#hint hello world
["skipTime", {
parseNumber (_this select 0) remoteExec ["skipTime"];
}, "admin"] call CBA_fnc_registerChatCommand;
Usage:
#skipTime 6
["kill", {
params ["_name"];
// pick unit that matches given name
// reports null when no or more than one unit was found
private _fnc_findMatch = {
params ["_name"];
private _matches = [];
{
if ([_name, name _x] call BIS_fnc_inString) then {
_matches pushBack _x;
};
} forEach ([] call CBA_fnc_players);
if (count _matches == 1) exitWith {_matches select 0};
objNull
};
private _unit = _name call _fnc_findMatch;
_unit setDamage 1;
}, "adminLogged"] call CBA_fnc_registerChatCommand;
Usage:
#kill commy
-> kills "Gefr. commy2"