Add some functions to the mode creaton 'API'

master
LoneWolfHT 2019-08-06 13:04:24 -07:00
parent 165f4e5282
commit e95a12f405
2 changed files with 43 additions and 4 deletions

View File

@ -1,7 +1,7 @@
main = {
current_mode = {},
modes = {},
playing = {},
playing = {}, -- main.playing[playername] = true/false
mode_interval = 60 * 5,
default_drops = {
default = "shooter_guns:ammo",
@ -36,6 +36,10 @@ function main.register_mode(name, def)
end
function main.start_mode(name)
if vc_info.mode_running and main.current_mode.mode.on_end then
local _ = main.current_mode.mode.on_end()
end
vc_info.mode_running = false
main.current_mode.name = name
@ -62,6 +66,10 @@ function main.start_mode(name)
end
end
if main.modes[name].on_start then
local _ = main.modes[name].on_start()
end
main.sethud_all("Current mode: "..main.modes[name].full_name..". Current map: "..mapdef.name, 7)
vc_info.mode_running = true
@ -101,20 +109,20 @@ end
minetest.register_on_joinplayer(function(p)
p:set_hp(20, {type = "set_hp"})
if #minetest.get_connected_players() == 1 then
if not vc_info.mode_running then
main.start_mode("default")
else
main.join_player(p)
end
end)
minetest.register_on_respawnplayer(function(p)
function main.on_respawn(p)
if not main.current_mode.playerspawns then return false end
p:set_pos(main.current_mode.playerspawns[math.random(1, #main.current_mode.playerspawns)])
return true
end)
end
minetest.register_on_player_hpchange(function(_, hp_change, reason)
if reason.type == "fall" then

View File

@ -1,3 +1,20 @@
--[[ All mode settings
main.register_mode("modename", {
full_name = "Mode Name", <required>
min_players = 1, <required>
drops = main.default_drops, <required>
starter_items = main.default_starter_items, <required>
drop_interval = main.default_drop_interval, <required>
on_start = function(), <optional>
on_end = function(), <optional>
on_step = function(dtime), <optional>
on_death = function(player, reason), <optional>
on_respawn = function(player), <optional>
})
]]--
main.register_mode("default", {
full_name = "PvP Party",
min_players = 1,
@ -38,3 +55,17 @@ minetest.register_globalstep(function(dtime)
vc_info.mode_running = false
end
end)
minetest.register_on_dieplayer(function(player, reason)
if main.current_mode.mode.on_death and main.playing[player:get_player_name()] then
main.current_mode.mode.on_death(player, reason)
end
end)
minetest.register_on_respawnplayer(function(player)
if main.current_mode.mode.on_respawn and main.playing[player:get_player_name()] then
main.current_mode.mode.on_respawn(player)
end
main.on_respawn(player)
end)