mirror of
https://github.com/minetest-mods/towercrane.git
synced 2024-11-26 01:03:45 +01:00
"Never Store ObjectRefs" bug fixed
This commit is contained in:
parent
e6503cedd3
commit
7e23b7bf50
24
init.lua
24
init.lua
@ -43,15 +43,6 @@ local function chat(owner, text)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local PlayerList = {}
|
|
||||||
|
|
||||||
local function maintain_playerlist()
|
|
||||||
PlayerList = {}
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
|
||||||
PlayerList[player:get_player_name()] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--##################################################################################################
|
--##################################################################################################
|
||||||
--## Construction Area
|
--## Construction Area
|
||||||
--##################################################################################################
|
--##################################################################################################
|
||||||
@ -148,8 +139,9 @@ local function remove_hook(pos, player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function control_player(pos, pos1, pos2, player)
|
local function control_player(pos, pos1, pos2, player_name)
|
||||||
if player and PlayerList[player:get_player_name()] then
|
local player = minetest.get_player_by_name(player_name)
|
||||||
|
if player then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local running = meta:get_int("running")
|
local running = meta:get_int("running")
|
||||||
if running == 1 then
|
if running == 1 then
|
||||||
@ -164,8 +156,8 @@ local function control_player(pos, pos1, pos2, player)
|
|||||||
if pl_pos.z < pos1.z then pl_pos.z = pos1.z; correction = true end
|
if pl_pos.z < pos1.z then pl_pos.z = pos1.z; correction = true end
|
||||||
if pl_pos.z > pos2.z then pl_pos.z = pos2.z; correction = true end
|
if pl_pos.z > pos2.z then pl_pos.z = pos2.z; correction = true end
|
||||||
-- check if a protected area is violated
|
-- check if a protected area is violated
|
||||||
if correction == false and minetest.is_protected(pl_pos, player:get_player_name()) then
|
if correction == false and minetest.is_protected(pl_pos, player_name) then
|
||||||
chat(player:get_player_name(), "Area is protected.")
|
chat(player_name, "Area is protected.")
|
||||||
correction = true
|
correction = true
|
||||||
end
|
end
|
||||||
if correction == true then
|
if correction == true then
|
||||||
@ -177,7 +169,7 @@ local function control_player(pos, pos1, pos2, player)
|
|||||||
meta:set_string("last_known_pos", minetest.pos_to_string(pl_pos))
|
meta:set_string("last_known_pos", minetest.pos_to_string(pl_pos))
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.after(1, control_player, pos, pos1, pos2, player)
|
minetest.after(1, control_player, pos, pos1, pos2, player_name)
|
||||||
else
|
else
|
||||||
remove_hook(pos, player)
|
remove_hook(pos, player)
|
||||||
end
|
end
|
||||||
@ -205,7 +197,7 @@ local function place_hook(pos, dir, player, pos1, pos2)
|
|||||||
player:setpos(pos)
|
player:setpos(pos)
|
||||||
meta:set_string("last_known_pos", minetest.pos_to_string(pos))
|
meta:set_string("last_known_pos", minetest.pos_to_string(pos))
|
||||||
-- control player every second
|
-- control player every second
|
||||||
minetest.after(1, control_player, switch_pos, pos1, pos2, player)
|
minetest.after(1, control_player, switch_pos, pos1, pos2, player:get_player_name())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -754,12 +746,10 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
player:set_attribute("tower_crane_store_fly", minetest.serialize(privs["fly"]))
|
player:set_attribute("tower_crane_store_fly", minetest.serialize(privs["fly"]))
|
||||||
player:set_attribute("tower_crane_store_speed", minetest.serialize(physics.speed))
|
player:set_attribute("tower_crane_store_speed", minetest.serialize(physics.speed))
|
||||||
end
|
end
|
||||||
maintain_playerlist()
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- switch back to normal player privs
|
-- switch back to normal player privs
|
||||||
minetest.register_on_leaveplayer(function(player, timed_out)
|
minetest.register_on_leaveplayer(function(player, timed_out)
|
||||||
maintain_playerlist()
|
|
||||||
remove_hook(nil, player)
|
remove_hook(nil, player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user