Donut Team is a labor of love, built and maintained by a small group of passionate developers. We invest our own time and resources to offer our tools, mods, and web services completely free of charge.

We don't run ads, and we will never sell your data - period.

If you've enjoyed anything we've created, please consider supporting our work with a one-time or monthly donation via our Ko-fi page . Every contribution helps us continue building great experiences for the community.

Dismiss
  • Modding Tools
  • Simpsons Hit & Run Multiplayer Server
  • Lua API Reference
  • Server Functions
  • Server.Commands Functions

Server.Commands.Register

Available since Version 1.0.

Adds a new chat command that players can use in the game chat. When a player types the command in chat, the provided callback function will be called with the player who sent the command and any arguments they provided.

Syntax

Server.Commands.Register( name, minimumArgs, maximumArgs, usage, callback )

Arguments

  • name (string): The name of the command. This is the word that players will type in chat to use the command, without the leading slash.
  • minimumArgs (number): The minimum number of arguments required for the command. If a player tries to use the command with fewer arguments than this, they will receive an error message.
  • maximumArgs (number): The maximum number of arguments allowed for the command. If a player tries to use the command with more arguments than this, they will receive an error message.
  • usage (string): A string describing how to use the command. This will be shown to players if they use the command incorrectly (e.g. with the wrong number of arguments).
  • callback (function): The function to call when the command is used. This function will be passed the following arguments:
    • player (Player): The player who sent the command.
    • args (table): A table of the arguments provided by the player, where args[1] is the first argument, args[2] is the second argument, and so on.
    • argsN (number): The total number of arguments provided by the player.

Return Values

No return values.

Examples

Server.Commands.Register("hide", 0, 0, "/hide",
function (player, args, argsN)
    player.Character.HasRadarIcon = not player.Character.HasRadarIcon
    player.Character.HasNameTag = not player.Character.HasNameTag
    player.Character.HasFullScreenMapIcon = not player.Character.HasFullScreenMapIcon
    player:SendGameChatMessage("Your radar icon and name tag are now " .. (player.Character.HasRadarIcon and "visible" or "hidden"))
end)