- Joined
- Jun 30, 2021
- Messages
- 28
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