Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --LUA Lag Compensation
- --by FlooD
- --thx to Jermuk for his custom server
- --and lasthope and def3ct for initial testing.
- BUFFER_SIZE = 25
- buffer = {}
- for i = 0, (BUFFER_SIZE - 1) do
- buffer[i] = {}
- for j = 1, 32 do
- buffer[i][j] = {0, 0}
- end
- end
- weapons = {}
- weapons[30] = {range = 300, damage = 22, name = "AK-47"}
- weapons[32] = {range = 300, damage = 22, name = "M4A1"}
- weapons[50] = {range = 8, damage = 50, name = "Knife"}
- weapons[3] = {range = 300, damage = 34, name = "Deagle"}
- for i = 1, 100 do
- if weapons[i] then
- parse("mp_wpndmg "..weapons[i]["name"].." 0")
- end
- end
- addhook("always", "updatebuffer")
- function updatebuffer()
- for i = 0, (BUFFER_SIZE - 2) do
- buffer[BUFFER_SIZE - 1 - i] = deepcopy(buffer[BUFFER_SIZE - 2 - i])
- end
- for i = 1, 32 do
- buffer[0][i][1], buffer[0][i][2] = player(i,"x"), player(i,"y")
- end
- end
- addhook("leave", "clearbuffer")
- addhook("die", "clearbuffer")
- function clearbuffer(id)
- for i = 0, (BUFFER_SIZE - 1) do
- buffer[i][id] = {0, 0}
- end
- end
- addhook("attack", "onattack")
- function onattack(id)
- local wpn = player(id, "weapon")
- local frames = math.floor(player(id, "ping") / 20)
- if frames > (BUFFER_SIZE - 1) then
- frames = (BUFFER_SIZE -1)
- end
- local rot = player(id, "rot")
- local increment_x = math.sin(math.pi * rot / 180)
- local increment_y = math.cos(math.pi * rot / 180)
- local current_x = player(id, "x")
- local current_y = player(id, "y")
- local targets = player(0, "tableliving")
- local hit = {}
- for i = 1, 32 do
- hit[i] = 0
- end
- for i = 1, (3 * weapons[wpn]["range"]) do
- current_x = current_x + increment_x
- current_y = current_y - increment_y
- local tile_x = math.floor(current_x / 32)
- local tile_y = math.floor(current_y / 32)
- if tile(tile_x, tile_y, "wall") then
- return
- end
- for j = 1, #targets do
- local tid=targets[j]
- if ((game("sv_friendlyfire") == 1) or (player(tid, "team") ~= player(id, "team"))) and (tid ~= id) and (hit[tid] == 0) and (math.abs(buffer[frames][tid][1] - current_x) <= 12) and (math.abs(buffer[frames][tid][2] - current_y) <= 12) then
- hit[tid] = 1
- local newarmor = player(tid, "armor") - weapons[wpn]["damage"]
- if newarmor < 0 then
- newarmor = 0
- end
- local newhealth = player(tid, "health") - (weapons[wpn]["damage"] - math.floor(game("mp_kevlar") * (player(tid, "armor") - newarmor)))
- if newhealth > 0 then
- parse("sethealth "..tid.." "..newhealth)
- parse("setarmor "..tid.." "..newarmor)
- else
- parse("customkill "..id.." "..weapons[wpn]["name"].." "..tid)
- end
- end
- end
- end
- end
- function deepcopy(object)
- local lookup_table = {}
- local function _copy(object)
- if type(object) ~= "table" then
- return object
- elseif lookup_table[object] then
- return lookup_table[object]
- end
- local new_table = {}
- lookup_table[object] = new_table
- for index, value in pairs(object) do
- new_table[_copy(index)] = _copy(value)
- end
- return setmetatable(new_table, getmetatable(object))
- end
- return _copy(object)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement