Hello.
While playing I died and couldn't get back to my death location - it was just too far away...
Then I remembered there was a /back command in Minecraft and tried it out -
It didn't work, as expected. So I spent a few hours this afternoon searching the developer wiki etc.
If anyone of you have an idea how to make it, definitely go for it and take this just as inspiration.
Thanks a lot
/back Command
-
- Member
- Posts: 30
- Joined: Fri Jun 24, 2016 10:40
- In-game: kosmonautik
- Location: Czech Republic
- Contact:
- Krock
- Developer
- Posts: 4649
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: /back Command
I think this mod offers something that can help you: viewtopic.php?t=15453
A mod based on your idea would need to register a "on_dieplayer" (or similar) callback. It can be used to get the position of the player given in its function parameter. Then it's just a few lines to add a new chat command to actually set the position of the player. Here's some copypasta material for registering a chat command: https://github.com/minetest/minetest/bl ... #L680-L698
A mod based on your idea would need to register a "on_dieplayer" (or similar) callback. It can be used to get the position of the player given in its function parameter. Then it's just a few lines to add a new chat command to actually set the position of the player. Here's some copypasta material for registering a chat command: https://github.com/minetest/minetest/bl ... #L680-L698
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
-
- Member
- Posts: 30
- Joined: Fri Jun 24, 2016 10:40
- In-game: kosmonautik
- Location: Czech Republic
- Contact:
Re: /back Command
Well I made this and got stuck here:
When the code is like this, when I type /back it says something like "set_pos: expected table got nil"
I then tried:
This time: "set_pos: invalid x coordinate"
Code: Select all
minetest.register_on_dieplayer(function(player)
local pos = player:getpos()
end)
minetest.register_chatcommand("back", {
params = "",
description = "",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
player:setpos(pos)
end
})
I then tried:
Code: Select all
minetest.register_on_dieplayer(function(player)
local pos = player:getpos()
end)
minetest.register_chatcommand("back", {
params = "",
description = "",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
player:setpos({pos})
end
})
Re: /back Command
You'll have to make pos a global variable so it's defined in all the functions and not only the first one. c:kosmonautik wrote:Well I made this and got stuck here:When the code is like this, when I type /back it says something like "set_pos: expected table got nil"Code: Select all
minetest.register_on_dieplayer(function(player) local pos = player:getpos() end) minetest.register_chatcommand("back", { params = "", description = "", func = function(name, param) local player = minetest.get_player_by_name(name) if not player then return false, "Player not found" end player:setpos(pos) end })
Like so:
Code: Select all
local pos
minetest.register_on_dieplayer(function(player)
pos = player:getpos(),
minetest.chat_send_all("died")
end)
minetest.register_chatcommand("back", {
params = "",
description = "",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
if not pos then
return false, "No death position found"
end
player:setpos(pos)
end
})
- ExeterDad
- Member
- Posts: 1717
- Joined: Sun Jun 01, 2014 20:00
- In-game: ExeterDad
- Location: New Hampshire U.S.A
Re: /back Command
make pos local outside of the functions.
Your chat command can't see it as it's local to the register_on_dieplayer function.
Edit: ninja'd
I need to type faster.
Your chat command can't see it as it's local to the register_on_dieplayer function.
Edit: ninja'd
I need to type faster.
HOMETOWN -Our little server. Keep the HOMETOWN chatter @ http://hometownserver.com - Our server map: http://media.hometownserver.com
Who is online
Users browsing this forum: No registered users and 8 guests