@@ -530,22 +530,29 @@ core.register_chatcommand("giveme", {
530
530
})
531
531
532
532
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" ,
535
535
privs = {give = true , interact = true },
536
536
func = function (name , param )
537
- local entityname = string.match (param , " (.+ )$" )
537
+ local entityname , p = string.match (param , " ^([^ ]+) *(.* )$" )
538
538
if not entityname then
539
539
return false , " EntityName required"
540
540
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 ))
543
543
local player = core .get_player_by_name (name )
544
544
if player == nil then
545
545
core .log (" error" , " Unable to spawn entity, player is nil" )
546
546
return false , " Unable to spawn entity, player is nil"
547
547
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
549
556
p .y = p .y + 1
550
557
core .add_entity (p , entityname )
551
558
return true , (" %q spawned." ):format (entityname )
0 commit comments