Update ObjectVariables.ext

Added proper support for mangos
Removed map specific variables
This commit is contained in:
Rochet2
2015-08-15 22:24:03 +03:00
parent b6740496bf
commit a0e5e623c3

View File

@@ -7,74 +7,64 @@
-- filename.ext files are loaded before normal .lua files -- filename.ext files are loaded before normal .lua files
local variableStores = { local variableStores = {
Map = {},
Player = {}, Player = {},
Creature = {}, Creature = {},
GameObject = {}, GameObject = {},
} }
local function DestroyData(event, obj) local function DestroyData(event, obj)
if (event == 18) then if event == 18 or event == 17 then
local mapid = obj:GetMapId() local map = obj:GetMapId()
local instid = obj:GetInstanceId() local inst = obj:GetInstanceId()
if (variableStores.Map[mapid]) then for k,v in pairs(variableStores) do
variableStores.Map[mapid][instid] = nil if inst == 0 then
end v[map] = nil
else else
variableStores[obj:GetObjectType()][obj:GetGUIDLow()] = nil local mapdata = v[map]
if mapdata then
mapdata[inst] = nil
end
end
end
return
end
local mapdata = variableStores[obj:GetObjectType()][obj:GetMapId()]
if mapdata then
local instancedata = mapdata[obj:GetInstanceId()]
if instancedata then
instancedata[obj:GetGUIDLow()] = nil
end
end end
end end
local function GetData(self, field) local function GetData(self, field)
local Type = self:GetObjectType() local varStore = variableStores[self:GetObjectType()]
local varStore = variableStores[Type] local guid = self:GetGUIDLow()
local id local map = self:GetMapId()
if (Type == "Map") then local inst = self:GetInstanceId()
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 varStore[map] = varStore[map] or {}
return nil varStore[map][inst] = varStore[map][inst] or {}
end varStore[map][inst][guid] = varStore[map][inst][guid] or {}
if (field == nil) then if field then
return varStore[id] return varStore[map][inst][guid][field]
else else
return varStore[id][field] return varStore[map][inst][guid]
end end
end end
local function SetData(self, field, val) local function SetData(self, field, val)
assert(field ~= nil, "field was nil", 2) local varStore = variableStores[self:GetObjectType()]
local guid = self:GetGUIDLow()
local map = self:GetMapId()
local inst = self:GetInstanceId()
local Type = self:GetObjectType() varStore[map] = varStore[map] or {}
local varStore = variableStores[Type] varStore[map][inst] = varStore[map][inst] or {}
local id varStore[map][inst][guid] = varStore[map][inst][guid] or {}
if (Type == "Map") then
local mapid = self:GetMapId()
if (not varStore[mapid]) then varStore[map][inst][guid][field] = val
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 end
for k,v in pairs(variableStores) do for k,v in pairs(variableStores) do
@@ -82,7 +72,9 @@ for k,v in pairs(variableStores) do
_G[k].SetData = SetData _G[k].SetData = SetData
end end
RegisterPlayerEvent(4, DestroyData) RegisterPlayerEvent(3, DestroyData) -- login
RegisterServerEvent(31, DestroyData) RegisterPlayerEvent(4, DestroyData) -- logout
RegisterServerEvent(32, DestroyData) RegisterServerEvent(31, DestroyData) -- creature delete
RegisterServerEvent(18, DestroyData) RegisterServerEvent(32, DestroyData) -- gameobject delete
RegisterServerEvent(17, DestroyData) -- map create
RegisterServerEvent(18, DestroyData) -- map destroy