IMIsle Modkit
Pages in this area

commands

Server

modkit.commands.add

modkit.commands.add(name, fn [, adminOnly]) modkit.commands.add(name, fn, permission)

Registers a command that players run with /name or !name in the chat, or with name in the F8 console of the launcher client.

Parameter Type Description
name string command name without the slash. It is stored in lower case.
fn function fn(player, arg1, arg2, ...). The arguments are the words after the command, all strings.
adminOnly boolean true lets only Steam IDs from sv_admins run it. Others get the answer admin only. Default false.
permission string in place of adminOnly. Only players with this acl permission can run the command. Others get the answer no permission. Players from sv_admins hold every permission.

Returns: nothing.

Behaviour worth knowing.

  • The typed name and the registered name are both lowered, /Heal and /heal are the same command.
  • Registering the same name again in the same resource replaces the old function.
  • Each resource has its own table. With the same name in two resources, the one that was loaded first runs.
  • A line that ran a command is not shown in the chat and is not passed to the game. A line without a matching command is passed on.
  • The same line from the same player within 1.5 seconds runs once.
modkit.commands.add("pos", function(player)
  local x, y, z = player:pos()
  if not x then player:message("You have no dinosaur.") return end
  player:message(string.format("x=%.0f y=%.0f z=%.0f yaw=%.0f", x, y, z, player.yaw))
end)

modkit.commands.add("bring", function(player, steamId)
  local target = steamId and modkit.players.get(steamId)
  if not target then player:message("usage: /bring <steamId>") return end
  local x, y, z = player:pos()
  if x then target:teleport(x, y, z + 150) end
end, true)

modkit.commands.remove

modkit.commands.remove(name)

Removes a command of the calling resource.

Returns: true when the command existed.

modkit.commands.list

modkit.commands.list()

Returns: array of all commands of all resources, as tables with name, resource, adminOnly and permission ("" when none). Handy for a /help command.

modkit.commands.add("help", function(player)
  for _, c in ipairs(modkit.commands.list()) do
    local allowed = c.permission ~= "" and player:hasPermission(c.permission) or (c.permission == "" and (not c.adminOnly or player.admin))
    if allowed then player:message("/" .. c.name) end
  end
end)

See also the chat commands guide.