Advertisement
DanielHarty

Untitled

May 29th, 2022
918
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```lua
  2. local Players = game:GetService("Players")
  3. local RunService = game:GetService("RunService")
  4.  
  5. local Thing = {}
  6. Thing.__index = Thing
  7.  
  8. function Thing.new(instance)
  9.     return setmetatable({instance = instance}, Thing)
  10. end
  11.  
  12. local fire = Instance.new("Fire")
  13. fire.Size = 8
  14. fire.Enabled = false
  15.  
  16. local PlayerCharacter = {}
  17. PlayerCharacter.__index = PlayerCharacter
  18. setmetatable(PlayerCharacter, Thing)
  19. PlayerCharacter.EXTINGUISH_TIME = 5
  20.  
  21. function PlayerCharacter.new(model)
  22.     local self = setmetatable(Thing.new(model), PlayerCharacter)
  23.  
  24.     self.isOnFire = false
  25.  
  26.     self.fire = fire:Clone()
  27.     self.fire.Parent = self.instance.PrimaryPart
  28.    
  29.     self.extinguishTimer = 0
  30.    
  31.     return self
  32. end
  33.  
  34. function PlayerCharacter:setOnFire(onFire)
  35.     if onFire ~= self.isOnFire then
  36.         self.isOnFire = onFire
  37.         self.fire.Enabled = onFire
  38.     end
  39. end
  40.  
  41. function PlayerCharacter:update(deltaTime)
  42.     if self.isOnFire then
  43.         self.instance.Humanoid:TakeDamage(5 * deltaTime)
  44.  
  45.         self.extinguishTimer += deltaTime
  46.         if self.extinguishTimer >= PlayerCharacter.EXTINGUISH_TIME then
  47.             self:setOnFire(false)
  48.             self.extinguishTimer -= PlayerCharacter.EXTINGUISH_TIME
  49.         end
  50.     end
  51. end
  52.  
  53. type PlayerCharacter = typeof(PlayerCharacter.new(Instance.new("Player")))
  54.  
  55. local Game = {}
  56. Game.__index = Game
  57.  
  58. function Game.new()
  59.     local self = setmetatable({}, Game)
  60.  
  61.     self.things = {}
  62.     self.updatingThings = {}
  63.    
  64.     for _,player in pairs(Players:GetPlayers()) do
  65.         local character = player.Character
  66.         if character then
  67.             self:addPlayerCharacter(character)
  68.         end
  69.     end
  70.    
  71.     Players.PlayerAdded:Connect(function(player)
  72.         player.CharacterAppearanceLoaded:Connect(function(character)
  73.             self:addPlayerCharacter(character)
  74.         end)
  75.     end)
  76.  
  77.     RunService.Heartbeat:Connect(function(deltaTime)
  78.         for _, updatingThing in pairs(self.updatingThings) do
  79.             updatingThing:update(deltaTime)
  80.         end
  81.     end)
  82.  
  83.     return self
  84. end
  85.  
  86. function Game:addPlayerCharacter(character)
  87.     local playerCharacter = PlayerCharacter.new(character)
  88.  
  89.     self:addThing(playerCharacter, character)
  90. end
  91.  
  92. function Game:addThing(thing, instance)
  93.     self.things[instance] = thing
  94.  
  95.     if thing["update"] and type(thing["update"]) == "function" then
  96.         self.updatingThings[instance] = thing
  97.     end
  98.  
  99.     instance:GetPropertyChangedSignal("Parent"):Connect(function()
  100.         if instance.Parent == nil and self.things[instance] then
  101.             self.things[instance] = nil
  102.             self.updatingThings[instance] = nil
  103.             instance:Destroy()
  104.         end
  105.     end)
  106. end
  107.  
  108. function Game:update(deltaTime)
  109.     for thing in pairs(self.things) do
  110.         thing:update(deltaTime)
  111.     end
  112. end
  113.  
  114. local myGame = Game.new()
  115.  
  116. task.delay(4, function()
  117.     local me = myGame.things[Players:GetPlayers()[1].Character]
  118.     me:setOnFire(true)
  119. end)
  120. ```
Advertisement
RAW Paste Data Copied
Advertisement