mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
_ext in file name and .ext as extension can both be used to mark files as extensions that are loaded first. Otherwise all is loaded alphabetically. Everything is loaded as modules, which means that they cant be loaded twice with require. closes #85
62 lines
1.7 KiB
Plaintext
62 lines
1.7 KiB
Plaintext
--
|
|
-- Copyright (C) 2010 - 2014 Eluna Lua Engine <http://emudevs.com/>
|
|
-- This program is free software licensed under GPL version 3
|
|
-- Please see the included DOCS/LICENSE.md for more information
|
|
--
|
|
|
|
--[[
|
|
Functions:
|
|
Object:GetData(instance) -- returns a table unique for the object or it's instance
|
|
Object:RemoveData(instance) -- deletes the unique table for the object or it's instance
|
|
|
|
Usage:
|
|
-- Set a variable
|
|
creature:GetData().escorted = true
|
|
-- Check a variable
|
|
if(creature:GetData().escorted) then
|
|
print(creature:GetName().." has been escorted")
|
|
end
|
|
-- Remove all variables (on death, logout etc)
|
|
creature:RemoveData()
|
|
]]
|
|
|
|
local T = {}
|
|
function Object:GetData(instance)
|
|
assert(self, "ObjectVariables: self was nil")
|
|
if(instance) then
|
|
if(not self.GetInstanceId or not self.GetMapId) then
|
|
error("instance is true and object is not worldobject", 2)
|
|
end
|
|
local map = -self:GetMapId()
|
|
local ID = self:GetInstanceId()
|
|
if(not T[map]) then
|
|
T[map] = {}
|
|
end
|
|
if(not T[map][ID]) then
|
|
T[map][ID] = {}
|
|
end
|
|
return T[map][ID]
|
|
else
|
|
local ID = self:GetGUID()
|
|
if(not T[ID]) then
|
|
T[ID] = {}
|
|
end
|
|
return T[ID]
|
|
end
|
|
end
|
|
function Object:RemoveData(instance)
|
|
assert(self, "ObjectVariables: self was nil")
|
|
if(instance) then
|
|
if(not self.GetInstance or not self.GetMapId) then
|
|
error("instance or map is true and object is not worldobject", 2)
|
|
end
|
|
local map = -self:GetMapId()
|
|
local ID = self:GetInstanceId()
|
|
if(T[map]) then
|
|
T[map][ID] = nil
|
|
end
|
|
else
|
|
T[self:GetGUID()] = nil
|
|
end
|
|
end
|