]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/game/chatcommands.lua
Small fixes of minetest.has_feature
[dragonfireclient.git] / builtin / game / chatcommands.lua
index d656f1c9172029b5fa0b3ef0f39bc7840ce708d4..5d317de4b870289c91db5b39e258f28138d25566 100644 (file)
@@ -10,6 +10,7 @@ function core.register_chatcommand(cmd, def)
        def.params = def.params or ""
        def.description = def.description or ""
        def.privs = def.privs or {}
+       def.mod_origin = core.get_current_modname() or "??"
        core.chatcommands[cmd] = def
 end
 
@@ -37,6 +38,7 @@ core.register_on_chat_message(function(name, message)
        end
        local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
        if has_privs then
+               core.set_last_run_mod(cmd_def.mod_origin)
                local success, message = cmd_def.func(name, param)
                if message then
                        core.chat_send_player(name, message)
@@ -530,22 +532,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)