View Single Post
02/14/17, 07:34 PM   #7
BrizonTG
Join Date: Feb 2017
Posts: 2
Lua Code:
  1. -- First addon, just mess around and figuring out the API.
  2.  
  3. -- NOTICE: PLEASE SEE 'README.TXT' FOR INFORMATION REGARDING THIS ADDON, COMPLIANT TO
  4. -- [url]https://account.elderscrollsonline.com/add-on-terms[/url]
  5.  
  6. local Addon =
  7. {
  8.     name,
  9.     inCombat,  
  10. };
  11.  
  12. Addon.name = "test"
  13.  
  14. -----------------------------------------------------------------------------
  15. -- Boilerplate Lua...
  16. -- Here's  our hack to get the 'connect line' back...
  17.  
  18. local AddonManager = {};
  19. function AddonManager:connect(f)
  20.     EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_ADD_ON_LOADED, f);
  21. end
  22.  
  23. function AddonManager:disconnect()
  24.     EVENT_MANAGER:UnregisterForEvent(Addon.name, EVENT_ADD_ON_LOADED);
  25. end
  26.  
  27. local CombatManager = {};
  28. function CombatManager:connect(f)
  29.     EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_PLAYER_COMBAT_STATE, f);
  30. end
  31.  
  32. function warn(string)
  33.     d(string);
  34. end
  35.  
  36. function wait(time)
  37.     local init = os.clock() / 100;
  38.     repeat until (os.clock() / 100) > init + time;
  39. end
  40.  
  41. local clock = os.clock
  42. function sleep(n)  -- seconds
  43.   local t0 = clock();
  44.   while clock() - t0 <= n do end --os.clock isn't available, and this crashes anyway if we use GetTimeFromMilliseconds()
  45. end
  46.  
  47. -----------------------------------------------------------------------------
  48. local timer = 0;
  49. local tldgui;   -- Make us our thing...
  50. local lblcntr;
  51.  
  52. function OnPlayerCombatState(event, inCombat)
  53.     if (inCombat ~= Addon.inCombat)
  54.     then
  55.         Addon.inCombat = inCombat;
  56.         tldgui:SetHidden(not inCombat);
  57.     end
  58.     if (inCombat)
  59.         then
  60.             warn("Entering Combat...");
  61.             while (inCombat) do
  62.                 timer = timer + 1;
  63.                 --if (timer > 0)
  64.                 --then
  65.                     lblCounter:SetText("Counter: " .. timer);
  66.                 --else
  67.                 --  lblCounter:SetText("Entering Combat!");
  68.                 --end
  69.                 --wait(1); --???? Why is this invalid?
  70.                 --sleep();
  71.             end
  72.         else
  73.             warn("Leaving Combat...");
  74.             timer = 0;
  75.     end
  76. end
  77.  
  78. -- Borrowed from the tutorial, hate XML, rather do this.
  79. function Addon:CreateGui()
  80.     tldgui = GetWindowManager():CreateTopLevelWindow("tldgui");
  81.     tldgui:SetDimensions(200, 100);
  82.     tldgui:SetResizeToFitDescendents(true);
  83.     tldgui:SetAnchor(CENTER, GuiRoot, CENTER, 0,0);
  84.     tldgui:SetMovable(true);
  85.     tldgui:SetMouseEnabled(true);
  86.    
  87.     local bdBackdrop = GetWindowManager():CreateControl("bdBackDrop", tldgui, CT_BACKDROP);
  88.     bdBackDrop:SetEdgeColor(0.4,0.4,0.4);
  89.     bdBackDrop:SetCenterColor(0.1,0.1,0.1);
  90.     bdBackDrop:SetAnchor(TOPLEFT, tldgui, TOPLEFT, 0, 0);
  91.     bdBackDrop:SetDimensions(200,100);
  92.     bdBackDrop:SetAlpha(1);
  93.     bdBackDrop:SetDrawLayer(0);
  94.    
  95.     lblCounter = GetWindowManager():CreateControl("lblCounter", tldgui, CT_LABEL)
  96.     lblCounter:SetColor(0.8, 0.8, 0.8, 1);
  97.     lblCounter:SetFont("ZoFontAlert");
  98.     lblCounter:SetScale(1);
  99.     lblCounter:SetWrapMode(TEX_MODE_CLAMP);
  100.     lblCounter:SetDrawLayer(1);
  101.     lblCounter:SetText("Click Counts: 0");
  102.     lblCounter:SetAnchor(CENTER, GuiRoot, CENTER, 0,0);
  103.     lblCounter:SetDimensions(100,25);
  104. end
  105.  
  106. function Addon:Init()
  107.     Addon:CreateGui();
  108.     tldgui:SetHidden(true);
  109.     Addon.inCombat = IsUnitInCombat("player");
  110.     CombatManager:connect(OnPlayerCombatState);
  111.     AddonManager:disconnect();
  112. end
  113.  
  114. 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.

Last edited by BrizonTG : 02/15/17 at 01:34 PM.
  Reply With Quote