Advertisement
Rochet2

Untitled

Aug 12th, 2015
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. --
  2. -- Copyright (C) 2010 - 2015 Eluna Lua Engine <http://emudevs.com/>
  3. -- This program is free software licensed under GPL version 3
  4. -- Please see the included DOCS/LICENSE.md for more information
  5. --
  6.  
  7. -- filename.ext files are loaded before normal .lua files
  8.  
  9. local variableStores = {
  10.     Player = {},
  11.     Creature = {},
  12.     GameObject = {},
  13. }
  14.  
  15. local function DestroyData(event, obj)
  16.     if event == 18 or event == 17 then
  17.         local map = obj:GetMapId()
  18.         local inst = obj:GetInstanceId()
  19.         for k,v in pairs(variableStores) do
  20.             if inst == 0 then
  21.                 v[map] = nil
  22.             else
  23.                 local mapdata = v[map]
  24.                 if mapdata then
  25.                     mapdata[inst] = nil
  26.                 end
  27.             end
  28.         end
  29.         return
  30.     end
  31.     local mapdata = variableStores[obj:GetObjectType()][obj:GetMapId()]
  32.     if mapdata then
  33.         local instancedata = mapdata[obj:GetInstanceId()]
  34.         if instancedata then
  35.             instancedata[obj:GetGUIDLow()] = nil
  36.         end
  37.     end
  38. end
  39.  
  40. local function GetData(self, field)
  41.     local varStore = variableStores[self:GetObjectType()]
  42.     local guid = self:GetGUIDLow()
  43.     local map = self:GetMapId()
  44.     local inst = self:GetInstanceId()
  45.  
  46.     varStore[map] = varStore[map] or {}
  47.     varStore[map][inst] = varStore[map][inst] or {}
  48.     varStore[map][inst][guid] = varStore[map][inst][guid] or {}
  49.  
  50.     if field then
  51.         return varStore[map][inst][guid][field]
  52.     else
  53.         return varStore[map][inst][guid]
  54.     end
  55. end
  56.  
  57. local function SetData(self, field, val)
  58.     local varStore = variableStores[self:GetObjectType()]
  59.     local guid = self:GetGUIDLow()
  60.     local map = self:GetMapId()
  61.     local inst = self:GetInstanceId()
  62.  
  63.     varStore[map] = varStore[map] or {}
  64.     varStore[map][inst] = varStore[map][inst] or {}
  65.     varStore[map][inst][guid] = varStore[map][inst][guid] or {}
  66.    
  67.     varStore[map][inst][guid][field] = val
  68. end
  69.  
  70. for k,v in pairs(variableStores) do
  71.     _G[k].GetData = GetData
  72.     _G[k].SetData = SetData
  73. end
  74.  
  75. RegisterPlayerEvent(3, DestroyData) -- login
  76. RegisterPlayerEvent(4, DestroyData) -- logout
  77. RegisterServerEvent(31, DestroyData) -- creature delete
  78. RegisterServerEvent(32, DestroyData) -- gameobject delete
  79. RegisterServerEvent(17, DestroyData) -- map create
  80. RegisterServerEvent(18, DestroyData) -- map destroy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement