Advertisement
actuallykane

Pseudo code entities

Dec 13th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. Entities = {}
  2.  
  3. function entity(type, location, name, update)
  4.     local self = {}
  5.  
  6.     self.type = type or "no-persist"
  7.     self.uid = math.random()
  8.     self.location = location or {x = 0.0, y = 0.0, z = 0.0, heading = 0.0}
  9.     self.name = name or "Default"
  10.  
  11.     self.functions = {}
  12.  
  13.     self.functions.setLocation = function(x, y, z, heading)
  14.         self.location = {x = x, y = y, z = z, heading = heading}
  15.     end
  16.  
  17.     self.get = function(key)
  18.         return self[key]
  19.     end
  20.  
  21.     self.set = function(key, value)
  22.         self[key] = value
  23.         return self[key]
  24.     end
  25.  
  26.     Citizen.CreateThread(function()
  27.         if (update ~= nil) then
  28.             while true do
  29.                 Citizen.Wait(1)
  30.                 if self.type == "no-persist" then break end
  31.                 update(self)
  32.             end
  33.         end
  34.     end)
  35.  
  36.     Entities[self.uid] = self.functions
  37. end
  38.  
  39. local npc = entity("npc", nil, "Some dude")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement