mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
Add ability to specify coordinates for /spawnentity
This commit is contained in:
parent
dd2e08e117
commit
c5c609ce3d
@ -530,22 +530,29 @@ core.register_chatcommand("giveme", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
core.register_chatcommand("spawnentity", {
|
core.register_chatcommand("spawnentity", {
|
||||||
params = "<EntityName>",
|
params = "<EntityName> [<X>,<Y>,<Z>]",
|
||||||
description = "Spawn entity at your position",
|
description = "Spawn entity at given (or your) position",
|
||||||
privs = {give=true, interact=true},
|
privs = {give=true, interact=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local entityname = string.match(param, "(.+)$")
|
local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
|
||||||
if not entityname then
|
if not entityname then
|
||||||
return false, "EntityName required"
|
return false, "EntityName required"
|
||||||
end
|
end
|
||||||
core.log("action", ("/spawnentity invoked, entityname=%q")
|
core.log("action", ("%s invokes /spawnentity, entityname=%q")
|
||||||
:format(entityname))
|
:format(name, entityname))
|
||||||
local player = core.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
if player == nil then
|
if player == nil then
|
||||||
core.log("error", "Unable to spawn entity, player is nil")
|
core.log("error", "Unable to spawn entity, player is nil")
|
||||||
return false, "Unable to spawn entity, player is nil"
|
return false, "Unable to spawn entity, player is nil"
|
||||||
end
|
end
|
||||||
local p = player:getpos()
|
if p == "" then
|
||||||
|
p = player:getpos()
|
||||||
|
else
|
||||||
|
p = core.string_to_pos(p)
|
||||||
|
if p == nil then
|
||||||
|
return false, "Invalid parameters ('" .. param .. "')"
|
||||||
|
end
|
||||||
|
end
|
||||||
p.y = p.y + 1
|
p.y = p.y + 1
|
||||||
core.add_entity(p, entityname)
|
core.add_entity(p, entityname)
|
||||||
return true, ("%q spawned."):format(entityname)
|
return true, ("%q spawned."):format(entityname)
|
||||||
|
Loading…
Reference in New Issue
Block a user