mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
remove spawn mod--> now in h2omes
add button tp to spawn, send my pos to player, tp to player
This commit is contained in:
parent
4d5aebde7b
commit
d503aabd6d
@ -3,7 +3,13 @@ h2omes.homes = {} -- table players home
|
||||
h2omes.path = minetest.get_worldpath() .. "/h2omes/"
|
||||
minetest.mkdir(h2omes.path)
|
||||
|
||||
h2omes.time = 2 * 60 --MFF 04/05/2016 2 minutes plus 20 minutes
|
||||
h2omes.time_home = 2 * 60 --MFF 04/05/2016 2 minutes plus 20 minutes
|
||||
h2omes.time_spawn = 5*60
|
||||
h2omes.time_from_player = 5*60
|
||||
h2omes.time_to_player = 5*60
|
||||
|
||||
local tmp_players = {}
|
||||
local from_players = {}
|
||||
|
||||
h2omes.have_nether = false -- nether mod
|
||||
if (minetest.get_modpath("nether") ~= nil) then
|
||||
@ -60,6 +66,19 @@ function h2omes.load_homes(name)
|
||||
end
|
||||
end
|
||||
|
||||
-- disallowed tp real-->nether or nether-->real
|
||||
function h2omes.can_teleport(from_pos, to_pos)
|
||||
if not h2omes.have_nether then -- not nether mod, -19600 is real
|
||||
return true
|
||||
end
|
||||
if from_pos.y < -19600 and to_pos.y < -19600 then
|
||||
return true
|
||||
elseif from_pos.y > -19600 and to_pos.y > -19600 then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--function set_homes
|
||||
function h2omes.set_home(name, home_type, pos)
|
||||
@ -100,6 +119,23 @@ function h2omes.get_home(name, home_type)
|
||||
end
|
||||
|
||||
|
||||
--function to_spawn
|
||||
function h2omes.to_spawn(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return false end
|
||||
if minetest.setting_get_pos("static_spawnpoint") then
|
||||
minetest.chat_send_player(name, "Teleporting to spawn...")
|
||||
player:setpos(minetest.setting_get_pos("static_spawnpoint"))
|
||||
minetest.sound_play("teleport", {to_player=name, gain = 1.0})
|
||||
minetest.log("action","Player ".. name .." respawned. Next allowed respawn in ".. h2omes.time_spawn .." seconds.")
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(name, "ERROR: No spawn point is set on this server!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--function to_homes
|
||||
function h2omes.to_home(name, home_type)
|
||||
h2omes.check(name)
|
||||
@ -121,29 +157,128 @@ function h2omes.to_home(name, home_type)
|
||||
end
|
||||
|
||||
|
||||
--function to_player
|
||||
function h2omes.to_player(name, to_pos, to_name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return false end
|
||||
local from_pos = player:getpos()
|
||||
if to_pos then
|
||||
if h2omes.can_teleport(from_pos, to_pos) then
|
||||
minetest.chat_send_player(name, "Teleporting to player "..to_name)
|
||||
player:setpos(to_pos)
|
||||
minetest.sound_play("teleport", {to_player=name, gain = 1.0})
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(name, "Sorry, teleport between 2 worlds(real/nether) is not allowed!")
|
||||
return false
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name, "ERROR: No position to player!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function h2omes.update_pos(name, pos, from_name)
|
||||
from_players[name] = {name=from_name, pos=pos}
|
||||
minetest.chat_send_player(name, from_name .." sent you their position to teleport")
|
||||
minetest.sound_play("dingdong",{to_player=name, gain = 0.8})
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function h2omes.send_pos_to_player(name, pos, to_name)
|
||||
local player = minetest.get_player_by_name(to_name)
|
||||
if not player or not pos then return false end
|
||||
if action_timers.wrapper(name, "send_pos_to_player", "from_player_" .. to_name, h2omes.time_from_player, h2omes.update_pos, {to_name, pos, name}) then
|
||||
minetest.chat_send_player(name, "Your position has been sent to "..to_name)
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(name, "Error: "..to_name.." already received a request. please try again later.")
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function h2omes.show_formspec_home(name)
|
||||
local formspec = {"size[6,7]label[2.1,0;Home Settings]"}
|
||||
if tmp_players[name] == nil then
|
||||
tmp_players[name] = {}
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return false end
|
||||
local formspec = {"size[8,9]label[3.15,0;Home Settings]"}
|
||||
local pos = player:getpos()
|
||||
--spawn
|
||||
table.insert(formspec, "label[3.45,0.8;TO SPAWN]")
|
||||
local spawn_pos = minetest.setting_get_pos("static_spawnpoint")
|
||||
if spawn_pos then
|
||||
if h2omes.can_teleport(pos, spawn_pos) then
|
||||
table.insert(formspec, string.format("label[2.9,1.3;x:%s, y:%s, z:%s]", math.floor(spawn_pos.x), math.floor(spawn_pos.y), math.floor(spawn_pos.z) ))
|
||||
table.insert(formspec, "button_exit[6,1.1;1.5,1;to_spawn;To Spawn]")
|
||||
else
|
||||
table.insert(formspec, "label[1.5,1.3;teleport between 2 worlds(real/nether) is not allowed]")
|
||||
end
|
||||
else
|
||||
table.insert(formspec, "label[3.3,1.3;No spawn set]")
|
||||
end
|
||||
|
||||
--home
|
||||
table.insert(formspec, "label[2.5,1;HOME]")
|
||||
local home = h2omes.get_home(name, "home")
|
||||
table.insert(formspec, "button[0.5,2;1.5,1;set_home;Set Home]")
|
||||
if home then
|
||||
table.insert(formspec, string.format("label[2,1.5;x:%s, y:%s, z:%s]", math.floor(home.x), math.floor(home.y), math.floor(home.z) ))
|
||||
table.insert(formspec, "button_exit[4,2;1.5,1;to_home;To Home]")
|
||||
table.insert(formspec, "label[3.5,2.1;TO HOME]")
|
||||
table.insert(formspec, "button[0.5,2.4;1.5,1;set_home;Set Home]")
|
||||
local home_pos = h2omes.get_home(name, "home")
|
||||
if home_pos then
|
||||
table.insert(formspec, string.format("label[2.9,2.5;x:%s, y:%s, z:%s]", math.floor(home_pos.x), math.floor(home_pos.y), math.floor(home_pos.z) ))
|
||||
table.insert(formspec, "button_exit[6,2.4;1.5,1;to_home;To Home]")
|
||||
else
|
||||
table.insert(formspec, "label[2.3,1.5;Home no set]")
|
||||
table.insert(formspec, "label[3.3,2.5;Home no set]")
|
||||
end
|
||||
|
||||
--pit
|
||||
table.insert(formspec, "label[2.5,3;PIT]")
|
||||
local pit = h2omes.get_home(name, "pit")
|
||||
table.insert(formspec, "button[0.5,4;1.5,1;set_pit;Set Pit]")
|
||||
if pit then
|
||||
table.insert(formspec, string.format("label[2,3.5;x:%s, y:%s, z:%s]", math.floor(pit.x), math.floor(pit.y), math.floor(pit.z) ))
|
||||
table.insert(formspec, "button_exit[4,4;1.5,1;to_pit;To Pit]")
|
||||
table.insert(formspec, "label[3.55,3.4;TO PIT]")
|
||||
table.insert(formspec, "button[0.5,3.7;1.5,1;set_pit;Set Pit]")
|
||||
local pit_pos = h2omes.get_home(name, "pit")
|
||||
if pit_pos then
|
||||
table.insert(formspec, string.format("label[2.9,3.8;x:%s, y:%s, z:%s]", math.floor(pit_pos.x), math.floor(pit_pos.y), math.floor(pit_pos.z) ))
|
||||
table.insert(formspec, "button_exit[6,3.7;1.5,1;to_pit;To Pit]")
|
||||
else
|
||||
table.insert(formspec, "label[2.3,3.5;Pit no set]")
|
||||
table.insert(formspec, "label[3.3,3.8;Pit no set]")
|
||||
end
|
||||
table.insert(formspec, "button_exit[2.3,6.3;1.5,1;close;Close]")
|
||||
|
||||
--to player
|
||||
table.insert(formspec, "label[3.35,4.7;TO PLAYER]")
|
||||
local to_player = from_players[name]
|
||||
if to_player and to_player.name and to_player.pos then
|
||||
table.insert(formspec, string.format("label[0.5,5.1;To %s]", to_player.name))
|
||||
table.insert(formspec,string.format("label[2.9,5.1;x:%s, y:%s, z:%s]", math.floor(to_player.pos.x),math.floor(to_player.pos.y),math.floor(to_player.pos.z)))
|
||||
table.insert(formspec, "button_exit[6,5;1.5,1;to_player;To Player]")
|
||||
else
|
||||
table.insert(formspec, "label[2.7,5.1;No request from player]")
|
||||
end
|
||||
|
||||
table.insert(formspec, "label[2.8,6;SEND MY POS TO PLAYER]")
|
||||
if not tmp_players[name] or not tmp_players[name].players_list or #tmp_players[name].players_list < 1 or tmp_players[name].refresh then
|
||||
tmp_players[name].refresh = nil
|
||||
tmp_players[name].players_list = {}
|
||||
tmp_players[name].selected_id = 0
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
local player_name = player:get_player_name()
|
||||
if player_name and player_name ~= "" and player_name ~= name then
|
||||
table.insert(tmp_players[name].players_list, player_name)
|
||||
end
|
||||
end
|
||||
tmp_players[name]["select_player"] = nil
|
||||
end
|
||||
if #tmp_players[name].players_list == 0 then
|
||||
table.insert(formspec, "label[3,6.4;No player, try later]")
|
||||
else
|
||||
table.insert(formspec,"button[3.5,6.4;1.5,1;refresh;refresh]")
|
||||
table.insert(formspec, "dropdown[0.5,6.5;3,1;select_player;"..table.concat(tmp_players[name].players_list, ",")..";"..tmp_players[name].selected_id.."]")
|
||||
end
|
||||
if tmp_players[name].selected_id and tmp_players[name].selected_id > 0 then
|
||||
table.insert(formspec, "button_exit[6,6.4;1.5,1;send_to;Send To]")
|
||||
end
|
||||
|
||||
table.insert(formspec, "button_exit[3.25,8.3;1.5,1;close;Close]")
|
||||
minetest.show_formspec(name, "h2omes:formspec", table.concat(formspec))
|
||||
end
|
||||
|
||||
@ -154,18 +289,46 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "h2omes:formspec" then
|
||||
if fields["set_home"] then
|
||||
--h2omes.set_home(name, "home")
|
||||
action_timers.wrapper(name, "sethome", "sethome_" .. name, h2omes.time, h2omes.set_home, {name, "home"})
|
||||
action_timers.wrapper(name, "sethome", "sethome_" .. name, h2omes.time_home, h2omes.set_home, {name, "home"})
|
||||
h2omes.show_formspec_home(name)
|
||||
elseif fields["set_pit"] then
|
||||
--h2omes.set_home(name, "pit")
|
||||
action_timers.wrapper(name, "sethome", "sethome_" .. name, h2omes.time, h2omes.set_home, {name, "pit"})
|
||||
action_timers.wrapper(name, "setpit", "sethome_" .. name, h2omes.time_home, h2omes.set_home, {name, "pit"})
|
||||
h2omes.show_formspec_home(name)
|
||||
elseif fields["to_home"] then
|
||||
--h2omes.to_home(name, "home")
|
||||
action_timers.wrapper(name, "tohome", "tohome_" .. name, h2omes.time, h2omes.to_home, {name, "home"})
|
||||
action_timers.wrapper(name, "home", "tohome_" .. name, h2omes.time_home, h2omes.to_home, {name, "home"})
|
||||
elseif fields["to_pit"] then
|
||||
--h2omes.to_home(name, "pit")
|
||||
action_timers.wrapper(name, "tohome", "tohome_" .. name, h2omes.time, h2omes.to_home, {name, "pit"})
|
||||
action_timers.wrapper(name, "pit", "tohome_" .. name, h2omes.time_home, h2omes.to_home, {name, "pit"})
|
||||
elseif fields["to_spawn"] then
|
||||
action_timers.wrapper(name, "spawn", "tospawn_" .. name, h2omes.time_spawn, h2omes.to_spawn, {name})
|
||||
elseif fields["to_player"] then
|
||||
if not from_players[name] then return end
|
||||
local to_name = from_players[name].name
|
||||
local pos = from_players[name].pos
|
||||
from_players[name] = nil
|
||||
if not to_name or not pos then return end
|
||||
h2omes.to_player(name, pos, to_name)
|
||||
elseif fields["send_to"] then
|
||||
local to_name = tmp_players[name]["select_player"]
|
||||
if not to_name then return end
|
||||
local pos = player:getpos()
|
||||
action_timers.wrapper(name, "send_pos_to_player", "to_player_" .. name, h2omes.time_to_player, h2omes.send_pos_to_player, {name, pos, to_name})
|
||||
tmp_players[name] = nil
|
||||
elseif fields["refresh"] then
|
||||
tmp_players[name].refresh = true
|
||||
elseif fields["select_player"] then
|
||||
for i, n in pairs(tmp_players[name].players_list) do
|
||||
if n == fields["select_player"] then
|
||||
tmp_players[name]["select_player"] = fields["select_player"]
|
||||
tmp_players[name].selected_id = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not fields["quit"] then
|
||||
h2omes.show_formspec_home(name)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@ -182,11 +345,31 @@ minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
if not name or name == "" then return end
|
||||
h2omes.homes[name] = nil
|
||||
tmp_players[name] = nil
|
||||
from_players[name] = nil
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_privilege("home", "Can use /sethome, /home, /setpit and /pit")
|
||||
|
||||
minetest.register_chatcommand("spawn", {
|
||||
description = "Teleport a player to the defined spawnpoint",
|
||||
func = function(name)
|
||||
local to_pos = minetest.setting_get_pos("static_spawnpoint")
|
||||
if not to_pos then
|
||||
minetest.chat_send_player(name, "ERROR: No spawn point is set on this server!")
|
||||
return false
|
||||
end
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
from_pos = player:getpos()
|
||||
if h2omes.can_teleport(from_pos, to_pos) then
|
||||
action_timers.wrapper(name, "spawn", "tospawn_" .. name, h2omes.time_spawn, h2omes.to_spawn, {name})
|
||||
else
|
||||
minetest.chat_send_player(name, "Sorry, teleport between 2 worlds(real/nether) is not allowed!")
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("home", {
|
||||
description = "Teleport you to your home point",
|
||||
@ -197,7 +380,7 @@ minetest.register_chatcommand("home", {
|
||||
return false
|
||||
end
|
||||
--h2omes.to_home(name, "home")
|
||||
return action_timers.wrapper(name, "tohome", "tohome_" .. name, h2omes.time, h2omes.to_home, {name, "home"})
|
||||
return action_timers.wrapper(name, "home", "tohome_" .. name, h2omes.time_home, h2omes.to_home, {name, "home"})
|
||||
end,
|
||||
})
|
||||
|
||||
@ -207,7 +390,7 @@ minetest.register_chatcommand("sethome", {
|
||||
privs = {home=true},
|
||||
func = function (name, params)
|
||||
--h2omes.set_home(name, "home")
|
||||
return action_timers.wrapper(name, "sethome", "sethome_" .. name, h2omes.time, h2omes.set_home, {name, "home"})
|
||||
return action_timers.wrapper(name, "sethome", "sethome_" .. name, h2omes.time_home, h2omes.set_home, {name, "home"})
|
||||
end,
|
||||
})
|
||||
|
||||
@ -221,7 +404,7 @@ minetest.register_chatcommand("pit", {
|
||||
return false
|
||||
end
|
||||
--h2omes.to_home(name, "pit")
|
||||
return action_timers.wrapper(name, "tohome", "tohome_" .. name, h2omes.time, h2omes.to_home, {name, "pit"})
|
||||
return action_timers.wrapper(name, "pit", "tohome_" .. name, h2omes.time_home, h2omes.to_home, {name, "pit"})
|
||||
end,
|
||||
})
|
||||
|
||||
@ -231,7 +414,7 @@ minetest.register_chatcommand("setpit", {
|
||||
privs = {home=true},
|
||||
func = function (name, params)
|
||||
--h2omes.set_home(name, "pit")
|
||||
return action_timers.wrapper(name, "sethome", "sethome_" .. name, h2omes.time, h2omes.set_home, {name, "pit"})
|
||||
return action_timers.wrapper(name, "setpit", "sethome_" .. name, h2omes.time_home, h2omes.set_home, {name, "pit"})
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
action_timers
|
@ -1,23 +0,0 @@
|
||||
local SPAWN_INTERVAL = 5*60
|
||||
|
||||
|
||||
minetest.register_chatcommand("spawn", {
|
||||
description = "Teleport a player to the defined spawnpoint",
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
local function go_to_spawn()
|
||||
if minetest.setting_get_pos("static_spawnpoint") then
|
||||
minetest.chat_send_player(player:get_player_name(), "Teleporting to spawn...")
|
||||
player:setpos(minetest.setting_get_pos("static_spawnpoint"))
|
||||
minetest.log("action","Player ".. name .." respawned. Next allowed respawn in ".. SPAWN_INTERVAL .." seconds.")
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(player:get_player_name(), "ERROR: No spawn point is set on this server!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
action_timers.wrapper(name, "spawn", "spawn_" .. name, SPAWN_INTERVAL, go_to_spawn, {})
|
||||
end
|
||||
})
|
@ -195,7 +195,6 @@ load_mod_name_restrictions = true
|
||||
load_mod_whoison = true
|
||||
load_mod_player_inactive = true
|
||||
load_mod_track_players = true
|
||||
load_mod_spawn = true
|
||||
load_mod__misc = true
|
||||
load_mod_interact = true
|
||||
load_mod_news = true
|
||||
|
Loading…
Reference in New Issue
Block a user