forked from Refactorio/RedMew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
walk_distance.lua
33 lines (30 loc) · 1.17 KB
/
walk_distance.lua
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
function walk_distance_on_second()
local last_positions = global.scenario.variables.player_positions
local d_x = 0
local d_y = 0
for _,v in pairs(game.players) do
if (v.afk_time < 30 or v.walking_state.walking) and v.vehicle == nil then
if last_positions[v.name] then
d_x = last_positions[v.name].x - v.position.x
d_y = last_positions[v.name].y - v.position.y
global.scenario.variables.player_walk_distances[v.name] = global.scenario.variables.player_walk_distances[v.name] + math.sqrt(d_x*d_x + d_y*d_y)
global.scenario.variables.player_positions[v.name] = v.position
end
end
end
end
local function get_player_positions()
local pos = {}
for _,v in pairs(game.players) do
pos[v.name] = v.position
end
return pos
end
local function init_player_position(event)
local player = game.players[event.player_index]
global.scenario.variables.player_positions[player.name] = player.position
if not global.scenario.variables.player_walk_distances[player.name] then
global.scenario.variables.player_walk_distances[player.name] = 0
end
end
-- Event.register(defines.events.on_player_joined_game, init_player_position)