Better sethome!
This commit is contained in:
parent
a2866722ca
commit
a132fadacd
@ -158,7 +158,7 @@ local function cmd_kits(name, param, splitparams)
|
||||
for kit in pairs(kits_cache) do
|
||||
local perms = true
|
||||
if kit_privs then
|
||||
perms = ess.priv_match(name, "ess.kits.kit." .. kit) or ess.priv_match(name, "ess.kits.all")
|
||||
perms = ess.priv_match(name, "ess.kits.kit." .. kit) or ess.priv_match(name, "ess.kits.kits.all")
|
||||
end
|
||||
|
||||
if perms then
|
||||
@ -172,7 +172,7 @@ end
|
||||
local commands = {
|
||||
["kits"] = {
|
||||
description = "Give or list available kits",
|
||||
params = "( (delete | create) <kit> [<timeout>] ) | ( [<kit>] [<playername>] )",
|
||||
params = "(delete|create) <kit> [<timeout>] | [<kit>] [<playername>]",
|
||||
aliases = {"kit"},
|
||||
privs = {
|
||||
["ess.kits.kits"] = true,
|
||||
@ -203,8 +203,6 @@ local commands = {
|
||||
|
||||
ess.autoregister(commands, "kits")
|
||||
|
||||
local loaded = false
|
||||
|
||||
if kit_give ~= "" then
|
||||
minetest.register_on_newplayer(function(player)
|
||||
give_kit(player, kit_give)
|
||||
|
185
sethome/init.lua
Normal file
185
sethome/init.lua
Normal file
@ -0,0 +1,185 @@
|
||||
-- sethome override for Icy Essentials with multi-home support
|
||||
|
||||
local maxhomes = tonumber(minetest.settings:get("sethome_count")) or 3
|
||||
local bedhome = minetest.settings:get_bool("sethome_bed", true)
|
||||
local homerespawn = minetest.settings:get_bool("sethome_respawn", false)
|
||||
|
||||
sethome = ess.register_module("home", "Homes")
|
||||
|
||||
sethome.set = function(name, pos, target)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player or not pos then
|
||||
return false, "Player not found!"
|
||||
end
|
||||
|
||||
if not target or target == "" then target = "home" end
|
||||
|
||||
local homes = ess.get_player_meta(name, "homes")
|
||||
if not homes then homes = {} end
|
||||
|
||||
local count = 0
|
||||
for i in pairs(homes) do
|
||||
if i ~= "bed" then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
if count >= maxhomes and maxhomes ~= 0 and not ess.priv_match(name, "home.multiple") and target ~= "bed" then
|
||||
return false, string.format("You don't have permission to set more than %d homes.", maxhomes)
|
||||
end
|
||||
|
||||
homes[target:lower()] = pos
|
||||
ess.set_player_meta(name, "homes", homes)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
sethome.get = function(name, target)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
if not target or target == "" then target = "home" end
|
||||
|
||||
local homes = ess.get_player_meta(name, "homes")
|
||||
if not homes then return false end
|
||||
local targ = homes[target:lower()]
|
||||
if not targ and target == "home" and homes["bed"] then
|
||||
targ = homes["bed"]
|
||||
target = "bed"
|
||||
end
|
||||
|
||||
if not targ then
|
||||
return nil
|
||||
end
|
||||
|
||||
return targ, target
|
||||
end
|
||||
|
||||
sethome.go = function(name,point)
|
||||
local pos, target = sethome.get(name,point)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
|
||||
if player and pos then
|
||||
ess.save_player_pos(player)
|
||||
player:set_pos(pos)
|
||||
return true, target
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function cmd_home(name, params, splitparams)
|
||||
local target = splitparams[1]
|
||||
if not target or target == "" then
|
||||
target = "home"
|
||||
end
|
||||
|
||||
local went, name = sethome.go(name, target)
|
||||
|
||||
if went then
|
||||
return true, string.format("Teleported to %s!", name)
|
||||
end
|
||||
|
||||
return false, string.format("Home \"%s\" does not exist.", target)
|
||||
end
|
||||
|
||||
local function cmd_set(name, params, splitparams)
|
||||
local target = splitparams[1]
|
||||
if not target or target == "" then
|
||||
target = "home"
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local success, err = sethome.set(name, player:get_pos(), target)
|
||||
|
||||
if player and success then
|
||||
return true, string.format("Home \"%s\" set!", target)
|
||||
end
|
||||
|
||||
return false, err
|
||||
end
|
||||
|
||||
local function cmd_del(name, params, splitparams)
|
||||
local target = splitparams[1]
|
||||
if not target or target == "" then target = "home" end
|
||||
|
||||
local homes = ess.get_player_meta(name, "homes")
|
||||
if not homes then homes = {} end
|
||||
homes[target:lower()] = nil
|
||||
ess.set_player_meta(name, "homes", homes)
|
||||
|
||||
return true, string.format("Home \"%s\" deleted successfully.", target)
|
||||
end
|
||||
|
||||
local function cmd_list(name, params, splitparams)
|
||||
local target = splitparams[1]
|
||||
if not target or target == "" then target = "home" end
|
||||
|
||||
local homes = ess.get_player_meta(name, "homes")
|
||||
if not homes then homes = {} end
|
||||
|
||||
local names = {}
|
||||
for i in pairs(homes) do
|
||||
table.insert(names, i)
|
||||
end
|
||||
|
||||
return true, "Homes: " .. table.concat( names, ", " )
|
||||
end
|
||||
|
||||
sethome.register_chatcommand("home", {
|
||||
description = "Teleport you to your home point",
|
||||
params = "[<name>]",
|
||||
privs = {
|
||||
home = true,
|
||||
["home.all"] = true,
|
||||
},
|
||||
func = cmd_home,
|
||||
})
|
||||
|
||||
sethome.register_chatcommand("homes", {
|
||||
description = "List your home points",
|
||||
privs = {
|
||||
home = true,
|
||||
["home.all"] = true,
|
||||
},
|
||||
func = cmd_list,
|
||||
})
|
||||
|
||||
sethome.register_chatcommand("sethome", {
|
||||
description = "Set your home point",
|
||||
params = "[<name>]",
|
||||
privs = {
|
||||
home = true,
|
||||
["home.all"] = true,
|
||||
["home.multiple"] = true,
|
||||
},
|
||||
func = cmd_set,
|
||||
})
|
||||
|
||||
sethome.register_chatcommand("delhome", {
|
||||
description = "Delete your home point",
|
||||
params = "[<name>]",
|
||||
privs = {
|
||||
home = true,
|
||||
["home.all"] = true,
|
||||
},
|
||||
func = cmd_del,
|
||||
})
|
||||
|
||||
if bedhome and minetest.get_modpath("beds") ~= nil and beds ~= nil then
|
||||
local rclick = beds.on_rightclick
|
||||
beds.on_rightclick = function (pos,player)
|
||||
local name = player:get_player_name()
|
||||
rclick(pos,player)
|
||||
|
||||
local success = sethome.set(name, pos, "bed")
|
||||
if success then
|
||||
minetest.chat_send_player(name, "Bed spawnpoint set!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if homerespawn then
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
return sethome.go(player:get_player_name())
|
||||
end)
|
||||
end
|
4
sethome/mod.conf
Normal file
4
sethome/mod.conf
Normal file
@ -0,0 +1,4 @@
|
||||
name = sethome
|
||||
description = sethome override for Icy Essentials with multi-home support
|
||||
depends = ess_core
|
||||
optional_depends = beds
|
7
sethome/settingtypes.txt
Normal file
7
sethome/settingtypes.txt
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
# Privilege home.multiple overrides this. Set to 0 to allow infinite amount.
|
||||
sethome_count (Maximum allowed homes per player) int 3
|
||||
|
||||
sethome_bed (Automatically set bed home point) bool true
|
||||
|
||||
sethome_respawn (Respawn at home) bool false
|
Loading…
Reference in New Issue
Block a user