View difference between Paste ID: BzcWZnKQ and kJuLwPiD
SHOW: | | - or go back to the newest paste.
1
-- Module [football] by Matiasgim and Sincabellera
2-
2+
 
3
--tfm.exec.setRoomMaxPlayers(14)
4
tfm.exec.disableAutoShaman(true)
5
 
6
local MAP = "@7136237";
7
local MAX_SCORE = 20;
8
local WELCOME_MESSAGE = "<J>Welcome! This is a football game for testing modules. Write <N>!help<J> for more information. Please report any issues to Makinit.";
9
local keys = {space = 32, left = 37, right = 39, a = 65, d = 68, q = 81, x = 88};
10
local team1 = {id = 1, score = 1, colour = "0x0000FF", colour2 = "0x8888FF", tag = "<BV>", name = "the blue team", players = {}};
11-
11+
12
local ball = {player = nil, object = 0, t = 0, x = 0, y = 0, vx = 0, vy = 0, ax = 0, ay = 0, takeTime = 0, shootTime = 0};
13-
	local object, x, y, r, vx, vy = ...
13+
14-
	print(object .. "," .. x .. "," .. y .. "," .. r .. "," .. vx .. "," .. vy)
14+
 
15-
	return tfm.exec.addShamanObject(...)
15+
16
    local object, x, y, r, vx, vy = ...
17-
17+
    print(object .. "," .. x .. "," .. y .. "," .. r .. "," .. vx .. "," .. vy)
18
    return tfm.exec.addShamanObject(...)
19
end
20-
20+
 
21
local players = {};
22
local spectators = {Matiasgim};
23
 
24
function table.copy(t)
25
  local t2 = {}
26
  for k,v in pairs(t) do
27
    t2[k] = v
28-
28+
29
  return t2
30-
	tabs = tabs or "";
30+
31-
	local t = type(value);
31+
 
32-
	print(tabs .. t .. " " .. tostring(name) .. " = " .. tostring(value));
32+
33-
	if t == "table" then
33+
    tabs = tabs or "";
34-
		for n, v in pairs(value) do
34+
    local t = type(value);
35-
			if v == value then
35+
    print(tabs .. t .. " " .. tostring(name) .. " = " .. tostring(value));
36-
				print(tabs .. "\tself " .. n);
36+
    if t == "table" then
37-
			else
37+
        for n, v in pairs(value) do
38-
				printInfo(n, v, tabs .. "\t");
38+
            if v == value then
39-
			end
39+
                print(tabs .. "\tself " .. n);
40-
		end
40+
            else
41-
	end
41+
                printInfo(n, v, tabs .. "\t");
42
            end
43-
43+
        end
44
    end
45
end
46
 
47-
47+
48
-- Fonction principale --
49-
	command.addHandler("debug", doDebug);
49+
50-
	command.addHandler("cheese", doCheese);
50+
 
51-
	command.addHandler("help", doHelp);
51+
52-
	command.addHandler("arrow", doArrow);
52+
    command.addHandler("debug", doDebug);
53-
	--command.addHandler("t", doTeamChat);
53+
    command.addHandler("cheese", doCheese);
54-
	
54+
    command.addHandler("help", doHelp);
55-
	debug.disableEventLog(debugOff);
55+
    command.addHandler("arrow", doArrow);
56-
	tfm.exec.disableAutoScore(true);
56+
    --command.addHandler("t", doTeamChat);
57-
	tfm.exec.disableAutoNewGame(true);
57+
   
58-
	tfm.exec.setGameTime(0, true);
58+
    debug.disableEventLog(debugOff);
59-
	--tfm.exec.chatMessage(WELCOME_MESSAGE);
59+
    tfm.exec.disableAutoScore(true);
60-
	tfm.exec.newGame(MAP);
60+
    tfm.exec.disableAutoNewGame(true);
61
    tfm.exec.setGameTime(0, true);
62-
62+
    --tfm.exec.chatMessage(WELCOME_MESSAGE);
63
    tfm.exec.newGame(MAP);
64
end
65
 
66-
66+
67
-- Fonction newGame ----
68-
	team1.players = {};
68+
69-
	team2.players = {};
69+
 
70-
	team1.score = 1;
70+
71-
	team2.score = 1;
71+
    team1.players = {};
72-
	gameOver = false;
72+
    team2.players = {};
73-
	arrows = false;
73+
    team1.score = 1;
74-
	clearTextArea = false;
74+
    team2.score = 1;
75-
	for name, player in pairs(tfm.get.room.playerList) do
75+
    gameOver = false;
76-
		if player.isShaman then
76+
    arrows = false;
77-
			tfm.exec.killPlayer(name);
77+
    clearTextArea = false;
78-
			tfm.exec.respawnPlayer(name);
78+
    for name, player in pairs(tfm.get.room.playerList) do
79-
			shaman = name;
79+
        if player.isShaman then
80-
		end
80+
            tfm.exec.killPlayer(name);
81-
		initPlayer(name);
81+
            tfm.exec.respawnPlayer(name);
82-
	end
82+
            shaman = name;
83-
	
83+
        end
84-
	for name, player in pairs(tfm.get.room.playerList) do
84+
        initPlayer(name);
85-
		if player.isShaman then
85+
    end
86-
			tfm.exec.killPlayer(name);
