The command global allows you to register custom commands that can be executed from the game client. Commands are executed with a configurable prefix (default: /).
Function to execute when command is called. Must return true on success, false on failure.
command.register("say", "Echo a message", function(ctx) if #ctx.args < 1 then ctx:reply("Usage: /say <message>") return false end local message = table.concat(ctx.args, " ") logger.info(message) return trueend)
command.register("say", "Echo a message to the client", function(ctx) if #ctx.args < 1 then ctx:reply("Usage: /say <message>") return false end local message = table.concat(ctx.args, " ") local log = LogPacket.new() log.msg = message send.to_client(log) return trueend)
command.register("pos", "Show your current position", function(ctx) local player = world:get_local_player() if not player then ctx:reply("`4Error: ``Not in a world") return false end ctx:reply("`2Position: ``({}, {})", player.position.x, player.position.y) return trueend)
command.register("item", "Get item information", function(ctx) if #ctx.args < 1 then ctx:reply("`4Usage: ``/item <item_id>") return false end local item_id = tonumber(ctx.args[1]) if not item_id then ctx:reply("`4Error: ``Invalid item ID") return false end local item = item_database:get_item(item_id) if item then ctx:reply("`2Item {}: ``{}", item.item_id, item.item_name) ctx:reply("`2Type: ``{}, `2Rarity: ``{}", item.item_type, item.rarity) else ctx:reply("`4Error: ``Item not found") end return trueend)
command.register("help", "List all commands", function(ctx) local commands = command.list() local prefix = command.get_prefix() ctx:reply("`2Available Commands:") for name, description in pairs(commands) do ctx:reply("`2{}{} ``- {}", prefix, name, description or "No description") end return trueend)
command.register("tp", "Teleport to coordinates", function(ctx) if #ctx.args < 2 then ctx:reply("`4Usage: ``/tp <x> <y>") return false end local x = tonumber(ctx.args[1]) local y = tonumber(ctx.args[2]) if not x or not y then ctx:reply("`4Error: ``Invalid coordinates") return false end local player = world:get_local_player() if not player then ctx:reply("`4Error: ``Not in a world") return false end -- Send teleport packet local pkt = GamePacket.new() pkt.type = packet.PacketType.PACKET_STATE pkt.net_id = player.net_id pkt.pos_x = x pkt.pos_y = y send.to_server(pkt) ctx:reply("`2Teleporting to ``({}, {})", x, y) return trueend)
command.register("worldinfo", "Display world information", function(ctx) local local_player = world:get_local_player() if not local_player then ctx:reply("`4Error: ``Not in a world") return false end local players = world:get_players() local player_count = 0 for _ in pairs(players) do player_count = player_count + 1 end ctx:reply("`2World Information:") ctx:reply("`2Players: ``{}", player_count) ctx:reply("`2Version: ``{}", world:get_version()) return trueend)
command.register("greet", "Greet the player", function(ctx) local player = world:get_local_player() if player then ctx:reply("`2Hello, ``{}!`2 Welcome to GTProxy!", player.name) else ctx:reply("`2Hello! ``Welcome to GTProxy!") end return trueend)
command.register("example", function(ctx) if #ctx.args < 1 then ctx:reply("Usage: /example <arg>") return false end -- Safe to use ctx.args[1] return trueend)