Advertisement
XaskeL

Untitled

Jul 22nd, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. local middleclass = loadstring(exports.shared:modules('shared.middleclass'))()
  2.  
  3. local NPCBase = middleclass.class('NPCBase')
  4. NPCBase.alive = {}
  5.  
  6. function NPCBase:initialize(params)
  7.     self.params = params;
  8. end
  9.  
  10. function NPCBase:setHealth(n)
  11.     self.params.health = n;
  12. end
  13.  
  14. function table.findIn(t, In, value)
  15.     if type( t ) ~= 'table' then
  16.         error( 'Bad argument #1, got ' .. type( t ), 2 )
  17.     end
  18.     if In == nil then
  19.         error( 'Bad argument #2, got nil', 2 )
  20.     end
  21.     for i, data in pairs( t ) do
  22.         if data[In] == value then
  23.             return i, data
  24.         end
  25.     end
  26.     return false
  27. end
  28.  
  29. function NPCBase:destroy()
  30.     local i, data = table.findIn(NPCBase.alive, 'table', self.id)
  31.     return table.remove(NPCBase.alive, i)
  32. end
  33.  
  34. for i = 1, 1000000 do
  35.     local bot = NPCBase:new({id=i;type="zombie";health=100;skin=0});
  36.     table.insert(NPCBase.alive, bot)
  37.     bot:destroy()
  38. end
  39.  
  40. collectgarbage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement