Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- varStore = varStore[mapid]
- if (not varStore) then
- varStore[mapid] = {}
- end
- 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(32, DestroyData)
- RegisterServerEvent(34, DestroyData)
- RegisterServerEvent(18, DestroyData)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement