Skip to content

Instantly share code, notes, and snippets.

@kaeza
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaeza/14f85ed2389a8d6855b7 to your computer and use it in GitHub Desktop.
Save kaeza/14f85ed2389a8d6855b7 to your computer and use it in GitHub Desktop.
local KICK_TIME = 300 -- 5 minutes
local player_info = { }
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 5 then return end
for _, pl in ipairs(minetest.get_connected_players()) do
local pos = pl:getpos()
if not player_info[pl] then
player_info[pl] = {
pos = pos,
timer = 0,
}
end
local d = vector.distance(player_info[pl].pos.x, pos)
if d < 0.1 then
player_info[pl].timer = player_info[pl].timer + timer
if player_info[pl].timer >= KICK_TIME then
minetest.kick_player(pl:get_player_name(), "Kicked for idling.")
end
else
player_info[pl].timer = 0
end
player_info[pl].pos = pos
end
timer = 0
end)
minetest.register_on_leaveplayer(function(player)
player_info[player] = nil
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment