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
local fuels = {}
local fuel_img_offset = 30 -- use this to offset the img from the player
addhook("always", "update_fuels")
addhook("hit", "carry_fuel")
function add_fuel(x, y, imgid)
	fuels:insert({carrier = 0, x=x, y=y,img=imgid})
end
function update_fuels()
	for k, v in pairs(fuels) do
		if ( v.carrier > 0 ) then
			if ( player(v.carrier, "exists") == false or player(v.carrier, "health") <= 0 ) then
				fuels[k].carrier = 0
			else
				local rot = player(v.carrier, "rot")
				local x = player(v.carrier, "x")
				local y = player(v.carreir, "y")
				x = x + fuel_img_offset * math.cos(rot)
				y = y + fuel_img_offset * math.sin(rot)
				fuels[k].x = x
				fuels[k].y = y
				imagepos(v.img, x, y, 0)
			end
		end
	end
end
local function math.dist(x,y)
	return math.sqrt((x-y)^2)
end
function carry_fuel(id)
	local x = player(id, "x")
	local y = player(id, "y")
	if ( not player(id, "bot") ) then
		local pickup = true
		for k, v in pairs(fuels) do
			if ( v.carrier == id ) then
				v.carrier = 0
				pickup = false
				break
			end
		end
		if ( pickup ) then
			for k, v in pairs(fuels) do
				local dist = math.dist(x, v.x) + math.dist(y, v.y)
				if ( dist <= fuel_img_offset and v.carrier == 0 ) then
					fuel[k].carrier = id
					break
				end
			end
		end
	end
end