Skip to content

Commit c5c609c

Browse files
beyondlimitsest31
authored andcommittedJul 18, 2015
Add ability to specify coordinates for /spawnentity
1 parent dd2e08e commit c5c609c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed
 

Diff for: ‎builtin/game/chatcommands.lua

+13-6
Original file line numberDiff line numberDiff line change
@@ -530,22 +530,29 @@ core.register_chatcommand("giveme", {
530530
})
531531

532532
core.register_chatcommand("spawnentity", {
533-
params = "<EntityName>",
534-
description = "Spawn entity at your position",
533+
params = "<EntityName> [<X>,<Y>,<Z>]",
534+
description = "Spawn entity at given (or your) position",
535535
privs = {give=true, interact=true},
536536
func = function(name, param)
537-
local entityname = string.match(param, "(.+)$")
537+
local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
538538
if not entityname then
539539
return false, "EntityName required"
540540
end
541-
core.log("action", ("/spawnentity invoked, entityname=%q")
542-
:format(entityname))
541+
core.log("action", ("%s invokes /spawnentity, entityname=%q")
542+
:format(name, entityname))
543543
local player = core.get_player_by_name(name)
544544
if player == nil then
545545
core.log("error", "Unable to spawn entity, player is nil")
546546
return false, "Unable to spawn entity, player is nil"
547547
end
548-
local p = player:getpos()
548+
if p == "" then
549+
p = player:getpos()
550+
else
551+
p = core.string_to_pos(p)
552+
if p == nil then
553+
return false, "Invalid parameters ('" .. param .. "')"
554+
end
555+
end
549556
p.y = p.y + 1
550557
core.add_entity(p, entityname)
551558
return true, ("%q spawned."):format(entityname)

0 commit comments

Comments
 (0)
Please sign in to comment.