Lua Code:
-- First addon, just mess around and figuring out the API.
-- NOTICE: PLEASE SEE 'README.TXT' FOR INFORMATION REGARDING THIS ADDON, COMPLIANT TO
-- [url]https://account.elderscrollsonline.com/add-on-terms[/url]
local Addon =
{
name,
inCombat,
};
Addon.name = "test"
-----------------------------------------------------------------------------
-- Boilerplate Lua...
-- Here's our hack to get the 'connect line' back...
local AddonManager = {};
function AddonManager:connect(f)
EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_ADD_ON_LOADED, f);
end
function AddonManager:disconnect()
EVENT_MANAGER:UnregisterForEvent(Addon.name, EVENT_ADD_ON_LOADED);
end
local CombatManager = {};
function CombatManager:connect(f)
EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_PLAYER_COMBAT_STATE, f);
end
function warn(string)
d(string);
end
function wait(time)
local init = os.clock() / 100;
repeat until (os.clock() / 100) > init + time;
end
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock();
while clock() - t0 <= n do end --os.clock isn't available, and this crashes anyway if we use GetTimeFromMilliseconds()
end
-----------------------------------------------------------------------------
local timer = 0;
local tldgui; -- Make us our thing...
local lblcntr;
function OnPlayerCombatState(event, inCombat)
if (inCombat ~= Addon.inCombat)
then
Addon.inCombat = inCombat;
tldgui:SetHidden(not inCombat);
end
if (inCombat)
then
warn("Entering Combat...");
while (inCombat) do
timer = timer + 1;
--if (timer > 0)
--then
lblCounter:SetText("Counter: " .. timer);
--else
-- lblCounter:SetText("Entering Combat!");
--end
--wait(1); --???? Why is this invalid?
--sleep();
end
else
warn("Leaving Combat...");
timer = 0;
end
end
-- Borrowed from the tutorial, hate XML, rather do this.
function Addon:CreateGui()
tldgui = GetWindowManager():CreateTopLevelWindow("tldgui");
tldgui:SetDimensions(200, 100);
tldgui:SetResizeToFitDescendents(true);
tldgui:SetAnchor(CENTER, GuiRoot, CENTER, 0,0);
tldgui:SetMovable(true);
tldgui:SetMouseEnabled(true);
local bdBackdrop = GetWindowManager():CreateControl("bdBackDrop", tldgui, CT_BACKDROP);
bdBackDrop:SetEdgeColor(0.4,0.4,0.4);
bdBackDrop:SetCenterColor(0.1,0.1,0.1);
bdBackDrop:SetAnchor(TOPLEFT, tldgui, TOPLEFT, 0, 0);
bdBackDrop:SetDimensions(200,100);
bdBackDrop:SetAlpha(1);
bdBackDrop:SetDrawLayer(0);
lblCounter = GetWindowManager():CreateControl("lblCounter", tldgui, CT_LABEL)
lblCounter:SetColor(0.8, 0.8, 0.8, 1);
lblCounter:SetFont("ZoFontAlert");
lblCounter:SetScale(1);
lblCounter:SetWrapMode(TEX_MODE_CLAMP);
lblCounter:SetDrawLayer(1);
lblCounter:SetText("Click Counts: 0");
lblCounter:SetAnchor(CENTER, GuiRoot, CENTER, 0,0);
lblCounter:SetDimensions(100,25);
end
function Addon:Init()
Addon:CreateGui();
tldgui:SetHidden(true);
Addon.inCombat = IsUnitInCombat("player");
CombatManager:connect(OnPlayerCombatState);
AddonManager:disconnect();
end
AddonManager:connect(Addon.Init);
There's a lot more problems than just wait() here, and I'm still figuring out the differences between ESO's Lua and the implementation of Lua I know.