1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00
RedMew/walk_distance.lua
Valansch 999d7c141f Merge branch 'disable_pets' into develop
# Conflicts:
#	fish_market.lua
#	on_tick.lua
#	player_list.lua
#	poll.lua
#	walk_distance.lua
2018-04-07 20:02:49 +02:00

36 lines
1.1 KiB
Lua

local Event = require "utils.event"
function 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.player_walk_distances[v.name] = global.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.player_walk_distances[player.name] then
global.player_walk_distances[player.name] = 0
end
end
Event.on_nth_tick(62, on_second)
Event.add(defines.events.on_player_joined_game, init_player_position)