Advertisement
Urik_Kane

jc2mp-clock-urik (client\clock.lua)

Jun 4th, 2021 (edited)
2,438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. class 'Clock'
  2.  
  3. function Clock:__init()
  4.     Events:Subscribe( "Render", self, self.Render )
  5. end
  6.  
  7. function Clock:Render()
  8.     self:CalcTime()
  9.  
  10.     local font_scale    = math.round(Render.Size.y/1080,1)
  11.     local text1 = "Time"
  12.     local text2 = tostring(self.time)
  13.     local pos1 = Vector2( Render.Width*0.95, Render.Height * 0.10 )
  14.     local pos2 = Vector2( Render.Width*0.95, Render.Height * 0.12 )
  15.     local font1 = 18*font_scale
  16.     local font2 = 18*font_scale
  17.     pos1.y = pos1.y - Render:GetTextHeight(text1, font1)
  18.     pos1.x = pos1.x - Render:GetTextWidth(text1, font1) / 2    
  19.     pos2.y = pos2.y - Render:GetTextHeight("00:00", font2)
  20.     pos2.x = pos2.x - Render:GetTextWidth("00:00", font2) / 2
  21.     Render:DrawText( pos1 + Vector2(1,1)*font_scale, text1, Color.Black, font1)
  22.     Render:DrawText( pos1, text1, Color.Teal, font1)
  23.     Render:DrawText( pos2 + Vector2(1,1)*font_scale, text2, Color.Black, font2)
  24.     Render:DrawText( pos2, text2, Color.SkyBlue, font2)
  25. end
  26.  
  27. function Clock:CalcTime()
  28.     local gettime = Game:GetTime()
  29.     local hh, timedec = math.modf(gettime)
  30.     local mm, _ = math.modf(60*timedec)
  31.     self.time = string.format("%02d:%02d", hh, mm)
  32. end
  33.  
  34.  
  35. math.round = function(x, n) -- rounding function
  36.     n = math.pow(10, n or 0)
  37.     x = x * n
  38.     if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end
  39.     return x / n
  40. end
  41.  
  42. Clock = Clock()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement