-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathspawn_fast_walk.lua
39 lines (28 loc) · 963 Bytes
/
spawn_fast_walk.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
34
35
36
37
38
39
local spawn_pos = minetest.string_to_pos(minetest.settings:get("static_spawnpoint") or "(0, 0, 0)")
local range = 150
local player_map = {} -- playername => boolean
minetest.register_on_leaveplayer(function(player)
player_map[player:get_player_name()] = nil
end)
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 1 then
return
end
timer = 0
for _, player in ipairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
local ppos = player:get_pos()
local is_in_center = vector.distance(spawn_pos, ppos) < range
if is_in_center and not player_map[playername] then
-- moved to spawn
player_monoids.speed:add_change(player, 2, "spawn_fast")
player_map[playername] = true
elseif not is_in_center and player_map[playername] then
-- moved out of spawn
player_monoids.speed:del_change(player, "spawn_fast")
player_map[playername] = nil
end
end
end)