How can I set a spawn point?

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

How can I set a spawn point?

by burli » Tue May 31, 2016 06:53

I want to set the spawn point if I rightclick on a node. How can I do this without the bed?
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: How can I set a spawn point?

by azekill_DIABLO » Tue May 31, 2016 07:58

hijack it :)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: How can I set a spawn point?

by burli » Tue May 31, 2016 08:05

azekill_DIABLO wrote:hijack it :)

Well, you are right. I probably hijack the spawn.lua from the bed mod
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

Re: How can I set a spawn point?

by octacian » Thu Jun 02, 2016 15:10

Add the following code to the node:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
on_rightclick = function(name, pos)
local player = minetest.get_player_by_name(name) -- get player
-- make sure it is a valid player
if not player then
return
end
local pos = player:getpos() -- get player position
-- add 0.5 to x and z to make it cooler
pos.x = math.floor(0.5+pos.x)
pos.z = math.floor(0.5+pos.z)
minetest.setting_set("static_spawn", minetest.pos_to_string(pos)) -- save position as a setting
-- notify player in chat
minetest.chat_send_player(name, "Spawn point set at "..minetest.setting_get("static_spawn"));
-- print to log
minetest.log("action", "[ModName] "..name.."'s spawn point set at "..minetest.setting_get("static_spawn"))
end,


Didn't test it, but it should work. You can call the setting static_spawn whatever you want, as long as you change it in all three places. However, remember that this is creating a setting in the minetest.conf file, so it will apply to all worlds and sometimes in servers is somehow cleared. To fix this, you would have to save these settings within a separate file in the world folder, but I don't have any example code at the moment. You also need a function that calls on respawn such as:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_respawnplayer(function(player)
   if not player then
      return
   end
   if minetest.setting_get("static_genesis") == nil or minetest.setting_get("static_genesis") == "" then
      return
   end
   player:setpos(minetest.string_to_pos(minetest.setting_get("static_genesis")))
end)

Once again, that will call for every player which could be an issue. To do this on a player and world basis, I would look at the code for the home command (or beds) as you could probably to copy and paste mostly everything. Also check out my WIP mod Server_Tools which includes a command to set the spawn of the world (which I called genesis, or beginning, point instead). Be careful with what you take from it though, I haven't yet gotten around to fixing any of the problems mentioned, but will soon.
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron