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
local offset = 18 --change this if you think the laser should appear farther away from the player
local length = 400 --((640^2+480^2)^0.5)/2 = 400, this should always go across the whole screen (starting from the center, ofc)
images = {}
function killimage(id)
	freeimage(images[id])
	images[id] = nil
end
function spawnimage(id)
	local img = image("gfx/sprites/laser.bmp",1,0,1,id) -- This image should be a 1x1 white bitmap -- id param: only visible to player
	local r,g,b = 255,0,0
	if player(id,"team") == 2 then
		r = 0
		g = 0
		b = 255
	end
	imagecolor(img,r,g,b)
	imageblend(img,1) --cool looking light blending mode
	images[id] = img
end
function togglelaser(id)
	if images[id] then
		killimage(id)
	else
		spawnimage(id)
	end
end
addhook("serveraction","turn_on")
function turn_on(id,action)
	if action == 1 then
		togglelaser(id)
	end
end
addhook("die","_die")
function _die(id)
	killimage(id)
end
addhook("always","_always")
function _always()
	for id=1,32 do
		if images[id] then
			local r = math.rad(player(id,"rot") - 90)
			local newscale = length
			local s = math.sin(r)
			local c = math.cos(r)
			for i=1,length,1 do
				if tile(math.floor((player(id,"x")+c*i)/32),math.floor((player(id,"y")+s*i)/32),"wall") then
					newscale = i
					if newscale < 0 then newscale = newscale + offset else newscale = newscale -offset end
					break
				end
			end
			imagescale(images[id],2,newscale) --double width so the laser is actually visible
			imagepos(images[id],player(id,"x")+c*(newscale/2+offset),player(id,"y")+s*(newscale/2+offset),player(id,"rot"))
		end
	end
end