Skip to main content

Overview

commands.lua defines the Commands class and its single entry point Commands:OnPlayerChat(keys). All player-typed commands are routed through this function.

Entry point

Commands:OnPlayerChat(keys)

keys.playerid — the player who typed the message
keys.text — the raw chat string (lowercased before processing)
function Commands:OnPlayerChat(keys)
    local playerID = keys.playerid
    local text     = string.lower(keys.text)

    local command
    local arguments = {}

    for k, v in pairs(util:split(text, " ")) do
        if string.match(v, "-") then
            command = v                              -- dash prefix → command token
        elseif string.match(v, "#") then
            playerID = tonumber(string.sub(v, 2))   -- hash prefix → target player ID
        else
            table.insert(arguments, v)              -- everything else → argument list
        end
    end

    if not command or not playerID then return end
    -- ...
end

Parsing rules

Token prefixMeaningExample
-Command name-gold, -ar, -enablecheat
#Target player ID#3 targets playerID 3
(none)Positional argument500 after -gold sets the amount
You can target another player by including #<playerID> anywhere in the message:
-gold 500 #3
Use -pid first to discover player IDs.

The IsCommand closure

Inside OnPlayerChat, a local closure is created to do prefix-matched command detection:
local function IsCommand(s)
    local len = string.len(s)
    return string.sub(command, 1, len) == s
end
This means -ar matches -antirat and -antirat both match IsCommand("-ar").

Vote commands

Vote commands require a threshold percentage of players to accept before taking effect. They use util:CreateVoting(...) internally.
CommandAliasConditionEffect
-antirat-arantiRat == 0 and cheat mode offEnables anti-rat protection on Tier-3 towers
-doublecreeps-dcneutralMultiply < 2Doubles neutral camp spawns
-enablecheat-ecCheat mode not already onEnables cheat mode for all players
-enablekamikaze-ekAnti-kamikaze activeDisables the kamikaze death penalty
-enablebuilder-ebBuilder not enabledOpens the ingame hero builder
-enablerespawn-erRespawn limit activeFreezes escalating respawn times
-enablefat-efFat-O-Meter offActivates the Fat-O-Meter mechanic
-enablerefreshRefresh-on-death offRefreshes cooldowns on death
-switchteamTeam imbalance or single-playerMoves the player to the other team
Vote thresholds depend on the map:
  • all_allowed map: some votes require only 50 % (e.g. -antirat, -doublecreeps, -enablefat, -enablerefresh)
  • All other maps: 100 % required
Example — anti-rat vote:
if IsCommand("-antirat") or IsCommand("-ar") then
    if OptionManager:GetOption('antiRat') == 0 and not Ingame.voteEnabledCheatMode then
        util:CreateVoting(
            "lodVotingAntirat", playerID, 10,
            OptionManager:GetOption('mapname') == 'all_allowed' and 50 or 100,
            function()
                OptionManager:SetOption('antiRat', 1)
                Ingame:giveAntiRatProtection()
                Ingame.voteAntiRat = true
                EmitGlobalSound("Event.CheatEnabled")
            end
        )
    elseif OptionManager:GetOption('antiRat') == 1 then
        util:DisplayError(playerID, "#antiRatAlreadyOn")
    end
end

Debug commands

Always available regardless of cheat mode:
CommandEffect
-testSends a test message and prints the map name
-fixheroRe-spawns the player’s hero with the correct build (fixes wisp-spawn edge case)
-printabilitiesBroadcasts all of the hero’s current abilities to chat
-pidLists every active player ID and hero name in chat
-fixcastingRemoves and re-adds all talent abilities to fix stuck casting state
-bot modeReports whether bots are in early- or late-game mode
ggPlays the Memes.GG sound when memesRedux is active

Cheat commands

Cheat commands are only available when util:isSinglePlayerMode() is true or Ingame.voteEnabledCheatMode is true.
CommandAliasEffect
-gold [amount]Gives amount gold (default 100 000)
-points [n]Sets hero ability points to n (default 1)
-godToggles modifier_invulnerable
-nofogDisables fog of war
-fogRe-enables fog of war
-aghs-aghanim, -scepterToggles Aghanim’s Scepter consumed modifier
-regenToggles fountain regen aura
-gemToggles true sight aura
-invisToggles permanent invisibility
-dif [level]Sets bot difficulty (1–4)
-reflectToggles spell reflect
-spellblockToggles spell block
-cooldownToggles no-cooldown mode
-globalcastToggles global cast range
-wtf-wtfmenuToggles WTF mode (no cooldowns/mana costs)
-unwtfDisables WTF mode
-lvlup [n]Levels hero up by n (default 1)
-lvlmaxInstantly sets hero to maximum level
-item <name>Gives the named item (e.g. item_blink)
-addability <name>-giveability, -addGives the named ability
-removeability <name>-removeRemoves the named ability (use all to clear)
-daggerGives the dev global-teleport dagger
-dagonGives the dev ultra-dagon
-teleportGives the dev teleport dagger
-startgameForces the game clock to start
-respawnInstantly respawns the hero
-refreshRestores HP/mana and ends all cooldowns
-bot switchToggles bots between early- and late-game AI
-fortifyFortifies all buildings for both teams
-fortify_direToggles fountain regen on all Dire buildings
-fortify_radToggles fountain regen on all Radiant buildings

Build docs developers (and LLMs) love