Add translate client-side, 100% fr ok

Add hell home to support hell mod, and better support to nether/hell coordinates.
Forbids teleportion between 2 worlds.
add variable cooldown in minestest.conf
This commit is contained in:
Crabman77 2022-07-10 04:44:19 +02:00
parent a95392ad0e
commit 63ac6dfa0f
7 changed files with 226 additions and 76 deletions

View File

@ -3,7 +3,7 @@
**A minetest mod by MFF team**
depends of action_timers
optional: nether, unified_inventory
optional: nether, hell, unified_inventory
[demo video youtube](https://www.youtube.com/watch?v=79lt3M-2ZKs)

View File

@ -1,4 +0,0 @@
default
action_timers
unified_inventory?
nether?

View File

@ -1 +0,0 @@
This mod add teleportation to spawn, 2 homes and to players.

201
init.lua
View File

@ -1,22 +1,35 @@
local S = minetest.get_translator(minetest.get_current_modname())
h2omes = {}
h2omes.homes = {} -- table players home
h2omes.path = minetest.get_worldpath() .. "/h2omes/"
minetest.mkdir(h2omes.path)
h2omes.time_home = 2 * 60
h2omes.time_spawn = 5 * 60
h2omes.time_from_player = 5 * 60
h2omes.time_to_player = 5 * 60
h2omes.time_home = tonumber(minetest.settings:get("h2omes.time_home")) or 2 * 60
h2omes.time_spawn = tonumber(minetest.settings:get("h2omes.time_spawn")) or 5 * 60
h2omes.time_from_player = tonumber(minetest.settings:get("h2omes.time_from_player")) or 5 * 60
h2omes.time_to_player = tonumber(minetest.settings:get("h2omes.time_to_player")) or 5 * 60
local tmp_players = {}
local from_players = {}
h2omes.have_hell = false -- hell mod
if (minetest.get_modpath("hell") ~= nil) then
h2omes.have_hell = true
h2omes.hell_ceiling = hell.DEPTH
h2omes.hell_floor = hell.DEPTH - 510
end
h2omes.have_nether = false -- nether mod
if (minetest.get_modpath("nether") ~= nil) then
h2omes.have_nether = true
h2omes.nether_ceiling = nether.DEPTH_CEILING
h2omes.nether_floor = nether.DEPTH_FLOOR
end
function h2omes.check(name)
if h2omes.homes[name] == nil then
h2omes.homes[name] = {["home"] = {}, ["pit"] = {}}
@ -53,6 +66,9 @@ function h2omes.load_homes(name)
if data.home.nether then
h2omes.homes[name].home.nether = data.home.nether
end
if data.home.hell then
h2omes.homes[name].home.hell = data.home.hell
end
end
if data.pit then
if data.pit.real then
@ -61,40 +77,70 @@ function h2omes.load_homes(name)
if data.pit.nether then
h2omes.homes[name].pit.nether = data.pit.nether
end
if data.pit.hell then
h2omes.homes[name].pit.hell = data.pit.hell
end
end
end
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
local function is_inside(pos, pos_min, pos_max)
if pos < pos_min and pos > pos_max then
return true
end
return false
end
--function set_homes
function h2omes.set_home(name, home_type, pos)
h2omes.check(name)
if not pos then
local player = minetest.get_player_by_name(name)
if not player then return end
pos = player:get_pos()
-- disallowed tp real-->nether or nether-->real
function h2omes.can_teleport(from_pos, to_pos)
if not h2omes.have_nether and not h2omes.have_hell then -- not nether/hell mod
return true
end
if h2omes.have_nether then
if is_inside(from_pos.y, h2omes.nether_ceiling, h2omes.nether_floor) and not is_inside(to_pos.y, h2omes.nether_ceiling, h2omes.nether_floor) then
return false
elseif is_inside(to_pos.y, h2omes.nether_ceiling, h2omes.nether_floor) and not is_inside(from_pos.y, h2omes.nether_ceiling, h2omes.nether_floor) then
return false
end
end
if h2omes.have_hell then
if is_inside(from_pos.y, h2omes.hell_ceiling, h2omes.hell_floor) and not is_inside(to_pos.y, h2omes.hell_ceiling, h2omes.hell_floor) then
return false
elseif is_inside(to_pos.y, h2omes.hell_ceiling, h2omes.hell_floor) and not is_inside(from_pos.y, h2omes.hell_ceiling, h2omes.hell_floor) then
return false
end
end
return true
end
--function set_homes
function h2omes.set_home(name, home_type)
h2omes.check(name)
local player = minetest.get_player_by_name(name)
if not player then return false end
local pos = player:get_pos()
if not pos then return false end
if pos.y < -19600 and h2omes.have_nether then
if h2omes.have_nether and is_inside(pos.y, h2omes.nether_ceiling, h2omes.nether_floor) then
h2omes.homes[name][home_type].nether = pos
elseif h2omes.have_hell and is_inside(pos.y, h2omes.hell_ceiling, h2omes.hell_floor) then
h2omes.homes[name][home_type].hell = pos
else
h2omes.homes[name][home_type].real = pos
end
minetest.chat_send_player(name, home_type.." set!")
if home_type == "home" then
minetest.chat_send_player(name, S("Home set!"))
else
minetest.chat_send_player(name, S("Pit set!"))
end
minetest.sound_play("dingdong", {to_player = name, gain = 1.0})
h2omes.save_homes(name)
return true
@ -109,9 +155,13 @@ function h2omes.get_home(name, home_type)
local pos = player:get_pos()
if not pos then return nil end
local status = "real"
if pos.y < -19600 and h2omes.have_nether then
if h2omes.have_nether and is_inside(pos.y, h2omes.nether_ceiling, h2omes.nether_floor) then
status = "nether"
end
elseif h2omes.have_hell and is_inside(pos.y, h2omes.hell_ceiling, h2omes.hell_floor) then
status = "hell"
end
if h2omes.homes[name][home_type][status] then
return h2omes.homes[name][home_type][status]
end
@ -125,10 +175,20 @@ function h2omes.getspawn(name)
local pos = player:get_pos()
if not pos then return nil end
local spawn_pos
if pos.y < -19600 and h2omes.have_nether then
if h2omes.have_nether and is_inside(pos.y, h2omes.nether_ceiling, h2omes.nether_floor) then
spawn_pos = minetest.string_to_pos(minetest.settings:get("nether_static_spawnpoint") or "")
elseif minetest.setting_get_pos("static_spawnpoint") then
spawn_pos = minetest.setting_get_pos("static_spawnpoint")
if spawn_pos and not is_inside(spawn_pos.y, h2omes.nether_ceiling, h2omes.nether_floor) then
minetest.log("error","[h2omes] nether_static_spawnpoint is not in nether, fix in minetest.conf.")
return nil
end
elseif h2omes.have_hell and is_inside(pos.y, h2omes.hell_ceiling, h2omes.hell_floor) then
spawn_pos = minetest.string_to_pos(minetest.settings:get("hell_static_spawnpoint") or "")
if spawn_pos and not is_inside(spawn_pos.y, h2omes.hell_ceiling, h2omes.hell_floor) then
minetest.log("error","[h2omes] hell_static_spawnpoint is not in hell, fix in minetest.conf.")
return nil
end
else
spawn_pos = minetest.string_to_pos(minetest.settings:get("static_spawnpoint") or "")
end
return spawn_pos
end
@ -140,13 +200,13 @@ function h2omes.to_spawn(name)
if not player then return false end
local spawn_pos = h2omes.getspawn(name)
if spawn_pos then
minetest.chat_send_player(name, "Teleporting to spawn...")
minetest.chat_send_player(name, S("Teleporting to spawn..."))
player:set_pos(spawn_pos)
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!")
minetest.chat_send_player(name, S("ERROR: No spawn point is set on this server!"))
return false
end
end
@ -160,12 +220,15 @@ function h2omes.to_home(name, home_type)
local pos = player:get_pos()
if not pos then return false end
local status = "real"
if pos.y < -19600 and h2omes.have_nether then
if h2omes.have_nether and is_inside(pos.y, h2omes.nether_ceiling, h2omes.nether_floor) then
status = "nether"
elseif h2omes.have_hell and is_inside(pos.y, h2omes.hell_ceiling, h2omes.hell_floor) then
status = "hell"
end
if h2omes.homes[name][home_type][status] then
player:set_pos(h2omes.homes[name][home_type][status])
minetest.chat_send_player(name, "Teleported to "..home_type.."!")
minetest.chat_send_player(name, S("Teleported to @1!", home_type))
minetest.sound_play("teleport", {to_player=name, gain = 1.0})
return true
end
@ -180,16 +243,16 @@ function h2omes.to_player(name, to_pos, to_name)
local from_pos = player:get_pos()
if to_pos then
if h2omes.can_teleport(from_pos, to_pos) then
minetest.chat_send_player(name, "Teleporting to player "..to_name)
minetest.chat_send_player(name, S("Teleporting to player @1", to_name))
player:set_pos(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!")
minetest.chat_send_player(name, S("Sorry, teleport between 2 worlds is not allowed!"))
return false
end
else
minetest.chat_send_player(name, "ERROR: No position to player!")
minetest.chat_send_player(name, S("ERROR: No position to player!"))
return false
end
end
@ -197,7 +260,7 @@ 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.chat_send_player(name, S("@1 sent you their position to teleport.", from_name))
minetest.sound_play("dingdong", {to_player = name, gain = 0.8})
return true
end
@ -207,7 +270,7 @@ 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)
minetest.chat_send_player(name, S("Your position has been sent to @1.", to_name))
return true
else
minetest.chat_send_player(name, "Error: "..to_name.." already received a request. please try again later.")
@ -222,52 +285,52 @@ function h2omes.show_formspec_home(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 formspec = {"size[8,9]label[3,0;".. S("Home Settings") .."]"}
local pos = player:get_pos()
--spawn
table.insert(formspec, "label[3.45,0.8;TO SPAWN]")
table.insert(formspec, "label[3.35,0.8;".. S("TO SPAWN") .."]")
local spawn_pos = h2omes.getspawn(name)
if 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]")
table.insert(formspec, "button_exit[6,1.1;2,1;to_spawn;".. S("To Spawn") .."]")
else
table.insert(formspec, "label[3.3,1.3;No spawn set]")
table.insert(formspec, "label[2.9,1.3;".. S("No spawn set") .."]")
end
--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]")
table.insert(formspec, "label[3.5,2.1;".. S("TO HOME") .."]")
table.insert(formspec, "button[0,2.4;2,1;set_home;".. S("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]")
table.insert(formspec, "button_exit[6,2.4;2,1;to_home;".. S("To Home") .."]")
else
table.insert(formspec, "label[3.3,2.5;Home no set]")
table.insert(formspec, "label[2.9,2.5;".. S("Home no set") .."]")
end
--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]")
table.insert(formspec, "label[3.55,3.4;".. S("TO PIT") .."]")
table.insert(formspec, "button[0,3.7;2,1;set_pit;".. S("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]")
table.insert(formspec, "button_exit[6,3.7;2,1;to_pit;".. S("To Pit") .."]")
else
table.insert(formspec, "label[3.3,3.8;Pit no set]")
table.insert(formspec, "label[2.9,3.8;".. S("Pit no set") .."]")
end
--to player
table.insert(formspec, "label[3.35,4.7;TO PLAYER]")
table.insert(formspec, "label[3.35,4.7;".. S("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, "label[0,5.1;".. S("To @1", 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]")
table.insert(formspec, "button_exit[6,5;2,1;to_player;".. S("To Player") .."]")
else
table.insert(formspec, "label[2.7,5.1;No request from player]")
table.insert(formspec, "label[2.7,5.1;".. S("No request from player") .."]")
end
table.insert(formspec, "label[2.8,6;SEND MY POS TO PLAYER]")
table.insert(formspec, "label[2,6;".. S("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 = {}
@ -281,16 +344,16 @@ function h2omes.show_formspec_home(name)
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]")
table.insert(formspec, "label[2.5,6.4;".. S("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.."]")
table.insert(formspec,"button[3,6.4;2,1;refresh;".. S("Refresh") .."]")
table.insert(formspec, "dropdown[0,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]")
table.insert(formspec, "button_exit[6,6.4;2,1;send_to;".. S("Send To") .."]")
end
table.insert(formspec, "button_exit[3.25,8.3;1.5,1;close;Close]")
table.insert(formspec, "button_exit[3.25,8.3;2,1;close;".. S("Close") .."]")
minetest.show_formspec(name, "h2omes:formspec", table.concat(formspec))
end
@ -360,27 +423,27 @@ minetest.register_on_leaveplayer(function(player)
end)
minetest.register_privilege("home", "Can use /sethome, /home, /setpit and /pit")
minetest.register_privilege("home", S("Can use /sethome, /home, /setpit and /pit"))
minetest.register_chatcommand("spawn", {
description = "Teleport a player to the defined spawnpoint",
description = S("Teleport a player to the defined spawnpoint"),
func = function(name)
local spawn_pos = h2omes.getspawn(name)
if spawn_pos then
action_timers.wrapper(name, "spawn", "tospawn_" .. name, h2omes.time_spawn, h2omes.to_spawn, {name})
else
minetest.chat_send_player(name, "ERROR: No spawn point is set on this server!")
minetest.chat_send_player(name, S("ERROR: No spawn point is set on this server!"))
return false
end
end
})
minetest.register_chatcommand("home", {
description = "Teleport you to your home point",
description = S("Teleport you to your home point"),
privs = {home = true},
func = function (name, params)
if not h2omes.get_home(name, "home") then
minetest.chat_send_player(name, "Set a home using /sethome")
minetest.chat_send_player(name, S("Set a home using /sethome"))
return false
end
--h2omes.to_home(name, "home")
@ -390,7 +453,7 @@ minetest.register_chatcommand("home", {
minetest.register_chatcommand("sethome", {
description = "Set your home point",
description = S("Set your home point"),
privs = {home = true},
func = function (name, params)
--h2omes.set_home(name, "home")
@ -400,11 +463,11 @@ minetest.register_chatcommand("sethome", {
minetest.register_chatcommand("pit", {
description = "Teleport you to your pit point",
description = S("Teleport you to your pit point"),
privs = {home = true},
func = function (name, params)
if not h2omes.get_home(name, "pit") then
minetest.chat_send_player(name, "Set a pit using /setpit")
minetest.chat_send_player(name, S("Set a pit using /setpit"))
return false
end
--h2omes.to_home(name, "pit")
@ -414,7 +477,7 @@ minetest.register_chatcommand("pit", {
minetest.register_chatcommand("setpit", {
description = "Set your pit point",
description = S("Set your pit point"),
privs = {home = true},
func = function (name, params)
--h2omes.set_home(name, "pit")
@ -423,7 +486,7 @@ minetest.register_chatcommand("setpit", {
})
minetest.register_chatcommand("homegui", {
description = "Show home formspec",
description = S("Show home menu"),
privs = {home = true},
func = function (name, params)
h2omes.show_formspec_home(name)
@ -434,7 +497,7 @@ if (minetest.get_modpath("unified_inventory")) then
unified_inventory.register_button("home_formspec", {
type = "image",
image = "h2omes_home.png",
tooltip = "My Home",
tooltip = S("My Home"),
show_with = "home",
action = function(player)
local name = player:get_player_name()

46
locale/h2omes.fr.tr Normal file
View File

@ -0,0 +1,46 @@
# textdomain: h2omes
### init.lua ###
Home set!=Maison définie!
Pit set!=Mine définie!
Teleporting to spawn...=Téléportation vers spawn...
ERROR: No spawn point is set on this server!=ERREUR : Aucun spawn n'est défini sur ce serveur!
Teleported to @1!=Téléporté vers @1!
Teleporting to player @1=Téléportation vers joueur @1
Sorry, teleport between 2 worlds is not allowed!=Désolé, la téléportation entre 2 mondes n'est pas autorisée!
ERROR: No position to player!=ERREUR : Aucune position vers le joueur!
@1 sent you their position to teleport.=@1 vous a envoyé sa position pour vous téléporter.
Your position has been sent to @1.=Votre position a été envoyée à @1.
Home Settings=Paramètres de home
TO SPAWN=AU SPAWN
To Spawn=Au spawn
No spawn set=Pas de spawn défini
TO HOME=À MAISON
Set Home=Définir Maison
To Home=À maison
Home no set=Pas de maison définie
TO PIT=À MINE
Set Pit=Définir Mine
To Pit=À la Mine
Pit no set=Pas de mine définie
TO PLAYER=À JOUEUR
To @1=Vers @1
To Player=Vers joueur
No request from player=Aucune demande de joueur
SEND MY POS TO PLAYER=ENVOYER MA POSITION AU JOUEUR
No player, try later=Aucun joueur, essayez plus tard
Refresh=Actualiser
Send To=Envoyer à
Close=Fermer
Can use /sethome, /home, /setpit and /pit=Peut utiliser /sethome, /home, /setpit et /pit
Teleport a player to the defined spawnpoint=Téléporte un joueur vers spawn défini
Teleport you to your home point=Vous téléporter à votre maison
Set a home using /sethome=Définir une maison en utilisant /sethome
Set your home point=Définissez votre maison
Teleport you to your pit point=Vous téléporter à votre mine
Set a pit using /setpit=Définir une mine en utilisant /setpit
Set your pit point=Définissez votre mine
Show home menu=Afficher le menu home
My Home=Ma maison

46
locale/mytemplate.txt Normal file
View File

@ -0,0 +1,46 @@
# textdomain: h2omes
### init.lua ###
Home set!=
Pit set!=
Teleporting to spawn...=
ERROR: No spawn point is set on this server!=
Teleported to @1!=
Teleporting to player @1=
Sorry, teleport between 2 worlds is not allowed!=
ERROR: No position to player!=
@1 sent you their position to teleport.=
Your position has been sent to @1.=
Home Settings=
TO SPAWN=
To Spawn=
No spawn set=
TO HOME=
Set Home=
To Home=
Home no set=
TO PIT=
Set Pit=
To Pit=
Pit no set=
TO PLAYER=
To @1=
To Player=
No request from player=
SEND MY POS TO PLAYER=
No player, try later=
Refresh=
Send To=
Close=
Can use /sethome, /home, /setpit and /pit=
Teleport a player to the defined spawnpoint=
Teleport you to your home point=
Set a home using /sethome=
Set your home point=
Teleport you to your pit point=
Set a pit using /setpit=
Set your pit point=
Show home menu=
My Home=

View File

@ -1,4 +1,4 @@
name = h2omes
depends = default, action_timers
optional_depends = unified_inventory, nether
optional_depends = unified_inventory, nether, hell
description = This mod add teleportation to spawn, 2 homes and to players.