Possible?!
when train hit you, die!
Script:
Spoiler
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
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
trains = { 	[1] = { 		img = "gfx/finbus.png", 		speed = 16; 		tid, gfx = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0, dir = 0, nodes = 0, current = 0, wait = false, 		players = {}, 		node = { 			{59, 16}, {61, 16, 5}, {67, 16}, {78, 27}, {88, 27}, 			{88, 33, 5}, {88, 35}, {92, 35}, {92, 16}, 			{61, 16, 5}, {49, 16}, {49, 52}, 			{62, 52, 5}, {80, 52}, {80, 16}, 		}, 	}, } function GetDir(x1, y1, x2, y2) 	return math.atan2(x2-x1, y2-y1); end function GetDist(x1, y1, x2, y2) 	return math.sqrt((x2 - x1)^2 + (y2 - y1)^2); end function InitTrains() 	local _, i; 	for _, i in pairs(trains) do 		i.nodes = #i.node; 		i.current = 1; 		i.tid = _; 		i.x1 = (i.node[1][1] * 32) + 16; 		i.y1 = (i.node[1][2] * 32) + 16; 		i.x2 = (i.node[2][1] * 32) + 16; 		i.y2 = (i.node[2][2] * 32) + 16; 		i.dir = GetDir(i.x1, i.y1, i.x2, i.y2); 		i.gfx = image(i.img, i.x1, i.y1, 1); 		imagepos(i.gfx, i.x1, i.y1, -math.deg(i.dir)); 	end end InitTrains(); function UnwaitTrain(i) 	trains[tonumber(i)].wait = false; end addhook("always", "moveTrains") function moveTrains() 	local _, i; 	for _, i in pairs(trains) do 		if not i.wait then 			i.x1 = i.x1 + math.sin(i.dir) * i.speed; 			i.y1 = i.y1 + math.cos(i.dir) * i.speed; 			local tx1, ty1; 			tx1 = math.floor(i.x1 / 32); 			ty1 = math.floor(i.y1 / 32); 			if tx1 == math.floor(i.x2 / 32) and ty1 == math.floor(i.y2 / 32) then 				i.current = i.current + 1; 				if i.node[i.current] ~= nil then 					if i.node[i.current][3] ~= nil then 						i.wait = true; 						timer(i.node[i.current][3] * 1000, "UnwaitTrain", tostring(_)); 					end 				end 				i.x1 = i.x2; 				i.y1 = i.y2; 				if i.current == i.nodes + 1 then 					i.current = 1; 					i.x1 = (i.node[1][1] * 32) + 16; 					i.y1 = (i.node[1][2] * 32) + 16; 					i.x2 = (i.node[2][1] * 32) + 16; 					i.y2 = (i.node[2][2] * 32) + 16; 				elseif (i.current + 1) > i.nodes then 					i.x2 = (i.node[1][1] * 32) + 16; 					i.y2 = (i.node[1][2] * 32) + 16; 				else 					i.x2 = (i.node[i.current + 1][1] * 32) + 16; 					i.y2 = (i.node[i.current + 1][2] * 32) + 16; 				end 				i.dir = GetDir(i.x1, i.y1, i.x2, i.y2); 			end 			imagepos(i.gfx, i.x1, i.y1, -math.deg(i.dir)); 		end 		local j, k; 		for j, k in pairs(i.players) do 			if player(k, "health") > 0 then 				parse("setpos ".. k .." ".. i.x1 .." ".. i.y1); 			else 				table.remove(i.players, j); 			end 		end 	end end addhook("use", "enterTrain") function enterTrain(id) 	local x, y = player(id, "x"), player(id, "y"); 	local _, i; 	if not Player[id].car and not Player[id].carowner then 		if Player[id].train == 0 then 			for _, i in pairs(trains) do 				if GetDist(x, y, i.x1, i.y1) <= 48 then 					if i.wait then 						table.insert(i.players, id) 						Player[id].speed = player(id, "speedmod"); 						Player[id].train = _; 						parse("speedmod ".. id .." -100"); 						break; 					else 						msg2(id, "©255000000You can enter train only at station!"); 					end 				end 			end 		else 			if trains[Player[id].train].wait then 				for _, i in pairs(trains[Player[id].train].players) do 					if i == id then 						table.remove(trains[Player[id].train].players, _); 						break; 					end 				end 				Player[id].train = 0; 				parse("speedmod ".. id .." ".. Player[id].speed); 			else 				msg2(id, "©255000000You can't get out of train while traveling"); 			end 		end 	end end