1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 02:00:37 +01:00

Sethome working in the nether, factions too.

- Sethome depends on nether
- There is a home in the nether and another in the real world
- Factions no longer use mobf missing API
- Players' skin refreshed after only 2min
This commit is contained in:
LeMagnesium 2014-11-01 13:00:59 +01:00
parent e8443c87f6
commit 699d4f96c5
5 changed files with 49 additions and 12 deletions

View File

@ -0,0 +1,2 @@
default
nether

View File

@ -1,8 +1,9 @@
local homes_file = minetest.get_worldpath() .. "/homes" local real_homes_file = minetest.get_worldpath() .. "/real_homes"
local homepos = {} local nether_homes_file = minetest.get_worldpath() .. "/nether_homes"
local homepos = {real = {},nether = {}}
local function loadhomes() local function loadhomes()
local input = io.open(homes_file, "r") local input = io.open(real_homes_file, "r")
if input then if input then
repeat repeat
local x = input:read("*n") local x = input:read("*n")
@ -12,11 +13,28 @@ local function loadhomes()
local y = input:read("*n") local y = input:read("*n")
local z = input:read("*n") local z = input:read("*n")
local name = input:read("*l") local name = input:read("*l")
homepos[name:sub(2)] = {x = x, y = y, z = z} homepos.real[name:sub(2)] = {x = x, y = y, z = z}
until input:read(0) == nil until input:read(0) == nil
io.close(input) io.close(input)
else else
homepos = {} homepos.real = {}
end
input = io.open(nether_homes_file, "r")
if input then
repeat
local x = input:read("*n")
if x == nil then
break
end
local y = input:read("*n")
local z = input:read("*n")
local name = input:read("*n")
homepos.nether[name:sub(2)] = {x = x, y = y, z = z}
until input:read(0) == nil
io.close(input)
else
homepos.nether = {}
end end
end end
@ -31,12 +49,19 @@ minetest.register_chatcommand("home", {
privs = {home=true}, privs = {home=true},
func = function(name) func = function(name)
local player = minetest.env:get_player_by_name(name) local player = minetest.env:get_player_by_name(name)
if not player_in_nether then return end
local is_in_nether = table.icontains(players_in_nether, name)
if player == nil then if player == nil then
-- just a check to prevent the server crashing -- just a check to prevent the server crashing
return false return false
end end
if homepos[player:get_player_name()] then if homepos[player:get_player_name()] then
player:setpos(homepos[player:get_player_name()]) if is_in_nether then
player:setpos(nether.homepos[player:get_player_name()])
else
player:setpos(real.homepos[player:get_player_name()])
end
minetest.chat_send_player(name, "Teleported to home!") minetest.chat_send_player(name, "Teleported to home!")
else else
minetest.chat_send_player(name, "Set a home using /sethome") minetest.chat_send_player(name, "Set a home using /sethome")
@ -50,11 +75,21 @@ minetest.register_chatcommand("sethome", {
func = function(name) func = function(name)
local player = minetest.env:get_player_by_name(name) local player = minetest.env:get_player_by_name(name)
local pos = player:getpos() local pos = player:getpos()
homepos[player:get_player_name()] = pos if not players_in_nether then return end
local is_in_nether = table.icontains(players_in_nether, name)
if is_in_nether then
homepos.nether[player:get_player_name()] = pos
else
homepos.real[player:get_player_name()] = pos
end
minetest.chat_send_player(name, "Home set!") minetest.chat_send_player(name, "Home set!")
changed = true changed = true
if changed then if changed then
local output = io.open(homes_file, "w") if is_in_nether then
local output = io.open(nether_homes_file, "w")
else
local output = io.open(real_homes_file, "w")
end
for i, v in pairs(homepos) do for i, v in pairs(homepos) do
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n") output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
end end

View File

@ -343,7 +343,7 @@ end
--! @return true/false (succesfully changed privileges) --! @return true/false (succesfully changed privileges)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function factions.set_admin(name,playername,value) function factions.set_admin(name,playername,value)
mobf_assert_backtrace(type(playername) == "string") --mobf_assert_backtrace(type(playername) == "string")
if factions.data.factions[name] ~= nil then if factions.data.factions[name] ~= nil then
if value then if value then
factions.data.factions[name].adminlist[playername] = true factions.data.factions[name].adminlist[playername] = true

View File

@ -16,7 +16,7 @@ table.icontains = table.icontains or function(t, v)
return false return false
end end
local players_in_nether = {} players_in_nether = {}
local file = io.open(minetest.get_worldpath()..'/nether_players', "r") local file = io.open(minetest.get_worldpath()..'/nether_players', "r")
if file then if file then
local contents = file:read('*all') local contents = file:read('*all')

View File

@ -13,7 +13,7 @@ u_skins.load_players()
local ttime = 0 local ttime = 0
minetest.register_globalstep(function(t) minetest.register_globalstep(function(t)
ttime = ttime + t ttime = ttime + t
if ttime < 360 then --every 6min' if ttime < 120 then --every 6min'
return return
end end
ttime = 0 ttime = 0