[Please help] Limiting lnventory formspec to certain items

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

[Please help] Limiting lnventory formspec to certain items

by Extex » Post

How would I limit an inventory to only items with a certain group in way like 3d armor does?


Code snippet would be great (Credit will be given)
Player of PK, RIP. Creator of the light_tool and motorbike mods. Working on another mod which should be coming soon!

ShadMOrdre
Member
Posts: 679
Joined: Mon Dec 29, 2014 08:07
GitHub: ShadMOrdre
In-game: shadmordre
Location: USA

Re: [Please help] Limiting lnventory formspec to certain ite

by ShadMOrdre » Post

Extex,

You might find a code sample in the smart_inv mod by bell07. I remember this mod grouped items in the inventory.

You can also look at the smart_sfinv mods, also by bell07.

Shad
MY MODS: lib_ecology lib_materials lib_clouds lib_node_shapes ---- Inspired By: Open Source Virtual World Simulator Opensimulator.

matyilona200
Member
Posts: 14
Joined: Sun May 20, 2018 14:41
GitHub: matyilona

Re: [Please help] Limiting lnventory formspec to certain ite

by matyilona200 » Post

I have not used this myself, but default:furnaces in minetest_game seem to use allow_inventory_metadata_* functions which are the used when registering the nodes. They are documented here in the lua_api.txt.

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

Re: [Please help] Limiting lnventory formspec to certain ite

by Extex » Post

matyilona200 wrote:I have not used this myself, but default:furnaces in minetest_game seem to use allow_inventory_metadata_* functions which are the used when registering the nodes. They are documented here in the lua_api.txt.
But that's for a node, how do I do it for a player inventory?
Player of PK, RIP. Creator of the light_tool and motorbike mods. Working on another mod which should be coming soon!

User avatar
Linuxdirk
Member
Posts: 2645
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Please help] Limiting lnventory formspec to certain ite

by Linuxdirk » Post

Extex wrote:But that's for a node, how do I do it for a player inventory?
https://github.com/minetest/minetest/bl ... 4052-L4063

Check for the inventory being you mod’s player inventory and inventory_info having put. Then analyze stack (that’s the ItemStack that’s about being put to the inventory) and return 0 when it’s not an item that is allowed to be put in the inventory.

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

Re: [Please help] Limiting lnventory formspec to certain ite

by Extex » Post

How do I compare them?

I tried this but it isn't working

Code: Select all

local inv = player:get_inventory():get_list("listname")
if inventory == inv then
Player of PK, RIP. Creator of the light_tool and motorbike mods. Working on another mod which should be coming soon!

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

Re: [Please help] Limiting lnventory formspec to certain ite

by Extex » Post

OK I've got this:

Code: Select all

minetest.register_allow_player_inventory_action(function(player, action, inventory, info)
	if action == "take" then
      return
    end
    
	local list = info.to_list or info.listname
	
	if list ~= "wings" then
      return
	end
    local stack = info.stack
    local item = ItemStack(stack)
    local def = item:get_definition()
    if def.groups.thing then
	   return 1
    else
	   return 0
	end
end)
But it's not working
Player of PK, RIP. Creator of the light_tool and motorbike mods. Working on another mod which should be coming soon!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests