luamacrosworld-of-warcraft

Simple Anti AFK AddOn


I tried to write a simple LUA AddOn in World of Warcraft to avoid to be AFK.

Here is what I tried:

function SetNoLongerAFK()
    RunMacro("AntiAFK")
    IsPlayerAFK();
end

function IsPlayerAFK()
    while (UnitIsAFK("player") == false)    do 
        SetNoLongerAFK();
    end
end

function AntiAFKWelcomeMessage()
    print("|cff0080ffWelcome |cffd7df01"..playerName.." - "..realmName.."|r |cff0080ffto the AntiAFK AddOn!|r")
    local macroname = GetMacroInfo("AntiAFK")
    if (macroname == nil or macroname == "") then
        CreateMacro("AntiAFK", 134400, "/afk", 1)
    end
    IsPlayerAFK();
end

callWelcome();

but the RunMacro API Function is blocked I guess. Is there any other ways to realise this with the WoW LUA-API?


Solution

  • Yes, RunMacro is a protected function that can only be called by user code if it was triggered by a key/button press.

    Before I continue, let me say I'd be careful with attempting custom, homebrewed anti-afk methods on Blizzard's servers, as it may be seen as automation if Warden notices it.

    The addon Narcissus has a feature to activate its, uh, viewport when you go AFK, and also has an option to cast /stand to prevent sitting down while AFK. The setting says it does not prevent AFK logout, but I feel like it does prolong the time until you get eventually logged out. This is merely anecdotal, and your mileage may vary.
    But you could take a look at how this is implemented in the addon and experiment with it.