z_mirror/EvenDistributionLite

git clone https://git.raiguard.me/z_mirror/EvenDistributionLite

Caleb HeuerAdjust position slightly1009eca

simulation
1.4 KiB72 linesraw
1--- @type LuaPlayer
2local player = game.create_test_player({ name = "big k" }) --- @diagnostic disable-line
3player.teleport({ 0, 4 })
4
5game.camera_player = player
6game.camera_player_cursor_position = player.position
7game.camera_alt_info = true
8
9local path = {
10	{
11		on_started = function()
12			game.camera_player_cursor_position = { 0, 4 }
13			player.clear_cursor()
14		end,
15		wait_time = 30,
16	},
17	{
18		on_started = function()
19			player.character.cursor_stack.set_stack({ name = "copper-plate", count = 100 })
20		end,
21		wait_time = 30,
22	},
23	{
24		target = { -7, -1 },
25		wait_time = 30,
26	},
27	{
28		target = { 7, -1 },
29		wait_time = 120,
30	},
31	{
32		target = { 0, 4 },
33	},
34}
35
36local step = 1
37local started = false
38local wait_until_tick = 0
39
40script.on_event(defines.events.on_tick, function()
41	if wait_until_tick > game.tick then
42		return
43	end
44	local data = path[step]
45	if not data then
46		step = 1
47		started = false
48		return
49	end
50	if not started and data.on_started then
51		started = true
52		data.on_started()
53	end
54	local finished = true
55	if data.target then
56		finished = game.move_cursor({ position = data.target, speed = data.speed }) --- @diagnostic disable-line
57		if data.on_moved then
58			data.on_moved()
59		end
60	end
61	if not finished then
62		return
63	end
64	step = step + 1
65	started = false
66	if data.on_finished then
67		data.on_finished()
68	end
69	if data.wait_time then
70		wait_until_tick = game.tick + data.wait_time
71	end
72end)