start epic if the savegame points to it
This commit is contained in:
parent
0f562ed907
commit
a21c167a60
27
common.lua
27
common.lua
@ -1,4 +1,29 @@
|
||||
|
||||
-- starts the configured epic node at position
|
||||
epic.start = function(playername, pos)
|
||||
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
|
||||
if not player then
|
||||
-- player not online
|
||||
return false
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local main_pos = epic.to_absolute_pos(pos, minetest.string_to_pos(meta:get_string("main_pos")))
|
||||
local exit_pos = epic.to_absolute_pos(pos, minetest.string_to_pos(meta:get_string("exit_pos")))
|
||||
local epic_name = meta:get_string("name")
|
||||
|
||||
if not main_pos then
|
||||
-- no main position
|
||||
return false
|
||||
end
|
||||
|
||||
-- start epic
|
||||
epic.execute_epic(player, main_pos, exit_pos, epic_name)
|
||||
return true
|
||||
end
|
||||
|
||||
-- abort epic if running
|
||||
epic.abort = function(playername)
|
||||
if epic.state[playername] then
|
||||
@ -133,7 +158,7 @@ epic.is_epic = function(node)
|
||||
return nodedef.epic ~= nil
|
||||
end
|
||||
|
||||
-- executes an epic
|
||||
-- executes an epic with main and optional exit function
|
||||
epic.execute_epic = function(player, main_pos, exit_pos, name)
|
||||
if epic.state[player:get_player_name()] then
|
||||
-- already running a function
|
||||
|
@ -60,11 +60,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
if not selected_pos then
|
||||
-- nothing selected
|
||||
return true
|
||||
end
|
||||
|
||||
local node = epic.get_node(selected_pos)
|
||||
if node.name ~= "epic:save" then
|
||||
-- save node disappeared
|
||||
-- TODO: remove level from topic
|
||||
return true
|
||||
end
|
||||
|
||||
@ -72,11 +75,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local target_pos = minetest.string_to_pos(meta:get_string("pos"))
|
||||
|
||||
if not target_pos then
|
||||
-- no target position
|
||||
return true
|
||||
end
|
||||
|
||||
local destination_pos = epic.to_absolute_pos(selected_pos, target_pos)
|
||||
player:set_pos(destination_pos)
|
||||
|
||||
node = epic.get_node(destination_pos)
|
||||
if node.name == "epic:epic" then
|
||||
-- execute epic on position
|
||||
epic.start(playername, destination_pos)
|
||||
else
|
||||
-- teleport just above the position
|
||||
player:set_pos(vector.add(destination_pos, {x=0, y=0.5, z=0}))
|
||||
end
|
||||
end
|
||||
|
||||
if fields.levelname then
|
||||
|
@ -26,17 +26,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
local pos = minetest.string_to_pos(parts[2])
|
||||
local meta = minetest.get_meta(pos)
|
||||
local main_pos = epic.to_absolute_pos(pos, minetest.string_to_pos(meta:get_string("main_pos")))
|
||||
local exit_pos = epic.to_absolute_pos(pos, minetest.string_to_pos(meta:get_string("exit_pos")))
|
||||
local epic_name = meta:get_string("name")
|
||||
|
||||
if not main_pos then
|
||||
return
|
||||
end
|
||||
|
||||
if fields.start then
|
||||
epic.execute_epic(player, main_pos, exit_pos, epic_name)
|
||||
epic.start(player:get_player_name(), pos)
|
||||
end
|
||||
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user