[NodeMod Core]
/ .. / default
Class: default
Defined in: src/core/cmd.ts:94
Command manager for handling both client and server commands in the nodemod plugin system.
Example
// Register a client command
nodemodCore.cmd.add({
name\: 'hello',
type\: 'client',
handler\: (ctx) => {
console.log(`Hello ${ctx.client.name}!`);
}
});
// Register a server command
nodemodCore.cmd.add({
name\: 'restart',
type\: 'server',
handler\: () => {
console.log('Server restarting...');
}
});
Constructors
Constructor
new default():
NodemodCmd
Defined in: src/core/cmd.ts:144
Creates a new NodemodCmd instance and sets up command event listeners. Automatically handles client command events from the nodemod system.
Returns
NodemodCmd
Properties
commands
privatecommands:CommandOptions[] =[]
Defined in: src/core/cmd.ts:96
Array of registered commands
Methods
parseCommand()
privateparseCommand(command):string[]
Defined in: src/core/cmd.ts:110
Parses a command string into an array of arguments, respecting quoted strings.
Parameters
command
string
The raw command string to parse
Returns
string[]
Array of parsed arguments
Example
parseCommand('say "hello world" test') // Returns\: ['say', 'hello world', 'test']
parseCommand('kick player reason') // Returns\: ['kick', 'player', 'reason']
getCommand()
getCommand(
commandName,type):CommandOptions|undefined
Defined in: src/core/cmd.ts:173
Retrieves a registered command by name and type.
Parameters
commandName
string
The name of the command to find
type
string
The type of command ('client' or 'server')
Returns
CommandOptions | undefined
The command options if found, undefined otherwise
add()
add(
options):void
Defined in: src/core/cmd.ts:204
Adds a new command to the command registry. For server commands, automatically registers them with the native engine.
Parameters
options
Command configuration options
Returns
void
Example
// Client command
nodemodCore.cmd.add({
name\: 'info',
type\: 'client',
handler\: (ctx) => {
console.log(`Player\: ${ctx.client.name}, Args\: ${ctx.args.join(' ')}`);
}
});
// Server command
nodemodCore.cmd.add({
name\: 'status',
type\: 'server',
handler\: () => {
console.log('Server is running');
}
});
register()
register(
name,handler):void
Defined in: src/core/cmd.ts:266
Convenience method to register a console command that works from both client and server. Similar to AMXX console commands - can be executed by clients or from server console. The handler receives the client (null if from console) and arguments.
Parameters
name
string
The command name
handler
(client, args) => void
Function that receives the client entity (or null) and arguments
Returns
void
Example
nodemodCore.cmd.register('status', (client, args) => {
if (client) {
console.log(`Client ${client.name} requested status`);
} else {
console.log('Server console requested status');
}
});
registerClient()
registerClient(
name,handler):void
Defined in: src/core/cmd.ts:290
Convenience method to register a client-only command with a simplified handler signature. The handler receives the client entity and arguments (excluding the command name).
Parameters
name
string
The command name
handler
(client, args) => void
Function that receives the client and arguments
Returns
void
Example
nodemodCore.cmd.registerClient('kick', (client, args) => {
const targetName = args[0];
const reason = args.slice(1).join(' ');
console.log(`${client.name} wants to kick ${targetName}\: ${reason}`);
});
registerServer()
registerServer(
name,handler):void
Defined in: src/core/cmd.ts:314
Convenience method to register a server command with a simplified handler signature. The handler receives the arguments (excluding the command name) but no client entity.
Parameters
name
string
The command name
handler
(args) => void
Function that receives the command arguments
Returns
void
Example
nodemodCore.cmd.registerServer('ban', (args) => {
const playerId = args[0];
const duration = args[1] || '0';
console.log(`Banning player ${playerId} for ${duration} minutes`);
});
run()
run(
command):void
Defined in: src/core/cmd.ts:336
Executes a server command through the native engine. Automatically appends a newline character to the command.
Parameters
command
string
The server command to execute
Returns
void
Example
nodemodCore.cmd.run('changelevel de_dust2');
nodemodCore.cmd.run('kick "Player Name"');
nodemodCore.cmd.run('say "Server announcement"');