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