mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40:14 +00:00
feat: add WoW event system for Lua addons
Implement the WoW-compatible event system that lets addons react to gameplay events in real-time: - RegisterEvent(eventName, handler) — register a Lua function for an event - UnregisterEvent(eventName, handler) — remove a handler - fireEvent() dispatches events to all registered handlers with args Currently fired events: - PLAYER_ENTERING_WORLD — after addons load and world entry completes - PLAYER_LEAVING_WORLD — before logout/disconnect Events are stored in a __WoweeEvents Lua table, dispatched via LuaEngine::fireEvent() which is called from AddonManager::fireEvent(). Error handling logs Lua errors without crashing. Updated HelloWorld addon to use RegisterEvent for world entry/exit.
This commit is contained in:
parent
7da1f6f5ca
commit
510f03fa32
6 changed files with 148 additions and 14 deletions
|
|
@ -1,18 +1,24 @@
|
|||
-- HelloWorld addon — test the WoWee addon system
|
||||
print("|cff00ff00[HelloWorld]|r Addon loaded! Lua 5.1 is working.")
|
||||
print("|cff00ff00[HelloWorld]|r GetTime() = " .. string.format("%.2f", GetTime()) .. " seconds")
|
||||
|
||||
-- Query player info (will show real data when called after world entry)
|
||||
local name = UnitName("player")
|
||||
local level = UnitLevel("player")
|
||||
local health = UnitHealth("player")
|
||||
local maxHealth = UnitHealthMax("player")
|
||||
local gold = math.floor(GetMoney() / 10000)
|
||||
-- Register for game events
|
||||
RegisterEvent("PLAYER_ENTERING_WORLD", function(event)
|
||||
local name = UnitName("player")
|
||||
local level = UnitLevel("player")
|
||||
local health = UnitHealth("player")
|
||||
local maxHealth = UnitHealthMax("player")
|
||||
local _, _, classId = UnitClass("player")
|
||||
local gold = math.floor(GetMoney() / 10000)
|
||||
|
||||
print("|cff00ff00[HelloWorld]|r Player: " .. name .. " (Level " .. level .. ")")
|
||||
if maxHealth > 0 then
|
||||
print("|cff00ff00[HelloWorld]|r Health: " .. health .. "/" .. maxHealth)
|
||||
end
|
||||
if gold > 0 then
|
||||
print("|cff00ff00[HelloWorld]|r Gold: " .. gold .. "g")
|
||||
end
|
||||
print("|cff00ff00[HelloWorld]|r Welcome, " .. name .. "! (Level " .. level .. ")")
|
||||
if maxHealth > 0 then
|
||||
print("|cff00ff00[HelloWorld]|r Health: " .. health .. "/" .. maxHealth)
|
||||
end
|
||||
if gold > 0 then
|
||||
print("|cff00ff00[HelloWorld]|r Gold: " .. gold .. "g")
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterEvent("PLAYER_LEAVING_WORLD", function(event)
|
||||
print("|cff00ff00[HelloWorld]|r Goodbye!")
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue