Skip to content

Commit

Permalink
also release player when not attached
Browse files Browse the repository at this point in the history
rarely happens, but it can. Better abort in a clean manner to avoid other follow-up problems.
  • Loading branch information
SwissalpS authored Jan 6, 2025
1 parent 53ef6c6 commit b5daa9b
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ local function removeEntity(pos)
end
end


local function release_player(pos)
local hash = core.hash_node_position(pos)
local name = players_on_controller[hash]
local player = core.get_player_by_name(name)
if player then
local parent = player:get_attach()
local lua_entity = parent and parent:get_luaentity()
if lua_entity and lua_entity._is_gamecontroller then
-- Remove also detaches
parent:remove()
end
core.chat_send_player(name, sFreeToMove)
end
-- Shouldn't find any more entities now that above code is fixed
removeEntity(pos)
local meta = core.get_meta(pos)
meta:set_string("infotext", sReady)
last_seen_inputs[name] = nil
players_on_controller[hash] = nil
digilines.receptor_send(pos, digiline_rules,
meta:get_string("channel"), "player_left")
end

local function process_inputs(pos)
local hash = core.hash_node_position(pos)
local name = players_on_controller[hash]
Expand Down Expand Up @@ -88,6 +112,7 @@ local function process_inputs(pos)
digilines.receptor_send(pos, digiline_rules, channel, inputs_copy)
local entity, bone, position = player:get_attach()
if not entity then
release_player(pos)
return
end

Expand All @@ -97,29 +122,6 @@ local function process_inputs(pos)
end
end

local function release_player(pos)
local hash = core.hash_node_position(pos)
local name = players_on_controller[hash]
local player = core.get_player_by_name(name)
if player then
local parent = player:get_attach()
local lua_entity = parent and parent:get_luaentity()
if lua_entity and lua_entity._is_gamecontroller then
-- Remove also detaches
parent:remove()
end
core.chat_send_player(name, sFreeToMove)
end
-- Shouldn't find any more entities now that above code is fixed
removeEntity(pos)
local meta = core.get_meta(pos)
meta:set_string("infotext", sReady)
last_seen_inputs[name] = nil
players_on_controller[hash] = nil
digilines.receptor_send(pos, digiline_rules,
meta:get_string("channel"), "player_left")
end

-- Assumes that no other player is trapped at this position
local function trap_player(pos, player)
local hash = core.hash_node_position(pos)
Expand Down

0 comments on commit b5daa9b

Please sign in to comment.