mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
89 lines
2.0 KiB
Plaintext
89 lines
2.0 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
|
|
--
|
|
|
|
-- filename.ext files are loaded before normal .lua files
|
|
|
|
local variableStores = {
|
|
Map = {},
|
|
Player = {},
|
|
Creature = {},
|
|
GameObject = {},
|
|
}
|
|
|
|
local function DestroyData(event, obj)
|
|
if (event == 18) then
|
|
local mapid = obj:GetMapId()
|
|
local instid = obj:GetInstanceId()
|
|
if (variableStores.Map[mapid]) then
|
|
variableStores.Map[mapid][instid] = nil
|
|
end
|
|
else
|
|
variableStores[obj:GetObjectType()][obj:GetGUIDLow()] = nil
|
|
end
|
|
end
|
|
|
|
local function GetData(self, field)
|
|
local Type = self:GetObjectType()
|
|
local varStore = variableStores[Type]
|
|
local id
|
|
if (Type == "Map") then
|
|
local mapid = self:GetMapId()
|
|
varStore = varStore[mapid]
|
|
if (not varStore) then
|
|
return nil
|
|
end
|
|
id = self:GetInstanceId()
|
|
else
|
|
id = self:GetGUIDLow()
|
|
end
|
|
|
|
if (not varStore[id]) then
|
|
return nil
|
|
end
|
|
|
|
if (field == nil) then
|
|
return varStore[id]
|
|
else
|
|
return varStore[id][field]
|
|
end
|
|
end
|
|
|
|
local function SetData(self, field, val)
|
|
assert(field ~= nil, "field was nil", 2)
|
|
|
|
local Type = self:GetObjectType()
|
|
local varStore = variableStores[Type]
|
|
local id
|
|
if (Type == "Map") then
|
|
local mapid = self:GetMapId()
|
|
|
|
if (not varStore[mapid]) then
|
|
varStore[mapid] = {}
|
|
end
|
|
varStore = varStore[mapid]
|
|
|
|
id = self:GetInstanceId()
|
|
else
|
|
id = self:GetGUIDLow()
|
|
end
|
|
|
|
if (not varStore[id]) then
|
|
varStore[id] = {}
|
|
end
|
|
|
|
varStore[id][field] = val
|
|
end
|
|
|
|
for k,v in pairs(variableStores) do
|
|
_G[k].GetData = GetData
|
|
_G[k].SetData = SetData
|
|
end
|
|
|
|
RegisterPlayerEvent(4, DestroyData)
|
|
RegisterServerEvent(31, DestroyData)
|
|
RegisterServerEvent(32, DestroyData)
|
|
RegisterServerEvent(18, DestroyData)
|