Update builtin

This commit is contained in:
MoNTE48 2019-06-21 23:30:40 +02:00
parent 9a65213458
commit a51369d706
5 changed files with 58 additions and 56 deletions

View File

@ -82,7 +82,7 @@ core.register_chatcommand("me", {
core.register_chatcommand("admin", { core.register_chatcommand("admin", {
description = "Show the name of the server owner", description = "Show the name of the server owner",
func = function(name) func = function(name)
local admin = minetest.settings:get("name") local admin = core.settings:get("name")
if admin then if admin then
return true, "The administrator of this server is "..admin.."." return true, "The administrator of this server is "..admin.."."
else else
@ -104,7 +104,7 @@ core.register_chatcommand("privs", {
}) })
local function handle_grant_command(caller, grantname, grantprivstr) local function handle_grant_command(caller, grantname, grantprivstr)
local caller_privs = minetest.get_player_privs(caller) local caller_privs = core.get_player_privs(caller)
if not (caller_privs.privs or caller_privs.basic_privs) then if not (caller_privs.privs or caller_privs.basic_privs) then
return false, "Your privileges are insufficient." return false, "Your privileges are insufficient."
end end
@ -969,43 +969,47 @@ core.register_chatcommand("clearinv", {
end, end,
}) })
minetest.register_chatcommand("killme", { local function handle_kill_command(killer, victim)
description = "Kill yourself to respawn", if core.settings:get_bool("enable_damage") == false then
func = function(name) return false, "Players can't be killed, damage has been disabled."
local player = minetest.get_player_by_name(name) end
if player then local victimref = core.get_player_by_name(victim)
if minetest.settings:get_bool("enable_damage") then if victimref == nil then
player:set_hp(0) return false, string.format("Player %s is not online.", victim)
return true elseif victimref:get_hp() <= 0 then
if killer == victim then
return false, "You are already dead."
else else
for _, callback in pairs(core.registered_on_respawnplayers) do return false, string.format("%s is already dead.", victim)
if callback(player) then
return true
end end
end end
if not killer == victim then
core.log("action", string.format("%s killed %s", killer, victim))
end
-- Kill victim
victimref:set_hp(0)
return true, string.format("%s has been killed.", victim)
end
-- There doesn't seem to be a way to get a default spawn pos from the lua API core.register_chatcommand("kill", {
return false, "No static_spawnpoint defined" params = "[<name>]",
end description = "Kill player or yourself",
else privs = {server=true},
-- Show error message if used when not logged in, eg: from IRC mod func = function(name, param)
return false, "You need to be online to be killed!" return handle_kill_command(name, param == "" and name or param)
end end,
end
}) })
local spawn_spawnpos = minetest.setting_get_pos("static_spawnpoint") core.register_chatcommand("spawn", {
minetest.register_chatcommand("spawn", {
params = "", params = "",
description = "Teleport to the spawn point", description = "Teleport to the spawn point",
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = core.get_player_by_name(name)
if not player then if not player then
return false, "Player not found" return false, "Command called by invalid player"
end end
if spawn_spawnpos then if core.setting_get_pos("static_spawnpoint") then
player:set_pos(spawn_spawnpos) player:set_pos(core.setting_get_pos("static_spawnpoint"))
return true, "Teleporting to spawn..." return true, "Teleporting to spawn..."
else else
return false, "The spawn point is not set!" return false, "The spawn point is not set!"
@ -1013,24 +1017,22 @@ minetest.register_chatcommand("spawn", {
end, end,
}) })
minetest.register_chatcommand("setspawn", { core.register_chatcommand("setspawn", {
params = "", params = "",
description = "Sets the spawn point to your current position", description = "Sets the spawn point to your current position",
privs = {server = true}, privs = {server = true},
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = core.get_player_by_name(name)
if not player then if not player then
return false, "Player not found" return false, "Command called by invalid player"
end end
local pos = player:get_pos() local pos = vector.round(player:get_pos())
local x = math.floor(pos.x) local x = pos.x
local y = math.floor(pos.y) local y = pos.y
local z = math.floor(pos.z) local z = pos.z
local pos_string = x..","..y..","..z local pos_to_string = x..","..y..","..z
local pos_string_2 = "Setting spawn point to ("..x..", "..y..", "..z..")" core.setting_set("static_spawnpoint", pos_to_string)
minetest.setting_set("static_spawnpoint", pos_string) core.setting_save()
spawn_spawnpos = pos return true, "Setting spawn point to ("..x..", "..y..", "..z..")"
minetest.setting_save()
return true, pos_string_2
end, end,
}) })

View File

@ -24,7 +24,7 @@ local sb_bg = {} -- statbar background ids
local items = {} local items = {}
local function throw_error(msg) local function throw_error(msg)
minetest.log("error", "HUD[error]: " .. msg) core.log("error", "HUD[error]: " .. msg)
end end
-- --
@ -156,7 +156,7 @@ local function add_hud_item(player, name, def)
hud_id[i_name].id = player:hud_add(def) hud_id[i_name].id = player:hud_add(def)
end end
minetest.register_on_joinplayer(function(player) core.register_on_joinplayer(function(player)
-- add the backgrounds for statbars -- add the backgrounds for statbars
for _,item in pairs(sb_bg) do for _,item in pairs(sb_bg) do
add_hud_item(player, _.."_bg", item) add_hud_item(player, _.."_bg", item)

View File

@ -579,9 +579,9 @@ function core.item_eat(hp_change, replace_with_item)
local pos = user:get_pos() local pos = user:get_pos()
pos.y = pos.y + 1.5 pos.y = pos.y + 1.5
local itemname = itemstack:get_name() local itemname = itemstack:get_name()
local texture = minetest.registered_items[itemname].inventory_image local texture = core.registered_items[itemname].inventory_image
minetest.sound_play("player_eat", {pos = pos, max_hear_distance = 10, gain = 0.3}) core.sound_play("player_eat", {pos = pos, max_hear_distance = 10, gain = 0.3})
minetest.add_particlespawner({ core.add_particlespawner({
amount = 20, amount = 20,
time = 0.1, time = 0.1,
minpos = {x = pos.x, y = pos.y, z = pos.z}, minpos = {x = pos.x, y = pos.y, z = pos.z},

View File

@ -228,14 +228,14 @@ core.register_entity(":__builtin:item", {
end end
end end
local node = minetest.get_node_or_nil(self.object:get_pos()) local node = core.get_node_or_nil(self.object:get_pos())
if not node then if not node then
return return
end end
if minetest.get_item_group(node.name, "lava") > 0 then if core.get_item_group(node.name, "lava") > 0 then
minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 10}) core.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 10})
self.object:remove() self.object:remove()
minetest.add_particlespawner({ core.add_particlespawner({
amount = 3, amount = 3,
time = 0.1, time = 0.1,
minpos = {x = pos.x - 0.1, y = pos.y + 0.1, z = pos.z - 0.1 }, minpos = {x = pos.x - 0.1, y = pos.y + 0.1, z = pos.z - 0.1 },

View File

@ -44,7 +44,7 @@ local player_list = {}
core.register_on_joinplayer(function(player) core.register_on_joinplayer(function(player)
local player_name = player:get_player_name() local player_name = player:get_player_name()
player_list[player_name] = player player_list[player_name] = player
if not minetest.is_singleplayer() then if not core.is_singleplayer() then
core.chat_send_all("=> " .. player_name .. " has joined the server") core.chat_send_all("=> " .. player_name .. " has joined the server")
end end
end) end)
@ -79,8 +79,8 @@ function core.is_player(player)
end end
function minetest.player_exists(name) function core.player_exists(name)
return minetest.get_auth_handler().get_auth(name) ~= nil return core.get_auth_handler().get_auth(name) ~= nil
end end
-- Returns two position vectors representing a box of `radius` in each -- Returns two position vectors representing a box of `radius` in each
@ -181,7 +181,7 @@ function core.intersects_protection(minp, maxp, player_name, interval)
elseif maxp[c] == minp[c] then elseif maxp[c] == minp[c] then
d[c] = 1 -- Any value larger than 0 to avoid division by zero d[c] = 1 -- Any value larger than 0 to avoid division by zero
else -- maxp[c] < minp[c], print error and treat as protection intersected else -- maxp[c] < minp[c], print error and treat as protection intersected
minetest.log("error", "maxp < minp in 'minetest.intersects_protection()'") core.log("error", "maxp < minp in 'minetest.intersects_protection()'")
return true return true
end end
end end
@ -234,7 +234,7 @@ function core.http_add_fetch(httpenv)
end end
function core.close_formspec(player_name, formname) function core.close_formspec(player_name, formname)
return minetest.show_formspec(player_name, formname, "") return core.show_formspec(player_name, formname, "")
end end
function core.cancel_shutdown_requests() function core.cancel_shutdown_requests()