[question] sfinv modding questions

Post Reply
User avatar
Extex
Member
Posts: 245
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

[question] sfinv modding questions

by Extex » Post

OK so I'm making a mod with a new sfinv inventory page, with two item slots; and I only want items with a specific group to be allowed in these slots.
How would I do this?

Code: Select all

sfinv.register_page("rings:ring_page", {
	title = "Rings",
	get = function(self, player, context)
		return sfinv.make_formspec(player, context,
				"list[current_player;ring_slots;1.75,0.5;1,2;]",
			 true)
	end,
})
And I only want items with the group "ring" to be allowed in the slots
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: [question] sfinv modding questions

by Krock » Post

Extex wrote: I only want items with a specific group to be allowed in these slots.

And I only want items with the group "ring" to be allowed in the slots
First is possible, latter done by the rule given for the first request.

Since Minetest 5.0.0 you can use the callback minetest.register_allow_player_inventory_action to prevent items to be placed in player inventory slots.
Sample code: (untested, use "Quote" function to keep tabulators)

Code: Select all

mminetest.register_allow_player_inventory_action(function(player, action, inv, info)
	if action == "take" then
		return -- Not interesting
	end
	local list = info.to_list or info.listname
	if list ~= "ring_slots" then
		return -- Wrong affected list
	end
	return 0 -- May not put the item into this slot
end)
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Extex
Member
Posts: 245
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

Re: [question] sfinv modding questions

by Extex » Post

OK I have no idea how that function works.
So I just copy pasted, and for some reason both of the slots are just gone

And the content of the slots was shifted to my crafting

I removed it and it still happens
I just get this error

2019-05-25 12:44:47: WARNING[Main]: GUIFormSpecMenu::drawList(): The inventory list "ring_slots" @ "current_player" doesn't exist
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP

User avatar
Extex
Member
Posts: 245
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

Re: [question] sfinv modding questions

by Extex » Post

Oh nvm I figured out what was wrong.
I needed to do it like this

Code: Select all


minetest.register_on_joinplayer(function(player)                                 
    local inv = player:get_inventory()                                           
    inv:set_size("rings", 2)                                              
end)
sfinv.register_page("rings:ring_page", {
	title = "Rings",
	get = function(self, player, context)
	    local formspec = ""..
                "list[current_player;rings;1.75,0.5;1,2;]"..
				""..
				"image[0,4.7;1,1;gui_hb_bg.png]"..
				"image[1,4.7;1,1;gui_hb_bg.png]"..
				"image[2,4.7;1,1;gui_hb_bg.png]"..
				"image[3,4.7;1,1;gui_hb_bg.png]"..
				"image[4,4.7;1,1;gui_hb_bg.png]"..
				"image[5,4.7;1,1;gui_hb_bg.png]"..
				"image[6,4.7;1,1;gui_hb_bg.png]"..
				"image[7,4.7;1,1;gui_hb_bg.png]"
		  return sfinv.make_formspec(player, context, formspec, true)
	end
})
But still can't figure out how to limit it to only items with "ring" group
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests