[Mod] Less Simple Shop [shop]

Post Reply
User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

[Mod] Less Simple Shop [shop]

by jas » Post

https://github.com/jastevenson303/shop or master.zip
License: GPL3

This mod features a shop node, and a golden "M" coin. The skeleton key recipe from default is changed to two gold ingots, and one gold ingot yields nine "M" coins. The shop can sell up to 32 items; if the current "page" is set up (both buy and sell slots are occupied", and the next (">") button is pressed, a new page is created.

(Shift-)Right-clicking the node with a key from minetest_game `default:key' will enable infinite stocks, so no filling of inventory is needed ("admin shops").
Spoiler
I just remembered I should check for shop_admin priv on_key_use(), but you have to /give a default:key anyway so I'll get to it sooner or later.
Image
Image
Image
Attachments
screenshot_20170816_043156.png
screenshot_20170816_043156.png (49.31 KiB) Viewed 871 times
screenshot_20170816_122142.png
screenshot_20170816_122142.png (196.22 KiB) Viewed 871 times
screenshot_20170816_122402.png
screenshot_20170816_122402.png (86.96 KiB) Viewed 871 times
Last edited by jas on Thu Aug 17, 2017 04:53, edited 1 time in total.

User avatar
AntumDeluge
Member
Posts: 213
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge
Contact:

Re: [Mod] Less Simple Shop [shop]

by AntumDeluge » Post

Love it!!!

User avatar
AntumDeluge
Member
Posts: 213
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge
Contact:

Re: [Mod] Less Simple Shop [shop]

by AntumDeluge » Post

I haven't had the opportunity to check out your mod much yet, but is there an option to create a static shop that could be used alongside NPCs?

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [Mod] Less Simple Shop [shop]

by jas » Post

I just realized there's a bug where the infinite shops still say "out of stock" if there isn't at least one in the "stock." Whoops! [Edit: All done.]

Not sure what you mean by static shop, AntumDeluge. What's this about NPCs?

User avatar
AntumDeluge
Member
Posts: 213
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge
Contact:

Re: [Mod] Less Simple Shop [shop]

by AntumDeluge » Post

Not sure if "static" was the right word to use. Maybe the "infinite" shop that you mentioned is what I want.

I want to set up a shop that has permanent items (I assumed that this mod was for players to put items up for sale). That way, players can come to the shop to purchase items any time without depleting the stock.

As far as NPCs go, I was just planning on putting one next to the shop to make it look like it was the shop owner.

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [Mod] Less Simple Shop [shop]

by jas » Post

That is correct. You can set "admin shops" that sell an unlimited amount of whatever's listed. You do this by using a key from minetest_game `default:key'.

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: [Mod] Less Simple Shop [shop]

by azekill_DIABLO » Post

+1 i love the name!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [Mod] Less Simple Shop [shop]

by jas » Post

Update: Shop pages now remove themselves if empty.

Code: Select all

 		local admin_shop = meta:get_string("admin_shop")
 
 		if fields.next then
-			--print("It was next.")
 			if pg_total < 32 and
 					pg_current == pg_total and
 					player == owner and
 @@ -123,6 +122,20 @@ minetest.register_node("shop:shop", {
 				meta:set_int("pages_current", pg_current + 1) 
 				meta:set_int("pages_total", pg_current + 1)
 			elseif pg_total > 1 then
+				if inv:is_empty("sell" .. pg_current) and inv:is_empty("buy" .. pg_current) then
+					if pg_current == pg_total then
+						meta:set_int("pages_total", pg_total - 1)
+					else
+						for i = pg_current, pg_total do
+							inv:set_list("buy" .. i, inv:get_list("buy" .. i + 1))
+							inv:set_list("sell" .. i, inv:get_list("sell" .. i + 1))
+							inv:set_list("buy" .. i + 1, nil)
+							inv:set_list("sell" .. i + 1, nil)
+						end
+						meta:set_int("pages_total", pg_total - 1)
+						pg_current = pg_current - 1
+					end
+				end
 				if pg_current < pg_total then
 					meta:set_int("pages_current", pg_current + 1)
 				else
 @@ -131,13 +144,28 @@ minetest.register_node("shop:shop", {
 				meta:set_string("formspec", get_shop_formspec(node_pos, meta:get_int("pages_current")))
 			end
 		elseif fields.prev then
-			--print("It was prev.")
-			if pg_current == 1 and pg_total > 1 then
-				meta:set_int("pages_current", pg_total)
-			elseif pg_current > 1 then
-				meta:set_int("pages_current", pg_current - 1)
+			if pg_total > 1 then
+				if inv:is_empty("sell" .. pg_current) and inv:is_empty("buy" .. pg_current) then
+					if pg_current == pg_total then
+						meta:set_int("pages_total", pg_total - 1)
+					else
+						for i  = pg_current, pg_total do
+							inv:set_list("buy" .. i, inv:get_list("buy" .. i + 1))
+							inv:set_list("sell" .. i, inv:get_list("sell" .. i + 1))
+							inv:set_list("buy" .. i + 1, nil)
+							inv:set_list("sell" .. i + 1, nil)
+						end
+						meta:set_int("pages_total", pg_total - 1)
+						pg_current = pg_current + 1
+					end
+				end
+				if pg_current == 1 and pg_total > 1 then
+					meta:set_int("pages_current", pg_total)
+				elseif pg_current > 1 then
+					meta:set_int("pages_current", pg_current - 1)
+				end
+				meta:set_string("formspec", get_shop_formspec(node_pos, meta:get_int("pages_current")))
 			end
-			meta:set_string("formspec", get_shop_formspec(node_pos, meta:get_int("pages_current")))
 		elseif fields.register then
 			if player ~= owner and (not minetest.check_player_privs(player, "shop_admin")) then
 				output(player, "Only the shop owner can open the register.")
https://github.com/jastevenson303/shop/ ... 2da1ba3ffd

BBmine
Member
Posts: 3476
Joined: Sun Jul 12, 2015 22:51
GitHub: BBmine
IRC: BBmine
In-game: Baggins
Location: USA

Re: [Mod] Less Simple Shop [shop]

by BBmine » Post

/give default:key? Can't everyone craft a key?

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [Mod] Less Simple Shop [shop]

by jas » Post

No, there's no craft recipe for default:key. I think you're thinking about default:skeleton_key, which by default is one gold ingot. Here, I change it to two gold ingots.

Let me know if I'm mistaken about default:key.

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: [Mod] Less Simple Shop [shop]

by hajo » Post

jas wrote:No, there's no craft recipe for default:key.
To get a default:key, you need to use a default:skeleton_key on a door or chest.
This way, the key is set to open that specific door/chest.
Last edited by hajo on Fri Oct 27, 2017 10:36, edited 1 time in total.

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [Mod] Less Simple Shop [shop]

by jas » Post

Thanks very much! I keep meaning to actually figure out how they work. Updated.

User avatar
Lone_Wolf
Member
Posts: 2576
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [Mod] Less Simple Shop [shop]

by Lone_Wolf » Post

Why not make an item only procurable with /giveme?

Code: Select all

minetest.register_craftitem("shop:key", {
    description = "Shop key",
    inventory_image = "default_key.png.png"
})
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [Mod] Less Simple Shop [shop]

by jas » Post

I thought about that, and there's a number of ways to go about it. I went with a priv, since 'shop_admin' was already present. I used a key so that I didn't need to register yet another item. I like the keys, and plan on using them more in the future.

Thanks for the comments, and the star on GitHub. : )

User avatar
AntumDeluge
Member
Posts: 213
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge
Contact:

Re: [Mod] Less Simple Shop [shop]

by AntumDeluge » Post

jas, whatever happened to your mod? The link is dead!

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests