• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Lua] Simplest detection of Warcraft cheat codes for a single player

Lua:
function InitEditBoxAnalyzer()
    local states = {"", ""}
   
    local cheatsTable = { -- Table of known cheat codes in Warcraft 3
    "warpten",
    "whosyourdaddy",
    "keysersoze",
    "leafittome",
    "greedisgood",
    "pointbreak",
    "thereisnospoon",
    "somebodysetupusthebomb",
    "allyourbasearebelongtous",
    "whoisjohngalt",
    "sharpandshiny",
    "iseedeadpeople"
    }
   
    local textChangedTrigger = CreateTrigger()
    local textEnterTrigger = CreateTrigger()

    local function Punishment()
        -- You can add any reaction to entering a cheat code to this function
        -- In this example, the player gets defeat
        CustomDefeatBJ(GetLocalPlayer(), "Good luck next time!")
    end

    local function IfEditBoxContentEntered()
        for i = 1, #cheatsTable do
            if string.find(string.lower(states[2]), cheatsTable[i]) then
                Punishment()
                break
            end  
        end
    end

    local function IfEditBoxContentChanged()
        states[2] = states[1]
        states[1] = BlzGetTriggerFrameText()
    end

    local t = CreateTimer()
    -- Accessing to the frame while the map is initializing can result in a fatal error, so delay is needed
   
    TimerStart(t, 0.05, false, function()
        local frameGameUI = BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)
        local frameInputBox = BlzFrameGetChild(frameGameUI, 11)
        local frameEditBox = BlzFrameGetChild(frameInputBox, 1)

        BlzTriggerRegisterFrameEvent(textChangedTrigger, frameEditBox, FRAMEEVENT_EDITBOX_TEXT_CHANGED)
        BlzTriggerRegisterFrameEvent(textEnterTrigger, frameEditBox, FRAMEEVENT_EDITBOX_ENTER)
        TriggerAddCondition(textChangedTrigger, Condition(IfEditBoxContentChanged))
        TriggerAddCondition(textEnterTrigger, Condition(IfEditBoxContentEntered))
    DestroyTimer(t)
    end)
end
 
Top