Advertisement
Rochet2

Untitled

Jul 7th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local variableStores = {
  2.     Map = {},
  3.     Player = {},
  4.     Creature = {},
  5.     GameObject = {},
  6. }
  7.  
  8. local function DestroyData(event, obj)
  9.     if (event == 18) then
  10.         local mapid = obj:GetMapId()
  11.         local instid = obj:GetInstanceId()
  12.         if (variableStores.Map[mapid]) then
  13.             variableStores.Map[mapid][instid] = nil
  14.         end
  15.     else
  16.         variableStores[obj:GetObjectType()][obj:GetGUIDLow()] = nil
  17.     end
  18. end
  19.  
  20. local function GetData(self, field)
  21.     local Type = self:GetObjectType()
  22.     local varStore = variableStores[Type]
  23.     local id
  24.     if (Type == "Map") then
  25.         local mapid = self:GetMapId()
  26.         varStore = varStore[mapid]
  27.         if (not varStore) then
  28.             return nil
  29.         end
  30.         id = self:GetInstanceId()
  31.     else
  32.         id = self:GetGUIDLow()
  33.     end
  34.    
  35.     if (not varStore[id]) then
  36.         return nil
  37.     end
  38.    
  39.     if (field == nil) then
  40.         return varStore[id]
  41.     else
  42.         return varStore[id][field]
  43.     end
  44. end
  45.  
  46. local function SetData(self, field, val)
  47.     assert(field ~= nil, "field was nil", 2)
  48.    
  49.     local Type = self:GetObjectType()
  50.     local varStore = variableStores[Type]
  51.     local id
  52.     if (Type == "Map") then
  53.         local mapid = self:GetMapId()
  54.    
  55.         varStore = varStore[mapid]
  56.         if (not varStore) then
  57.             varStore[mapid] = {}
  58.         end
  59.        
  60.         id = self:GetInstanceId()
  61.     else
  62.         id = self:GetGUIDLow()
  63.     end
  64.    
  65.     if (not varStore[id]) then
  66.         varStore[id] = {}
  67.     end
  68.    
  69.     varStore[id][field] = val
  70. end
  71.  
  72. for k,v in pairs(variableStores) do
  73.     _G[k].GetData = GetData
  74.     _G[k].SetData = SetData
  75. end
  76.  
  77. RegisterPlayerEvent(4, DestroyData)
  78. RegisterServerEvent(32, DestroyData)
  79. RegisterServerEvent(34, DestroyData)
  80. RegisterServerEvent(18, DestroyData)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement