home/ (Limits)

Post Reply
Tumblebug
New member
Posts: 5
Joined: Mon Feb 07, 2022 17:35

home/ (Limits)

by Tumblebug » Post

Would like to set a limit of nodes (restricting /home) happening from a prior /sethome pos. I don't have the programming knowledge to modify the Lua sethome file.
Thanks

User avatar
Mantar
Member
Posts: 590
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: home/ (Limits)

by Mantar » Post

Try adding the middle part (starting with local oldpos) here to sethome/init.lua so it looks like this:

Code: Select all

sethome.set = function(name, pos)
	local player = minetest.get_player_by_name(name)
	if not player or not pos then
		return false
	end

	local oldpos = minetest.string_to_pos(player:get_attribute("sethome:home"))
	if vector.distance(oldpos, pos) > 2000 then
	   minetest.chat_send_player(name, "You are too far from your previous home")
	   return false
	end

	player:set_attribute("sethome:home", minetest.pos_to_string(pos))
This is untested, but ought to work. If the distance between the two is greater than 2000 nodes, it cancels the sethome and tells the player it's too far away.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

Tumblebug
New member
Posts: 5
Joined: Mon Feb 07, 2022 17:35

Re: home/ (Limits)

by Tumblebug » Post

I like the sethome/home option in a game, yet didn't much care for digging a hole and just jumping out. Sort of easy for stupid. Thank you.
Doesn't work as I intend yet have time to continue figuring...

User avatar
Mantar
Member
Posts: 590
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: home/ (Limits)

by Mantar » Post

Oh you wanted to keep the player from using /home past a certain distance, I misunderstood and thought you wanted to prevent /sethome. Easy fix! We just move our distance check down to the sethome.go function instead:

Code: Select all

sethome.go = function(name)
	local pos = sethome.get(name)
	local player = minetest.get_player_by_name(name)

	local oldpos = player:get_pos()
	if pos and vector.distance(oldpos, pos) > 2000 then
	   minetest.chat_send_player(name, "You are too far from your previous home")
	   return false
	end

	if player and pos then
		player:set_pos(pos)
		return true
	end
	return false
end
Added an "if pos" on the front because if there's no home set for this player, it will be a nil value. I think vector.distance might handle that okay, but it's usually best to just skip doing anything if you've got a nil value, passing it to the wrong function can cause crashes.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

Tumblebug
New member
Posts: 5
Joined: Mon Feb 07, 2022 17:35

Re: home/ (Limits)

by Tumblebug » Post

Yes, correct. I'm thinking better to restrict the "home" command operating, unless that person is within/near the spawn area. How much trouble figuring that one?
My apology for my lack of being precise.

User avatar
Mantar
Member
Posts: 590
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: home/ (Limits)

by Mantar » Post

No trouble there, just figure out the "spawn area" center's coordinates, then set "oldpos" to be that in { x = 0, y = 0, z = 0} format. Now you can't /sethome more than 2000 nodes from the center of spawn. Adjust range as desired.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

Tumblebug
New member
Posts: 5
Joined: Mon Feb 07, 2022 17:35

Re: home/ (Limits)

by Tumblebug » Post

All the modifications been looking into... Just now realized using "sethome/home" in the mod unified_inventory doesn't effect the "sethome" of minetest_game/mods/sethome. Two different sets.
Has anyone ever mentioned linking the two mods to work in union?

c56
Member
Posts: 307
Joined: Wed Apr 21, 2021 03:05
GitHub: tigercoding56
In-game: bm5 or bemo5 also sell_her_on55

Re: home/ (Limits)

by c56 » Post

Tumblebug wrote:
Sat Feb 12, 2022 00:29
All the modifications been looking into... Just now realized using "sethome/home" in the mod unified_inventory doesn't effect the "sethome" of minetest_game/mods/sethome. Two different sets.
Has anyone ever mentioned linking the two mods to work in union?

most people enjoy having 2 home positions 3 home positions would be even better i wish for 26 home positions but why stop there100 no 9999 better yet INFINITY HOME POSITIONS:D
this is a signature not a place to post messages also if i could change my username i would change it to sell_her_on55

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests