blackops7799

Dota2 Pudge rot damage simulation

Jul 29th, 2021
997
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Using lua-socket for its socket.gettime() function.. Gives a timestamp with milliseconds, which os.time() doesnt do..
  2. local socket = require("socket")
  3.  
  4. -- Variables to change
  5.  
  6. -- How fast we should do our simulation
  7. TIME_SCALE = 120
  8.  
  9. -- Time between rot damage ticks
  10. ROT_RATE = 0.2
  11.  
  12. -- Tick rate of the server
  13. TICK_RATE = 30
  14.  
  15. local function nice_time(seconds)
  16.     local minutes = math.floor(seconds/60)
  17.     local millisecs = (seconds-math.floor(seconds))*99
  18.     seconds = math.floor(seconds % 60)
  19.     -- Format the time in M:S.MS
  20.     return ("%d:%02d.%02d"):format(minutes, seconds, millisecs)
  21. end
  22.  
  23. local start = socket.gettime()
  24. local next_rot = start
  25. local last_rot = start
  26.  
  27. local function do_rot(time)
  28.     -- Only apply rot damage every 0.2 seconds
  29.     if next_rot <= time then
  30.         -- Uncomment this line to fix the timing issue
  31.         --local time_left = (time - next_rot) * TIME_SCALE
  32.  
  33.         local rot_time = (time - last_rot) * TIME_SCALE
  34.  
  35.         -- Only print if we have a weird anomaly
  36.         if rot_time >= 0.21 then
  37.             print(("[%s] Rot damage [SLOW!!!] (Time between ticks %s)"):format(nice_time((time - start) * TIME_SCALE), rot_time))
  38.         else
  39.             print(("[%s] Rot damage within margin of error"):format(nice_time((time - start) * TIME_SCALE)))
  40.         end
  41.  
  42.         last_rot = time
  43.         next_rot = time + (ROT_RATE / TIME_SCALE) - (time_left or 0)
  44.     end
  45. end
  46.  
  47. local function dotick(time)
  48.     do_rot(time)
  49. end
  50.  
  51. local next_tick = start
  52.  
  53. while true do
  54.     dotick(socket.gettime())
  55.     socket.sleep((1/TICK_RATE) / TIME_SCALE)
  56. end
RAW Paste Data