Is it possible to execute a registered command server sided?
For example I have a functionality that exists within a command in a separate mod. Instead of including the file and depend on it, I just execute this command server sided.
minetest.register_chatcommand("home", {
description = SL(("Teleport you to your home point")),
privs = {home=true},
func = function (name)
local player = minetest.get_player_by_name(name)
if player == nil then
-- just a check to prevent the server crashing
return false
end
if homepos[player:get_player_name()] then
player:setpos(homepos[player:get_player_name()])
minetest.chat_send_player(name, SL("Teleported to home!"))
else
minetest.chat_send_player(name, SL("Set a home using /sethome"))
end
end,
})function execute_home
-- call command home
end
gohome = function (name)
local player = minetest.get_player_by_name(name)
if player == nil then
-- just a check to prevent the server crashing
return false
end
if homepos[player:get_player_name()] then
player:setpos(homepos[player:get_player_name()])
minetest.chat_send_player(name, SL("Teleported to home!"))
else
minetest.chat_send_player(name, SL("Set a home using /sethome"))
end
function execute_home(player)
gohome(player:get_player_name())
end
twoelk wrote:if the command is registered as chat command, can't you just call the command from any other mod by sending it as if typed in chat?
local command_def = minetest.registered_chatcommands["home"]
command_def.func("playername", "other args")
Users browsing this forum: No registered users and 4 guests