Re: calculate

From Sludgy Elephant, 10 Years ago, written in Lua, viewed 681 times.
URL https://paste.godclan.hu/view/gOHuI2Rj Embed
Download Paste or View Raw
  1. local avgTime = 0
  2. local varTime = 0
  3.  
  4. function calledWhenRaceStarts()
  5.     if mysql_query(handler, "SELECT COUNT(*) FROM tops WHERE this_is_this_map") == 0 then
  6.         avgTime = 0
  7.         varTime = 0
  8.         return
  9.     end
  10.  
  11.     local result = mysql_query(handler, "SELECT AVG(time) FROM tops WHERE this_is_this_map")
  12.     avgTime = toNumber(result)
  13.  
  14.     local result = mysql_query(handler, "SELECT VAR(time) FROM tops WHERE this_is_this_map")
  15.     varTime = toNumber(result)
  16. end    
  17.  
  18. local A = 1
  19.  
  20. function calculatePoints(rank, pc, mode)
  21.     if not pc then pc = g_playerCount end
  22.     if not mode then mode = g_mode end
  23.     local points
  24.     if mode == 1 or mode == 3 then -- Race or DM
  25.         if (avgTime == 0 or varTime == 0)
  26.             points = A
  27.         else
  28.             points = A * exp((time - avgTim)^2 / (2 * varTime))
  29.         end
  30.     elseif mode == 2 then -- DD
  31.         points = A * 1000 * math.floor(pc - rank)
  32.     end
  33.     return points
  34. end
  35.  
  36. function calculateMoney(rank, pc, mode)
  37.     if not pc then pc = g_playerCount end
  38.     if not mode then mode = g_mode end
  39.     local money = 0
  40.     if mode == 1 or mode == 3 then -- Race or DM
  41.         money = 200 * (1 - rank/pc) * log(pc)
  42.     elseif mode == 2 then -- DD
  43.         money = 200 * (1 - rank/pc) * pc ^ (1/2)
  44.     end
  45.     return money
  46. end

Reply to "Re: calculate"

Here you can reply to the paste above