Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add ability to specify coordinates for /spawnentity
  • Loading branch information
beyondlimits authored and est31 committed Jul 18, 2015
1 parent dd2e08e commit c5c609c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions builtin/game/chatcommands.lua
Expand Up @@ -530,22 +530,29 @@ core.register_chatcommand("giveme", {
})

core.register_chatcommand("spawnentity", {
params = "<EntityName>",
description = "Spawn entity at your position",
params = "<EntityName> [<X>,<Y>,<Z>]",
description = "Spawn entity at given (or your) position",
privs = {give=true, interact=true},
func = function(name, param)
local entityname = string.match(param, "(.+)$")
local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
if not entityname then
return false, "EntityName required"
end
core.log("action", ("/spawnentity invoked, entityname=%q")
:format(entityname))
core.log("action", ("%s invokes /spawnentity, entityname=%q")
:format(name, entityname))
local player = core.get_player_by_name(name)
if player == nil then
core.log("error", "Unable to spawn entity, player is nil")
return false, "Unable to spawn entity, player is nil"
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
core.add_entity(p, entityname)
return true, ("%q spawned."):format(entityname)
Expand Down

0 comments on commit c5c609c

Please sign in to comment.