Basic Command

From GTA Connected
Jump to navigation Jump to search

Description

This code adds a red chat message to the chat box when any player types /text


Code

All examples below do the same thing, in terms of adding the chat message when the command is typed.
Two examples are shown for each supported scripting language, 1 with a global function, 1 with a lambda function. Lambda functions are favoured.
All examples below are server-side code, not client-side code.


JavaScript - Global Function

function textCommand(command, args, client) {
	message('This text is displayed in the chatbox when /text is typed ingame.', COLOUR_RED);
};
addCommandHandler('text', textCommand);


JavaScript - Lambda Function

addCommandHandler('text', function(command, args, client) {
	message('This text is displayed in the chatbox when /text is typed ingame.', COLOUR_RED);
});


Squirrel - Global Function

function textCommand(command, args, client) {
	message('This text is displayed in the chatbox when /text is typed ingame.', COLOUR_RED);
};
addCommandHandler('text', textCommand);


Squirrel - Lambda Function

addCommandHandler('text', function(command, args, client) {
	message('This text is displayed in the chatbox when /text is typed ingame.', COLOUR_RED);
});


Lua - Global Function

function textCommand(command, args, client)
	message('This text is displayed in the chatbox when /text is typed ingame.', COLOUR_RED)
end
addCommandHandler('text', textCommand)


Lua - Lambda Function

addCommandHandler('text', function(command, args, client)
	message('This text is displayed in the chatbox when /text is typed ingame.', COLOUR_RED)
end)


Notes

The code uses addCommandHandler, which is a shared function, shared means that the functionality is available both server-side and client-side.
The code uses COLOUR_RED which is a server define, see Server Colour Defines.