1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--------------------------------------------------
-- Based on Laserpointer Script by Plookerbooy --
-- & --
-- Hitzone Script by Unreal Software --
-- --
-- Modified by United --
--------------------------------------------------
function init(a,b)
	local array = {}
	for i = 1, a do
		array[i] = b
	end
	return array
end
lpline=init(32, "")
lppostion=init(32, {})
lpstate=init(32, false)
addhook("die","_reset")
addhook("leave","_reset")
addhook("use","_attack")
addhook("always","_always")
addhook("clientdata","_clientdata")
-- addhook("flashlight","_reset")
if sample==nil then sample={} end
sample.hitzone={}
sample.hitzone.id=0
-----------------------
-- STARTROUND --
-----------------------
addhook("startround","sample.hitzone.startround")
function sample.hitzone.startround()
	sample.hitzone.id=0
end
-----------------------
-- HITZONE --
-----------------------
addhook("hitzone","sample.hitzone.hit")
hits = 0
function sample.hitzone.hit(id)
	-- Show Message
	if hits == 0 then
		msg("+++ Hit!")
		hits = hits + 1
		return
	end
	if hits == 1 then
		msg("--- Hit!")
		hits = hits -1
		return
	end
end
function _attack(id)
	reqcld(id, 2)
end
function _clientdata(id, t, x, y, team)
	-- get data and assign to variables
	local xf, yf, teamf = x, y, team
	if (player(id, "team") == 1) then
		parse('effect "flare" '..xf..' '..yf..' 32 16 0 0 255')
	end
	if (player(id, "team") == 2) then
		parse('effect "flare" '..xf..' '..yf..' 32 16 255 0 0')
	end
	lppostion[id] = {xf, yf}
	lpstate[id]=id
	-- remove previous dummy hitzone
	freeimage(sample.hitzone.id)
	-- create dummy hitzone
	for _, id in pairs(player(0, "tableliving")) do
		if lpstate[id] then
			local x, y = lppostion[id][1], lppostion[id][2]
			sample.hitzone.id=image("gfx/player/randomplayer.bmp",x,y,1)
			imagehitzone(sample.hitzone.id,3,-28/2,-28/2,28,28)
			if (player(id, "team") == 1) then
				imagecolor(sample.hitzone.id,0,0,255)
			end
			if (player(id, "team") == 2) then
				imagecolor(sample.hitzone.id,255,0,0)
			end
			rot = player(id, "rot") - 180
			imagepos(sample.hitzone.id,x,y,rot)
		end
	end
end
function _reset(id)
	if lpstate[id] then
		lpstate[id]=false
		freeimage(lpline[id])
		freeimage(sample.hitzone.id)
	end
end
function _always()
	for _, id in pairs(player(0, "tableliving")) do
		if lpstate[id] then
			local x, y, ix, iy = player(id,"x"), player(id,"y"), lppostion[id][1], lppostion[id][2]
			local lpdist = math.sqrt((x-ix)^2 + (y-iy)^2)
			if lpline[id]~="" then
				freeimage(lpline[id])
			end
			lpline[id] = image("gfx/line.bmp", x, y, 1)
			local hp=100
			local angle= -math.deg(math.atan2(ix-x,iy-y))
			local linex,liney= x-math.sin(math.rad(angle))*lpdist/2, y+math.cos(math.rad(angle))*lpdist/2
			imagepos(lpline[id], linex, liney, angle)
			imagescale(lpline[id],1,lpdist)
			if freeline(x, y, ix, iy) then
				imagecolor(lpline[id], 0, 255, 0)
			else
				imagecolor(lpline[id], 255, 0, 0)
			end
		end
	end
end
function freeline(x1, y1, x2, y2)
for i=1, math.floor(math.sqrt(math.pow(x1 - x2, 2) + math.pow(y1 - y2, 2))) do
if tile(math.floor((x1 + i * math.cos(math.atan2(y2 - y1, x2 - x1))) / 32),math.floor((y1 + i * math.sin(math.atan2(y2 - y1, x2 - x1))) / 32), "wall") == true then
return false
end
end
return true
end