86+
   
87-
			tfm.exec.respawnPlayer(name);
87+
    for name, player in pairs(tfm.get.room.playerList) do
88-
			shaman = name;
88+
        if player.isShaman then
89-
		end
89+
            tfm.exec.killPlayer(name);
90-
		returnPlayer(name);
90+
            tfm.exec.respawnPlayer(name);
91-
	end
91+
            shaman = name;
92-
	ball.object = nil;
92+
        end
93-
	if #team1.players > 0 and math.random() > 0.5 then
93+
        returnPlayer(name);
94-
		tasks[os.time() + 5000] = function() giveBall(team1.players[math.random(#team1.players)]) tp123 == true; end;
94+
    end
95-
	elseif #team2.players > 0 then
95+
    ball.object = nil;
96-
		tasks[os.time() + 5000] = function() giveBall(team2.players[math.random(#team2.players)]) tp123 == true; end;
96+
    if #team1.players > 0 and math.random() > 0.5 then
97-
	end
97+
        tasks[os.time() + 5000] = function() giveBall(team1.players[math.random(#team1.players)]) tp123 == true; end;
98
    elseif #team2.players > 0 then
99-
99+
        tasks[os.time() + 5000] = function() giveBall(team2.players[math.random(#team2.players)]) tp123 == true; end;
100
    end
101
end
102
 
103
------------------------------
104-
	ball.player = player;
104+
105-
        tp123 == true;
105+
106
function eventPlayerGetCheese(player)
107-
107+
    ball.player = player;
108
end
109
 
110
------------------------
111-
111+
112
------------------------
113-
	if arrows then
113+
 
114-
	arrows = false
114+
115-
	else
115+
    if arrows then
116-
	arrows = true
116+
    arrows = false
117-
	end
117+
    else
118
    arrows = true
119-
119+
    end
120
end
121-
	--[[if clearTextArea then
121+
 
122-
	ui.removeTextArea(0, player)
122+
123-
	clearTextArea = false
123+
    --[[if clearTextArea then
124-
	end]]
124+
    ui.removeTextArea(0, player)
125-
	--local done = {}
125+
    clearTextArea = false
126-
	local now = os.time();
126+
    end]]
127-
	
127+
    --local done = {}
128-
	-- task handler
128+
    local now = os.time();
129-
	for when, task in pairs(table.copy(tasks)) do
129+
   
130-
		if when <= now then
130+
    -- task handler
131-
			tasks[when] = nil;
131+
    for when, task in pairs(table.copy(tasks)) do
132-
			task();
132+
        if when <= now then
133-
		end
133+
            tasks[when] = nil;
134-
	end
134+
            task();
135-
	if not gameOver then
135+
        end
136-
		tfm.exec.setGameTime(60 * team1.score + team2.score + 1, true);
136+
    end
137-
	if arrows then
137+
    if not gameOver then
138-
		local object = ball.object;
138+
        tfm.exec.setGameTime(60 * team1.score + team2.score + 1, true);
139-
		local player = ball.player;
139+
    if arrows then
140-
		if object then
140+
        local object = ball.object;
141-
			local x, y = getBallLocation();
141+
        local player = ball.player;
142-
			addShamanObject(0, x, y - 25, 0, 0, 0, true);
142+
        if object then
143-
		elseif player then
143+
            local x, y = getBallLocation();
144-
			local ballPlayer = players[player];
144+
            addShamanObject(0, x, y - 25, 0, 0, 0, true);
145-
			if false or ballPlayer then
145+
        elseif player then
146-
				addShamanObject(0, ballPlayer.x, ballPlayer.y - 50, 0, 0, 0, true);
146+
            local ballPlayer = players[player];
147-
			end
147+
            if false or ballPlayer then
148-
			local tfmPlayer = tfm.get.room.playerList[player];
148+
                addShamanObject(0, ballPlayer.x, ballPlayer.y - 50, 0, 0, 0, true);
149-
			if tfmPlayer then
149+
            end
150-
				addShamanObject(0, tfmPlayer.x, tfmPlayer.y - 50, 0, 0, 0, true);
150+
            local tfmPlayer = tfm.get.room.playerList[player];
151-
				end
151+
            if tfmPlayer then
152-
				end
152+
                addShamanObject(0, tfmPlayer.x, tfmPlayer.y - 50, 0, 0, 0, true);
153-
				end
153+
                end
154-
	-- Flèches
154+
                end
155-
		
155+
                end
156-
		--[[local object = ball.object;
156+
    -- Flèches
157-
		local player = ball.player;
157+
       
158-
		if object then
158+
        --[[local object = ball.object;
159-
			local x, y = getBallLocation();
159+
        local player = ball.player;
160-
			addShamanObject(0, x, y - 25, 0, 0, 0, true);
160+
        if object then
161-
		elseif player then
161+
            local x, y = getBallLocation();
162-
			local ballPlayer = players[player];
162+
            addShamanObject(0, x, y - 25, 0, 0, 0, true);
163-
			if false or ballPlayer then
163+
        elseif player then
164-
				addShamanObject(0, ballPlayer.x, ballPlayer.y - 50, 0, 0, 0, true);
164+
            local ballPlayer = players[player];
165-
			end
165+
            if false or ballPlayer then
166-
			local tfmPlayer = tfm.get.room.playerList[player];
166+
                addShamanObject(0, ballPlayer.x, ballPlayer.y - 50, 0, 0, 0, true);
167-
			if tfmPlayer then
167+
            end
168-
				addShamanObject(0, tfmPlayer.x, tfmPlayer.y - 50, 0, 0, 0, true);
168+
            local tfmPlayer = tfm.get.room.playerList[player];
169-
			end
169+
            if tfmPlayer then
170-
		end]]
170+
                addShamanObject(0, tfmPlayer.x, tfmPlayer.y - 50, 0, 0, 0, true);
171-
	else
171+
            end
172-
		local left =50;
172+
        end]]
173-
		local right = 1550;
173+
    else
174-
		if team1.score > team2.score then
174+
        local left =50;
175-
			right = 800;
175+
        local right = 1550;
176-
		elseif team2.score > team1.score then
176+
        if team1.score > team2.score then
177-
			left = 800;
177+
            right = 800;
178-
		end
178+
        elseif team2.score > team1.score then
179-
		addShamanObject(28, math.random(left, right), 350, 0, 0, 0, false);
179+
            left = 800;
180-
	end
180+
        end
181
        addShamanObject(28, math.random(left, right), 350, 0, 0, 0, false);
182-
182+
    end
183
end
184
 
185
-----------------------
186-
186+
187
-----------------------
188-
	if down and players[player] then
188+
 
189-
		if key == keys.left or key == keys.a or key == keys.q then
189+
190-
			players[player].direction = -1;
190+
    if down and players[player] then
191-
		elseif key == keys.right or key == keys.d then
191+
        if key == keys.left or key == keys.a or key == keys.q then
192-
			players[player].direction = 1;
192+
            players[player].direction = -1;
193-
		end
193+
        elseif key == keys.right or key == keys.d then
194-
	end
194+
            players[player].direction = 1;
195-
	if key == keys.space then
195+
        end
196-
		local now = os.time();
196+
    end
197-
		local x2, y2 = getBallLocation(now);
197+
    if key == keys.space then
198-
		if player == ball.player then
198+
        local now = os.time();
199-
			if down then
199+
        local x2, y2 = getBallLocation(now);
200-
				ball.space = now;
200+
        if player == ball.player then
201-
			elseif ball.space then
201+
            if down then
202-
				local force = (now - ball.space) / 100;
202+
                ball.space = now;
203-
				if force > 8 then
203+
            elseif ball.space then
204-
					force = 8;
204+
                local force = (now - ball.space) / 100;
205-
				end
205+
                if force > 8 then
206-
				ball.space = nil;
206+
                    force = 8;
207-
				shootBall(x, y, 5, -6 - force);
207+
                end
208-
				players[player].shootTime = now;
208+
                ball.space = nil;
209-
				ball.takeTime = 0;
209+
                shootBall(x, y, 5, -6 - force);
210-
				ball.shooter = player;
210+
                players[player].shootTime = now;
211-
			end
211+
                ball.takeTime = 0;
212-
		elseif ball.object then
212+
                ball.shooter = player;
213-
			local shootTime = players[player].shootTime or 0;
213+
            end
214-
			if now > shootTime + 1000 and isClose(x, y - 25, getBallLocation(now)) then
214+
        elseif ball.object then
215-
				removeBall();
215+
            local shootTime = players[player].shootTime or 0;
216-
				ball.takeTime = now;
216+
            if now > shootTime + 1000 and isClose(x, y - 25, getBallLocation(now)) then
217-
				giveBall(player);
217+
                removeBall();
218-
				ball.space = nil;
218+
                ball.takeTime = now;
219-
				ball.passer = ball.shooter;
219+
                giveBall(player);
220-
			end
220+
                ball.space = nil;
221-
		elseif ball.player and players[ball.player] and players[ball.player].team.id ~= players[player].team.id and now > ball.takeTime + 1000 then
221+
                ball.passer = ball.shooter;
222-
			local ballPlayer = tfm.get.room.playerList[ball.player];
222+
            end
223-
			local tfmPlayer = tfm.get.room.playerList[player];
223+
        elseif ball.player and players[ball.player] and players[ball.player].team.id ~= players[player].team.id and now > ball.takeTime + 1000 then
224-
			if isClose(x, y, ballPlayer.x, ballPlayer.y) or isClose(tfmPlayer.x, tfmPlayer.y, ballPlayer.x, ballPlayer.y) then
224+
            local ballPlayer = tfm.get.room.playerList[ball.player];
225-
				takeBall(ballPlayer.x, ballPlayer.y);
225+
            local tfmPlayer = tfm.get.room.playerList[player];
226-
				ball.takeTime = now;
226+
            if isClose(x, y, ballPlayer.x, ballPlayer.y) or isClose(tfmPlayer.x, tfmPlayer.y, ballPlayer.x, ballPlayer.y) then
227-
				giveBall(player);
227+
                takeBall(ballPlayer.x, ballPlayer.y);
228-
				ball.space = nil;
228+
                ball.takeTime = now;
229-
				ball.passer = nil;
229+
                giveBall(player);
230-
			end
230+
                ball.space = nil;
231-
		end
231+
                ball.passer = nil;
232-
	end
232+
            end
233-
	--players[player].x = x;
233+
        end
234-
	--players[player].y = y;
234+
    end
235
    --players[player].x = x;
236-
236+
    --players[player].y = y;
237
end
238
 
239
----------------------
240-
240+
241
----------------------
242-
	local d = 25;
242+
 
243-
	return x < x2+d and x > x2-d and y < y2+d and y > y2-d;
243+
244
    local d = 25;
245-
245+
    return x < x2+d and x > x2-d and y < y2+d and y > y2-d;
246
end
247
 
248
-------------------------
249-
249+
250
-------------------------
251-
	tfm.exec.removeObject(ball.object);
251+
 
252-
	ball.object = nil;
252+
253-
	if ball.floorTimer then
253+
    tfm.exec.removeObject(ball.object);
254-
		system.removeTimer(ball.floorTimer);
254+
    ball.object = nil;
255-
	end
255+
    if ball.floorTimer then
256-
	ball.floorTimer = nil;
256+
        system.removeTimer(ball.floorTimer);
257-
	if ball.goalTimer then
257+
    end
258-
		tasks[ball.goalTimer] = nil;
258+
    ball.floorTimer = nil;
259-
	end
259+
    if ball.goalTimer then
260-
	ball.goalTimer = nil;
260+
        tasks[ball.goalTimer] = nil;
261
    end
262-
262+
    ball.goalTimer = nil;
263
end
264
 
265
------------------------
266-
266+
267
------------------------
268-
	ball.x = x;
268+
 
269-
	ball.y = y;
269+
270-
	ball.vx = players[ball.player].direction * (vx or 5);
270+
    ball.x = x;
271-
	ball.vy = (vy or -6);
271+
    ball.y = y;
272-
	ball.ax = 0;
272+
    ball.vx = players[ball.player].direction * (vx or 5);
273-
	ball.ay = 5;
273+
    ball.vy = (vy or -6);
274-
	if ball.object then
274+
    ball.ax = 0;
275-
		tfm.exec.removeObject(ball.object);
275+
    ball.ay = 5;
276-
	end
276+
    if ball.object then
277-
	ball.t = os.time();
277+
        tfm.exec.removeObject(ball.object);
278-
	--ball.object = addShamanObject(tfm.enum.shamanObject.littleBox, x, y, 0, ball.vx, ball.vy, true);
278+
    end
279-
	ball.object = addShamanObject(17, x, y, 0, 0, 0, true);
279+
    ball.t = os.time();
280-
	tfm.exec.moveObject(ball.object, x, y, false, ball.vx*10, ball.vy*10, false);
280+
    --ball.object = addShamanObject(tfm.enum.shamanObject.littleBox, x, y, 0, ball.vx, ball.vy, true);
281-
	if not gameOver then
281+
    ball.object = addShamanObject(17, x, y, 0, 0, 0, true);
282-
		local yf = 330; --floor
282+
    tfm.exec.moveObject(ball.object, x, y, false, ball.vx*10, ball.vy*10, false);
283-
		setFloorTimer(yf);
283+
    if not gameOver then
284-
		if ball.vx < 0 then
284+
        local yf = 330; --floor
285-
			setGoalTimer(0);
285+
        setFloorTimer(yf);
286-
		elseif ball.vx > 0 then
286+
        if ball.vx < 0 then
287-
			setGoalTimer(800);
287+
            setGoalTimer(0);
288-
		end
288+
        elseif ball.vx > 0 then
289-
	end
289+
            setGoalTimer(800);
290-
	takeBall(x, y);
290+
        end
291
    end
292-
292+
    takeBall(x, y);
293
end
294
 
295
----------------------------
296-
296+
297
----------------------------
298-
	if ball.floorTimer then
298+
 
299-
		system.removeTimer(ball.floorTimer);
299+
300-
	end
300+
    if ball.floorTimer then
301-
	if yf then
301+
        system.removeTimer(ball.floorTimer);
302-
		local tf;
302+
    end
303-
		if (ball.ay == 0) then
303+
    if yf then
304-
			tf = (yf - ball.y) / (30*ball.vy);
304+
        local tf;
305-
		else
305+
        if (ball.ay == 0) then
306-
			tf = (-(30*ball.vy) + math.sqrt((30*ball.vy)*(30*ball.vy) - 4*(30*ball.ay)*(ball.y-yf))) / (2*(30*ball.ay));
306+
            tf = (yf - ball.y) / (30*ball.vy);
307-
			if tf < 0 then
307+
        else
308-
				--print"-");
308+
            tf = (-(30*ball.vy) + math.sqrt((30*ball.vy)*(30*ball.vy) - 4*(30*ball.ay)*(ball.y-yf))) / (2*(30*ball.ay));
309-
				tf = (-(30*ball.vy) - math.sqrt((30*ball.vy)*(30*ball.vy) - 4*(30*ball.ay)*(ball.y-yf)))/(2*(30*ball.ay));
309+
            if tf < 0 then
310-
			end
310+
                --print"-");
311-
		end
311+
                tf = (-(30*ball.vy) - math.sqrt((30*ball.vy)*(30*ball.vy) - 4*(30*ball.ay)*(ball.y-yf)))/(2*(30*ball.ay));
312-
		if tf < 1 then
312+
            end
313-
			tf = 1;
313+
        end
314-
		end
314+
        if tf < 1 then
315-
		--ball.floorTimer = system.newTimer(hitFloor, tf * 1000, false, tf);
315+
            tf = 1;
316-
	end
316+
        end
317
        --ball.floorTimer = system.newTimer(hitFloor, tf * 1000, false, tf);
318-
318+
    end
319
end
320
 
321
-----------------------
322-
322+
323
-----------------------
324-
	local now = os.time();
324+
 
325-
	local x, y = getBallLocation(now);
325+
326-
	ball.x = x;
326+
    local now = os.time();
327-
	ball.y = 330;
327+
    local x, y = getBallLocation(now);
328-
	ball.vy = 0;
328+
    ball.x = x;
329-
	ball.ax = 0;
329+
    ball.y = 330;
330-
	ball.ay = 0;
330+
    ball.vy = 0;
331-
	ball.t = now;
331+
    ball.ax = 0;
332-
	tfm.exec.moveObject(ball.object, ball.x, ball.y, false, 0, ball.vy, false);
332+
    ball.ay = 0;
333-
	--print"hit!");
333+
    ball.t = now;
334-
	--printtf .. "," .. x .. "," .. y);
334+
    tfm.exec.moveObject(ball.object, ball.x, ball.y, false, 0, ball.vy, false);
335
    --print"hit!");
336-
336+
    --printtf .. "," .. x .. "," .. y);
337
end
338
 
339
---------------------------
340-
340+
341
---------------------------
342-
	if ball.goalTimer then
342+
 
343-
		tasks[ball.goalTimer] = nil;
343+
344-
	end
344+
    if ball.goalTimer then
345-
	if xg then
345+
        tasks[ball.goalTimer] = nil;
346-
		local tg;
346+
    end
347-
		if (ball.ax == 0) then
347+
    if xg then
348-
			tg = (xg - ball.x) / (30*ball.vx);
348+
        local tg;
349-
		else
349+
        if (ball.ax == 0) then
350-
			tg = (-(30*ball.vx) + math.sqrt((30*ball.vx)*(30*ball.vx) - 4*(30*ball.ax)*(ball.x-xg))) / (2*(30*ball.ax));
350+
            tg = (xg - ball.x) / (30*ball.vx);
351-
			if tg < 0 then
351+
        else
352-
				--print"-");
352+
            tg = (-(30*ball.vx) + math.sqrt((30*ball.vx)*(30*ball.vx) - 4*(30*ball.ax)*(ball.x-xg))) / (2*(30*ball.ax));
353-
				tg = (-30*ball.vx - math.sqrt(900*ball.vx*ball.vx - 480*ball.ax*(ball.x-xg))) / (60*ball.ax);
353+
            if tg < 0 then
354-
			end
354+
                --print"-");
355-
		end
355+
                tg = (-30*ball.vx - math.sqrt(900*ball.vx*ball.vx - 480*ball.ax*(ball.x-xg))) / (60*ball.ax);
356-
		local _, hit = getBallLocation(os.time() + tg * 1000);
356+
            end
357-
		local height = 275;
357+
        end
358-
		ball.scored = hit > height;
358+
        local _, hit = getBallLocation(os.time() + tg * 1000);
359-
		
359+
        local height = 275;
360-
		if tg < 1 then
360+
        ball.scored = hit > height;
361-
			tg = 1;
361+
       
362-
		end
362+
        if tg < 1 then
363-
		ball.goalTimer = os.time() + tg * 1000;
363+
            tg = 1;
364-
		tasks[ball.goalTimer] = hitGoal;
364+
        end
365-
	end
365+
        ball.goalTimer = os.time() + tg * 1000;
366
        tasks[ball.goalTimer] = hitGoal;
367-
367+
    end
368
end
369
 
370
----------------------
371-
371+
372
----------------------
373
 
374-
374+
375
font = "<p align='center'><font size='11'><face='verdana'>"
376-
	local winner;
376+
 
377-
	local loser;
377+
378-
	local loser;
378+
    local winner;
379-
	if ball.vx > 0 then
379+
    local loser;
380-
		winner = team1;
380+
    local loser;
381-
		loser = team2;
381+
    if ball.vx > 0 then
382-
	elseif ball.vx < 0 then
382+
        winner = team1;
383-
		winner = team2;
383+
        loser = team2;
384-
		loser = team1;
384+
    elseif ball.vx < 0 then
385-
	end
385+
        winner = team2;
386-
	if ball.scored then
386+
        loser = team1;
387-
		winner.score = winner.score + 1;
387+
    end
388-
		if players[ball.shooter].team == winner then
388+
    if ball.scored then
389-
			tfm.exec.setPlayerScore(ball.shooter, 10, true);
389+
        winner.score = winner.score + 1;
390-
			local pass = "";
390+
        if players[ball.shooter].team == winner then
391-
			if ball.passer and players[ball.passer] and players[ball.passer].team == winner then
391+
            tfm.exec.setPlayerScore(ball.shooter, 10, true);
392-
				tfm.exec.setPlayerScore(ball.passer, 5, true);
392+
            local pass = "";
393-
				pass = " after a pass from " .. winner.tag .. ball.passer .. "<BL>";
393+
            if ball.passer and players[ball.passer] and players[ball.passer].team == winner then
394-
			end
394+
                tfm.exec.setPlayerScore(ball.passer, 5, true);
395-
			add(0, font .. winner.tag .. ball.shooter .. "<BL> scored" .. pass .. "!\n" .. team1.tag .. team1.name .. " <V>" .. team1.score .. "<BL> - <V>" .. team2.score .. team2.tag .. " " .. team2.name, nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
395+
                pass = " after a pass from " .. winner.tag .. ball.passer .. "<BL>";
396-
		else
396+
            end
397-
			tfm.exec.setPlayerScore(ball.shooter, -10, true);
397+
            add(0, font .. winner.tag .. ball.shooter .. "<BL> scored" .. pass .. "!\n" .. team1.tag .. team1.name .. " <V>" .. team1.score .. "<BL> - <V>" .. team2.score .. team2.tag .. " " .. team2.name, nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
398-
			add(0, font .. loser.tag .. ball.shooter .. "<BL> scored an own goal!\n" .. team1.tag .. team1.name .. " <V>" .. team1.score .. "<BL> - <V>" .. team2.score .. team2.tag .. " " .. team2.name, nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
398+
        else
399-
		end
399+
            tfm.exec.setPlayerScore(ball.shooter, -10, true);
400-
		--add(1,team1.tag .. team1.name .. " <V>" .. team1.score .. "<BL> - <V>" .. team2.score .. team2.tag .. " " .. team2.name, nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
400+
            add(0, font .. loser.tag .. ball.shooter .. "<BL> scored an own goal!\n" .. team1.tag .. team1.name .. " <V>" .. team1.score .. "<BL> - <V>" .. team2.score .. team2.tag .. " " .. team2.name, nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
401-
		if winner.score == MAX_SCORE then
401+
        end
402-
			add(0, font .. "<J>Well done, players of " .. winner.tag .. winner.name .. "<J>, you win!", nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
402+
        --add(1,team1.tag .. team1.name .. " <V>" .. team1.score .. "<BL> - <V>" .. team2.score .. team2.tag .. " " .. team2.name, nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
403-
			gameOver = true;
403+
        if winner.score == MAX_SCORE then
404-
			tfm.exec.setGameTime(20, true);
404+
            add(0, font .. "<J>Well done, players of " .. winner.tag .. winner.name .. "<J>, you win!", nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
405-
			system.newTimer(function() tfm.exec.newGame(MAP) end, 20000, false);
405+
            gameOver = true;
406-
		end
406+
            tfm.exec.setGameTime(20, true);
407-
	else
407+
            system.newTimer(function() tfm.exec.newGame(MAP) end, 20000, false);
408-
		add(0, font .. players[ball.shooter].team.tag .. ball.shooter .. "<BL> missed!", nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
408+
        end
409-
	end
409+
    else
410-
	removeBall();
410+
        add(0, font .. players[ball.shooter].team.tag .. ball.shooter .. "<BL> missed!", nil, 300, 50, 200, height, 0x324752, 0x382020, 0.9, false);
411-
	ball.shooter = nil;
411+
    end
412-
	ball.passer = nil;
412+
    removeBall();
413-
	
413+
    ball.shooter = nil;
414-
	for name, player in pairs(players) do
414+
    ball.passer = nil;
415-
		returnPlayer(name);
415+
   
416-
	end
416+
    for name, player in pairs(players) do
417-
	if #loser.players > 0 then
417+
        returnPlayer(name);
418-
		giveBall(loser.players[math.random(#loser.players)]);
418+
    end
419-
	else
419+
    if #loser.players > 0 then
420-
		giveBall(winner.players[math.random(#winner.players)]);
420+
        giveBall(loser.players[math.random(#loser.players)]);
421-
	end
421+
    else
422
        giveBall(winner.players[math.random(#winner.players)]);
423-
423+
    end
424
end
425
 
426
-----------------------
427-
427+
428
-----------------------
429-
	tfm.exec.killPlayer(ball.player);
429+
 
430-
	tfm.exec.respawnPlayer(ball.player);
430+
431-
	if x and y then
431+
    tfm.exec.killPlayer(ball.player);
432-
		tfm.exec.movePlayer(ball.player, x, y);
432+
    tfm.exec.respawnPlayer(ball.player);
433-
	end
433+
    if x and y then
434-
	ball.player = nil;
434+
        tfm.exec.movePlayer(ball.player, x, y);
435
    end
436-
	
436+
    ball.player = nil;
437
end
438-
	tfm.exec.giveCheese(player);
438+
   
439-
	ball.player = player;
439+
440
    tfm.exec.giveCheese(player);
441-
441+
    ball.player = player;
442
end
443-
	t = t or os.time();
443+
 
444-
	local dt = os.difftime(t, ball.t) / 1000;
444+
445-
	local x = ball.x + dt*(ball.vx + ball.ax*dt) * 30;
445+
    t = t or os.time();
446-
	--local y = ball.y + dt*(ball.vy + ball.ay*dt) * 30;
446+
    local dt = os.difftime(t, ball.t) / 1000;
447-
	-- FIXED GROUND
447+
    local x = ball.x + dt*(ball.vx + ball.ax*dt) * 30;
448-
	local y = math.min(ball.y + dt*(ball.vy + ball.ay*dt) * 30, 330);
448+
    --local y = ball.y + dt*(ball.vy + ball.ay*dt) * 30;
449-
	return x, y;
449+
    -- FIXED GROUND
450
    local y = math.min(ball.y + dt*(ball.vy + ball.ay*dt) * 30, 330);
451-
451+
    return x, y;
452
end
453
 
454
------------------------
455-
455+
456
------------------------
457-
	--tfm.exec.chatMessage(WELCOME_MESSAGE, player);
457+
 
458-
	initPlayer(player);
458+
459-
	tfm.exec.respawnPlayer(player);
459+
    --tfm.exec.chatMessage(WELCOME_MESSAGE, player);
460-
	returnPlayer(player);
460+
    initPlayer(player);
461
    tfm.exec.respawnPlayer(player);
462-
462+
    returnPlayer(player);
463
end
464
 
465
-------------------------
466-
466+
467
-------------------------
468-
	players[player] = {direction = 1, x = 0, y = 0};
468+
 
469-
	for key, code in pairs(keys) do
469+
470-
		tfm.exec.bindKeyboard(player, code, true, true);
470+
    players[player] = {direction = 1, x = 0, y = 0};
471-
		tfm.exec.bindKeyboard(player, code, false, true);
471+
    for key, code in pairs(keys) do
472-
	end
472+
        tfm.exec.bindKeyboard(player, code, true, true);
473-
	local team;
473+
        tfm.exec.bindKeyboard(player, code, false, true);
474-
	if #team1.players < #team2.players then
474+
    end
475-
		team = team1;
475+
    local team;
476-
	elseif #team1.players > #team2.players then
476+
    if #team1.players < #team2.players then
477-
		team = team2;
477+
        team = team1;
478-
	elseif math.random() < 0.5 then
478+
    elseif #team1.players > #team2.players then
479-
		team = team1;
479+
        team = team2;
480-
	else
480+
    elseif math.random() < 0.5 then
481-
		team = team2;
481+
        team = team1;
482-
	end
482+
    else
483-
	table.insert(team.players, player);
483+
        team = team2;
484-
	players[player].team = team;
484+
    end
485-
	
485+
    table.insert(team.players, player);
486-
	--tfm.exec.chatMessage("<N>Press the <VP>space bar<N> to take or shoot the ball.", player);
486+
    players[player].team = team;
487-
	--tfm.exec.chatMessage("<J>You joined " .. team.tag .. team.name .. "<J>!", player);
487+
   
488
    --tfm.exec.chatMessage("<N>Press the <VP>space bar<N> to take or shoot the ball.", player);
489-
489+
    --tfm.exec.chatMessage("<J>You joined " .. team.tag .. team.name .. "<J>!", player);
490
end
491
 
492
---------------------------
493-
493+
494
---------------------------
495-
	if not players[player] then
495+
 
496-
		initPlayer(player)
496+
497-
	end
497+
    if not players[player] then
498-
	local team = players[player].team;
498+
        initPlayer(player)
499-
	tfm.exec.setNameColor(player, team.colour);
499+
    end
500-
	if team == team1 then
500+
    local team = players[player].team;
501-
		tfm.exec.movePlayer(player, math.random(50, 400), 350);
501+
    tfm.exec.setNameColor(player, team.colour);
502-
	elseif team == team2 then
502+
    if team == team1 then
503-
		tfm.exec.movePlayer(player, math.random(400, 750), 350);
503+
        tfm.exec.movePlayer(player, math.random(50, 400), 350);
504-
	end
504+
    elseif team == team2 then
505
        tfm.exec.movePlayer(player, math.random(400, 750), 350);
506-
506+
    end
507
end
508
 
509
-------------------------
510-
510+
511
-------------------------
512-
	local team = players[player].team;
512+
 
513-
	local index;
513+
514-
	for i, name in ipairs(team.players) do
514+
    local team = players[player].team;
515-
		if name == player then
515+
    local index;
516-
			index = i;
516+
    for i, name in ipairs(team.players) do
517-
		end
517+
        if name == player then
518-
	end
518+
            index = i;
519-
	table.remove(team.players, index);
519+
        end
520-
	if ball.player == player then
520+
    end
521-
		if #team.players == 0 and team == team1 then
521+
    table.remove(team.players, index);
522-
			team = team2;
522+
    if ball.player == player then
523-
		elseif #team.players == 0 and team == team2 then
523+
        if #team.players == 0 and team == team1 then
524-
			team = team1
524+
            team = team2;
525-
		end
525+
        elseif #team.players == 0 and team == team2 then
526-
		giveBall(team.players[math.random(#team.players)]);
526+
            team = team1
527-
	end
527+
        end
528-
	
528+
        giveBall(team.players[math.random(#team.players)]);
529-
	for key, code in pairs(keys) do
529+
    end
530-
		tfm.exec.bindKeyboard(player, code, true, false);
530+
   
531-
		tfm.exec.bindKeyboard(player, code, false, false);
531+
    for key, code in pairs(keys) do
532-
	end
532+
        tfm.exec.bindKeyboard(player, code, true, false);
533
        tfm.exec.bindKeyboard(player, code, false, false);
534-
534+
    end
535
end
536
 
537
----------------------
538-
538+
539
----------------------
540
 
541-
	if player == "Makinit" then
541+
542-
		debugOff = not debugOff;
542+
543-
		debug.disableEventLog(debugOff);
543+
    if player == "Makinit" then
544-
	end
544+
        debugOff = not debugOff;
545
        debug.disableEventLog(debugOff);
546-
546+
    end
547
end
548
 
549
-----------------------
550-
550+
551
-----------------------
552-
	if player == "Masterrony" then
552+
 
553-
		tfm.exec.giveCheese("Masterrony");
553+
554-
	end
554+
    if player == "Masterrony" then
555
        tfm.exec.giveCheese("Masterrony");
556-
556+
    end
557
end
558-
558+
 
559
-- Test --
560
 
561
---------------------
562-
562+
563
---------------------
564-
	local message = [[<J>You are a team player and you have to cooperate to score!
564+
 
565
function doHelp(player)
566
    local message = [[<J>You are a team player and you have to cooperate to score!
567
Press the <VP>space bar<J> to take the ball, shoot the ball or tackle an opponent. When you hold it longer you will shoot harder.
568
The first team to reach ]] .. MAX_SCORE .. [[ points will win!
569
Commands:
570-
	ui.addPopup(0, 0, message, player, 250, yPos, 300, true);
570+
571
<N>!t message<J> - team chat]];
572-
572+
    ui.addPopup(0, 0, message, player, 250, yPos, 300, true);
573
end
574
 
575
--------------------------
576-
576+
577
--------------------------
578-
	local arg = {...}
578+
 
579-
	local team = players[player].team;
579+
580-
	local text = string.gsub(string.gsub(table.concat(arg, " "), "<", "&lt;"), ">", "&gt;");
580+
    local arg = {...}
581-
	if team and text and text ~= "" then
581+
    local team = players[player].team;
582-
		local message = team.tag .. "[" .. player .. "]<N> " .. text;
582+
    local text = string.gsub(string.gsub(table.concat(arg, " "), "<", "&lt;"), ">", "&gt;");
583-
		for i, name in ipairs(team.players) do
583+
    if team and text and text ~= "" then
584-
			tfm.exec.chat(message, name);
584+
        local message = team.tag .. "[" .. player .. "]<N> " .. text;
585-
		end-
585+
        for i, name in ipairs(team.players) do
586-
	end
586+
            tfm.exec.chat(message, name);
587
        end-
588-
588+
    end
589
end]]
590-
590+
 
591
-- command handling
592-
	local args = split(message, "%s");
592+
 
593-
	local text = table.remove(args, 1);
593+
594-
	
594+
    local args = split(message, "%s");
595-
	command.handle(string.lower(text), player, args);
595+
    local text = table.remove(args, 1);
596
   
597-
597+
    command.handle(string.lower(text), player, args);
598
end
599-
599+
 
600
command = {handlers = {}};
601-
	if command.handlers[text] == nil then
601+
 
602-
		command.handlers[text] = {};
602+
603-
		system.disableChatCommandDisplay(text, true);
603+
    if command.handlers[text] == nil then
604-
	end
604+
        command.handlers[text] = {};
605-
	table.insert(command.handlers[text], handler);
605+
        system.disableChatCommandDisplay(text, true);
606
    end
607-
	
607+
    table.insert(command.handlers[text], handler);
608
end
609-
	if command.handlers[text] ~= nil then
609+
   
610-
		local index
610+
611-
		for i, h in ipairs(command.handlers[text]) do
611+
    if command.handlers[text] ~= nil then
612-
			if handler == h then
612+
        local index
613-
				index = i;
613+
        for i, h in ipairs(command.handlers[text]) do
614-
			end
614+
            if handler == h then
615-
		end
615+
                index = i;
616-
		if index ~= nil then
616+
            end
617-
			table.remove(command.handlers[text], index)
617+
        end
618-
			if #command.handlers[text] == 0 then
618+
        if index ~= nil then
619-
				command.handlers[text] = nil;
619+
            table.remove(command.handlers[text], index)
620-
				--system.disableChatCommandDisplay(text, false);
620+
            if #command.handlers[text] == 0 then
621-
			end
621+
                command.handlers[text] = nil;
622-
		end
622+
                --system.disableChatCommandDisplay(text, false);
623-
	end
623+
            end
624
        end
625-
625+
    end
626
end
627-
	if command.handlers[text] ~= nil then
627+
 
628-
		for i, handler in ipairs(command.handlers[text]) do
628+
629-
			handler(player, unpack(args));
629+
    if command.handlers[text] ~= nil then
630-
		end
630+
        for i, handler in ipairs(command.handlers[text]) do
631-
	end
631+
            handler(player, unpack(args));
632
        end
633-
633+
    end
634
end
635-
	local res = {};
635+
 
636-
	for part in string.gmatch(input, "[^" .. seperator .. "]+") do
636+
637-
		table.insert(res, part);
637+
    local res = {};
638-
	end
638+
    for part in string.gmatch(input, "[^" .. seperator .. "]+") do
639-
	return res;
639+
        table.insert(res, part);
640
    end
641-
641+
    return res;
642
end
643
 
644-
	i = i or 1;
644+
645-
	if t[i] ~= nil then
645+
646-
		return t[i], unpack(t, i + 1);
646+
    i = i or 1;
647-
	end
647+
    if t[i] ~= nil then
648
        return t[i], unpack(t, i + 1);
649-
649+
    end
650
end
651
 
652
main();