1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-26 03:52:00 +02:00

added nil check to walk_distance_on_second() #51

This commit is contained in:
Valansch 2017-09-10 16:01:03 +02:00
parent 05d24c94c3
commit eae8ab39db

View File

@ -4,10 +4,12 @@ function walk_distance_on_second()
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
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
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