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
|
-- abort epic if running
|
||||||
epic.abort = function(playername)
|
epic.abort = function(playername)
|
||||||
if epic.state[playername] then
|
if epic.state[playername] then
|
||||||
@ -133,7 +158,7 @@ epic.is_epic = function(node)
|
|||||||
return nodedef.epic ~= nil
|
return nodedef.epic ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- executes an epic
|
-- executes an epic with main and optional exit function
|
||||||
epic.execute_epic = function(player, main_pos, exit_pos, name)
|
epic.execute_epic = function(player, main_pos, exit_pos, name)
|
||||||
if epic.state[player:get_player_name()] then
|
if epic.state[player:get_player_name()] then
|
||||||
-- already running a function
|
-- already running a function
|
||||||
|
@ -60,11 +60,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not selected_pos then
|
if not selected_pos then
|
||||||
|
-- nothing selected
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = epic.get_node(selected_pos)
|
local node = epic.get_node(selected_pos)
|
||||||
if node.name ~= "epic:save" then
|
if node.name ~= "epic:save" then
|
||||||
|
-- save node disappeared
|
||||||
|
-- TODO: remove level from topic
|
||||||
return true
|
return true
|
||||||
end
|
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"))
|
local target_pos = minetest.string_to_pos(meta:get_string("pos"))
|
||||||
|
|
||||||
if not target_pos then
|
if not target_pos then
|
||||||
|
-- no target position
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local destination_pos = epic.to_absolute_pos(selected_pos, target_pos)
|
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
|
end
|
||||||
|
|
||||||
if fields.levelname then
|
if fields.levelname then
|
||||||
|
@ -26,17 +26,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local pos = minetest.string_to_pos(parts[2])
|
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
|
if fields.start then
|
||||||
epic.execute_epic(player, main_pos, exit_pos, epic_name)
|
epic.start(player:get_player_name(), pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user