Guest User

http://www.unrealsoftware.de/forum_posts.php?post=347949

a guest
Feb 21st, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.28 KB | None | 0 0
  1. -----------------------------------------------
  2. ---Lua Lag Compensation version 2.2 by FlooD---
  3. -----------------------------------------------
  4. --[[       latest version always at
  5. raw.github.com/FloooD/C_lag_comp/master/llc.lua
  6. ---------------------------------------------]]
  7.  
  8. math.randomseed(os.time())
  9.  
  10. ping = {}
  11. mode = {{}, {}, {}}
  12. buf = {{}, {}}
  13. disabled = {}
  14. no_lc={}
  15. for _, v in ipairs({0, 47, 48, 49, 51, 72, 73, 75, 76, 77, 86, 87, 88, 89, 253, 254, 255}) do
  16.      disabled[v] = true
  17. end
  18.  
  19. armor = {}
  20. for i, v in ipairs({25, 50, 75, 50, 95}) do
  21.      armor[200 + i] = 1 - (v / 100)
  22. end
  23.  
  24. function lc_reset(id)
  25.      mode[1][id] = 0
  26.      mode[2][id] = 0
  27.      mode[3][id] = 0
  28.      buf[1][id] = {}
  29.      buf[2][id] = {}
  30.      ping[id] = nil
  31. end
  32. addhook("die", "lc_reset")
  33.  
  34. function lc_clear(id)
  35.      lc_reset(id)
  36.      no_lc[id] = false
  37. end
  38.  
  39. for i = 1, 32 do
  40.      lc_clear(i)
  41. end
  42. addhook("leave", "lc_clear")
  43.  
  44. function updateping(id)
  45.      local actualping = player(id, "ping")
  46.      if not actualping then return end
  47.      local lastping = ping[id]
  48.      if not lastping then lastping = 0 end
  49.      if actualping - lastping <= 30 or lastping == 0 then
  50.           ping[id] = actualping
  51.      else
  52.           ping[id] = 0.7 * lastping + 0.3 * actualping
  53.      end
  54. end
  55. addhook("spawn", "updateping")
  56.  
  57. function lc_second()
  58.      for i in pairs(ping) do
  59.           updateping(i)
  60.      end
  61. end
  62. addhook("second", "lc_second")
  63.  
  64. MAX_FRAMES = 15
  65. function updatebuf()
  66.      for i in pairs(ping) do
  67.           for j = MAX_FRAMES, 1, -1 do
  68.                buf[1][i][j], buf[2][i][j] = buf[1][i][j-1], buf[2][i][j-1]
  69.           end
  70.           buf[1][i][0], buf[2][i][0] = player(i, "x"), player(i, "y")
  71.      end
  72. end
  73. addhook("always", "updatebuf")
  74.  
  75. addhook("hit", "lc_hit", 1000)
  76. function lc_hit(v, id, wpn)
  77.      return (disabled[wpn] or id == 0 or no_lc[id]) and 0 or 1
  78. end
  79.  
  80. addhook("attack", "lc_attack")
  81. function lc_attack(id)
  82.      local wpn = player(id, "weapon")    
  83.      if disabled[wpn] or no_lc[id] then return end
  84.      local rot = player(id, "rot")
  85.      local dmg = itemtype(wpn, "dmg") * game("mp_damagefactor")
  86.      if (wpn == 2 and mode[1][id] == 1) or (wpn == 39 and mode[2][id] == 1) then
  87.           dmg = math.floor(dmg * 0.64 + 0.5)
  88.           simulate_attack(id, wpn, dmg, rot - 6 + 12 * math.random())
  89.           simulate_attack(id, wpn, dmg, rot + 6 + 8 * math.random())
  90.           simulate_attack(id, wpn, dmg, rot - 6 - 8 * math.random())
  91.           return
  92.      elseif wpn == 10 or wpn == 11 then
  93.           for i = 1, 5 do
  94.                simulate_attack(id, wpn, dmg, rot - 20 + 40 * math.random())
  95.           end
  96.           return
  97.      end
  98.      if mode[3][id] == 1 then
  99.           dmg = itemtype(wpn, "dmg_z1") * game("mp_damagefactor")
  100.      elseif mode[3][id] == 2 then
  101.           dmg = itemtype(wpn, "dmg_z2") * game("mp_damagefactor")
  102.      end
  103.      rot = rot + itemtype(wpn, "dispersion") * (2 * math.random() - 1)
  104.      simulate_attack(id, wpn, dmg, rot)
  105. end
  106.  
  107. addhook("attack2", "lc_attack2")
  108. function lc_attack2(id, m)
  109.      local wpn = player(id, "weapon")
  110.      if wpn == 50 or wpn == 69 then
  111.           if no_lc[id] then return end
  112.           simulate_attack(id, wpn, itemtype(wpn, "dmg_z1") * game("mp_damagefactor"))
  113.      elseif wpn == 2 then
  114.           mode[1][id] = m
  115.      elseif wpn == 39 then
  116.           mode[2][id] = m
  117.      elseif wpn ~= 32 and wpn >= 31 and wpn <= 37 then
  118.           mode[3][id] = m
  119.      end    
  120. end
  121.  
  122. addhook("reload", "unzoom")
  123. addhook("select", "unzoom")
  124. function unzoom(id)
  125.      mode[3][id] = 0
  126. end
  127.  
  128. addhook("drop", "lc_drop")
  129. function lc_drop(id, iid, wpn)
  130.      mode[3][id] = 0
  131.      if wpn == 2 then
  132.           mode[1][id] = 0
  133.      elseif wpn == 39 then
  134.           mode[2][id] = 0
  135.      end
  136. end
  137.  
  138. addhook("collect", "lc_collect")
  139. function lc_collect(id, iid, wpn, ain, a, m)
  140.      if wpn == 2 then
  141.           mode[1][id] = m
  142.      elseif wpn == 39 then
  143.           mode[2][id] = m
  144.      end
  145. end
  146.  
  147. function simulate_attack(id, wpn, dmg, rot)
  148.      if not wpn then wpn = player(id, "weapon") end
  149.      if not dmg then dmg = itemtype(wpn, "dmg") * game("mp_damagefactor") end
  150.      if not rot then rot = player(id, "rot") end
  151.      local range = itemtype(wpn, "range")
  152.      local start_x = player(id, "x")
  153.      local start_y = player(id, "y")
  154.      local end_x = (3 * range) * math.sin(math.rad(rot))
  155.      local end_y = -(3 * range) * math.cos(math.rad(rot))
  156.      local tile_x = math.floor(start_x / 32)
  157.      local tile_y = math.floor(start_y / 32)
  158.      local inc_x, inc_y
  159.      if rot < 0 then
  160.           inc_x = -1
  161.      elseif rot > 0 and rot ~= 180 then
  162.           inc_x = 1
  163.      end
  164.      if math.abs(rot) > 90 then
  165.           inc_y = 1
  166.      elseif math.abs(rot) < 90 then
  167.           inc_y = -1
  168.      end
  169.      while not tile(tile_x, tile_y, "wall") do
  170.           local temp_x, temp_y = tile_x, tile_y
  171.           if inc_x and intersect(end_x, end_y, topixel(temp_x + inc_x) - start_x, topixel(temp_y) - start_y, 16) then
  172.                tile_x = temp_x + inc_x
  173.           end
  174.           if inc_y and intersect(end_x, end_y, topixel(temp_x) - start_x, topixel(temp_y + inc_y) - start_y, 16) then
  175.                tile_y = temp_y + inc_y
  176.           end
  177.           if tile_x == temp_x and tile_y == temp_y then
  178.                break
  179.           end
  180.      end
  181.      if tile(tile_x, tile_y, "wall") then
  182.           end_x, end_y = intersect(end_x, end_y, topixel(tile_x) - start_x, topixel(tile_y) - start_y, 16)
  183.      end
  184.      local frames = math.floor(0.5 + ping[id] / 20)
  185.      if frames > MAX_FRAMES then frames = MAX_FRAMES end
  186.      local victims = {}
  187.      if game("sv_friendlyfire") == "0" and game("sv_gamemode") ~= "1" then
  188.           for i in pairs(ping) do
  189.                if player(i, "team") ~= player(id, "team") then
  190.                     victims[i] = true
  191.                end
  192.           end
  193.      else
  194.           for i in pairs(ping) do
  195.                victims[i] = true
  196.           end
  197.           victims[id] = nil
  198.      end
  199.      for i in pairs(victims) do
  200.           if intersect(end_x, end_y, buf[1][i][frames] - start_x, buf[2][i][frames] - start_y, 12) then
  201.                parse("sv_sound2 "..id.." player/hit"..math.ceil(3 * math.random())..".wav")
  202.                parse("sv_sound2 "..i.." player/hit"..math.ceil(3 * math.random())..".wav")
  203.                local newhealth
  204.                local newarmor = player(i, "armor")
  205.                if newarmor <= 200 then
  206.                     newarmor = newarmor - dmg
  207.                     if newarmor < 0 then
  208.                          newarmor = 0
  209.                     end
  210.                     newhealth = player(i, "health") - (dmg - math.floor(game("mp_kevlar") * (player(i, "armor") - newarmor)))
  211.                     parse("setarmor "..i.." "..newarmor)
  212.                else
  213.                     newhealth = player(i, "health") - math.floor((dmg * (armor[newarmor] or 1)))
  214.                end
  215.                if newhealth > 0 then
  216.                     parse("sethealth "..i.." "..newhealth)
  217.                else
  218.                     sample.ut.kill(id,i,wpn) --id=killer, i=victim
  219.                    
  220.                     parse("customkill "..id.." \""..itemtype(wpn, "name").."\" "..i)
  221.                end
  222.           end
  223.      end
  224. end
  225.  
  226. function topixel(tile)
  227.      return (tile * 32) + 16
  228. end
  229.  
  230. function intersect(ex, ey, bx, by, bl)
  231.      if not (bx and by) then return end
  232.      local cx, cy = (math.abs(bx) <= bl), (math.abs(by) <= bl)
  233.      if cx and cy then
  234.           if math.abs(ex - bx) <= bl and math.abs(ey - by) <= bl then
  235.                return ex, ey
  236.           end
  237.           bl = -bl
  238.      end
  239.      local ox = (ex >= 0) and bx - bl or bx + bl
  240.      local oy = (ey >= 0) and by - bl or by + bl
  241.      local flip
  242.      if (ex == 0 or (cx ~= cy or ((math.abs(ey * ox) >= math.abs(ex * oy)) == (bl < 0)))) and ((not cy) or cx) then
  243.           if ey == 0 then return end
  244.           ex, ey, bx, by, ox, oy = ey, ex, by, bx, oy, ox
  245.           flip = true
  246.      end
  247.      if (ox * ex) >= 0 and math.abs(ox) <= math.abs(ex) then
  248.           oy = ox * ey / ex
  249.           if math.abs(oy - by) <= math.abs(bl) then
  250.                if flip then return oy, ox end
  251.                return ox, oy
  252.           end
  253.      end
  254. end
  255.  
  256. addhook("serveraction", "lc_serveraction")
  257. function lc_serveraction(id, action)
  258.      if action == 1 then
  259.           msg2(id, "Lua Lag Compensation 2.2")
  260.           msg2(id, "Your current ping: "..player(id, "ping"))
  261.           msg2(id, "Current LC is "..(no_lc[id] and "off" or "on").." for yourself.")
  262.      elseif action == 2 then
  263.           no_lc[id] = not no_lc[id]
  264.           msg2(id, "LC toggled "..(no_lc[id] and "off" or "on").." for yourself.")
  265.           msg2(id, "Press the same button to toggle again.")
  266.      end
  267. end
  268.  
  269. --------------------------------------------------
  270. -- UT+Quake Sounds Script by Unreal Software    --
  271. -- 22.02.2009 - www.UnrealSoftware.de           --
  272. -- Adds UT and Quake Sounds to your Server      --
  273. --------------------------------------------------
  274.  
  275. if sample==nil then sample={} end
  276. sample.ut={}
  277.  
  278. -----------------------
  279. -- INITIAL SETUP     --
  280. -----------------------
  281. function initArray(m) --btw, can be a local function
  282.      local array = {}
  283.      for i = 1, m do
  284.           array[i]=0
  285.      end
  286.      return array
  287. end
  288. sample.ut.timer=initArray(32)                    -- time of last kill, for each player
  289. sample.ut.level=initArray(32)                    -- current kill level (killstreak), for each player
  290. sample.ut.fblood=0                                   -- first blood already shed? 0=no/1=yes
  291.  
  292. -----------------------
  293. -- KILL SOUNDS+MSGS  --
  294. -----------------------
  295. --THE HOOK HAS TO BE REMOVED, cuz the function is called from line 218
  296. function sample.ut.kill(killer,victim,weapon)
  297.      sample.ut.level[victim]=0  
  298.      level=sample.ut.level[killer]
  299.      level=level+1
  300.      sample.ut.level[killer]=level
  301.      -- HUMILIATION? (KNIFEKILL)
  302.      if (weapon==50) then
  303.           -- HUMILIATION!
  304.           parse("sv_sound \"e5/Ninja.wav\"");
  305.           msg (player(killer,"name").." ©000000255 NINJA style!!@C")
  306.      else
  307.           if (level==4) then
  308.                parse("sv_sound \"e5/ultrakill.wav\"")
  309.                msg (player(killer,"name").." ©000000255made an ULTRAKILL!@C")
  310.           elseif (level==5) then
  311.                parse("sv_sound \"e5/dominating.wav\"")
  312.                msg (player(killer,"name").." ©000000255is DOMINATING the other team!@C")
  313.           elseif (level==10) then
  314.                parse("sv_sound \"e5/headhunter.wav\"")
  315.                msg (player(killer,"name").." ©000000255killed 10 in a row!!@C")
  316.           elseif (level==20) then
  317.                parse("sv_sound \"e5/megakill.wav\"")
  318.                msg (player(killer,"name").." ©000000255continues his streak with 20 kills in a row!!@C")
  319.           elseif (level==50) then
  320.                parse("sv_sound \"e5/ownage.wav\"")
  321.                msg (player(killer,"name").." ©000000255just can't die... 50 kill streak!!!@C")
  322.           elseif (level==100) then
  323.                parse("sv_sound \"e5/unstoppable.wav\"")
  324.                msg (player(killer,"name").." ©000000255100 kills in a row... UNSTOPPABLE!@C")
  325.           elseif (level==200) then
  326.                parse("sv_sound \"e5/godlike.wav\"")
  327.                msg (player(killer,"name").." ©0002555000has demonstrated legendary skill with 200 killing streak!@C")
  328.           end
  329.      end
  330. end
Add Comment
Please, Sign In to add comment