From a0e5e623c39d4082f1cf5f8d73a98f14961f40bc Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sat, 15 Aug 2015 22:24:03 +0300 Subject: [PATCH] Update ObjectVariables.ext Added proper support for mangos Removed map specific variables --- extensions/ObjectVariables.ext | 102 +++++++++++++++------------------ 1 file changed, 47 insertions(+), 55 deletions(-) diff --git a/extensions/ObjectVariables.ext b/extensions/ObjectVariables.ext index 1dad6cd..f9107a1 100644 --- a/extensions/ObjectVariables.ext +++ b/extensions/ObjectVariables.ext @@ -7,74 +7,64 @@ -- 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 + if event == 18 or event == 17 then + local map = obj:GetMapId() + local inst = obj:GetInstanceId() + for k,v in pairs(variableStores) do + if inst == 0 then + v[map] = nil + else + 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 - 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() + local varStore = variableStores[self:GetObjectType()] + local guid = self:GetGUIDLow() + local map = self:GetMapId() + local inst = self:GetInstanceId() + + varStore[map] = varStore[map] or {} + varStore[map][inst] = varStore[map][inst] or {} + varStore[map][inst][guid] = varStore[map][inst][guid] or {} + + if field then + return varStore[map][inst][guid][field] 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] + return varStore[map][inst][guid] end end 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() + + varStore[map] = varStore[map] or {} + varStore[map][inst] = varStore[map][inst] or {} + varStore[map][inst][guid] = varStore[map][inst][guid] or {} - 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 + varStore[map][inst][guid][field] = val end for k,v in pairs(variableStores) do @@ -82,7 +72,9 @@ for k,v in pairs(variableStores) do _G[k].SetData = SetData end -RegisterPlayerEvent(4, DestroyData) -RegisterServerEvent(31, DestroyData) -RegisterServerEvent(32, DestroyData) -RegisterServerEvent(18, DestroyData) +RegisterPlayerEvent(3, DestroyData) -- login +RegisterPlayerEvent(4, DestroyData) -- logout +RegisterServerEvent(31, DestroyData) -- creature delete +RegisterServerEvent(32, DestroyData) -- gameobject delete +RegisterServerEvent(17, DestroyData) -- map create +RegisterServerEvent(18, DestroyData) -- map destroy