[Mod] Less Simple Shop [shop]

User avatar
jas
Member
 
Posts: 267
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

[Mod] Less Simple Shop [shop]

by jas » Wed Aug 16, 2017 16:30

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").
+ TODO


Image
Image
Image
Attachments
screenshot_20170816_043156.png
(49.31 KiB) Not downloaded yet
screenshot_20170816_122142.png
(196.22 KiB) Not downloaded yet
screenshot_20170816_122402.png
(86.96 KiB) Not downloaded yet
Last edited by jas on Thu Aug 17, 2017 04:53, edited 1 time in total.
 

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

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

Re: [Mod] Less Simple Shop [shop]

by AntumDeluge » Thu Aug 17, 2017 00:30

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: 267
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: [Mod] Less Simple Shop [shop]

by jas » Thu Aug 17, 2017 00:53

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: 166
Joined: Sun Aug 07, 2016 05:42
GitHub: AntumDeluge
IRC: AntumDeluge

Re: [Mod] Less Simple Shop [shop]

by AntumDeluge » Thu Aug 17, 2017 03:18

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: 267
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: [Mod] Less Simple Shop [shop]

by jas » Thu Aug 17, 2017 04:52

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: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 

User avatar
jas
Member
 
Posts: 267
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: [Mod] Less Simple Shop [shop]

by jas » Wed Oct 25, 2017 09:04

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
 

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

User avatar
jas
Member
 
Posts: 267
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: [Mod] Less Simple Shop [shop]

by jas » Thu Oct 26, 2017 06:22

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: 596
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: [Mod] Less Simple Shop [shop]

by hajo » Thu Oct 26, 2017 08:29

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: 267
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: [Mod] Less Simple Shop [shop]

by jas » Thu Oct 26, 2017 12:39

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

User avatar
Lone_Wolf
Member
 
Posts: 1980
Joined: Sun Apr 09, 2017 05:50
Location: Hopefully very far from yours, snoop :P
GitHub: LoneWolfHT
IRC: Lone_Wolf
In-game: Lone_Wolf

Re: [Mod] Less Simple Shop [shop]

by Lone_Wolf » Fri Oct 27, 2017 05:41

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"
})
 

User avatar
jas
Member
 
Posts: 267
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: [Mod] Less Simple Shop [shop]

by jas » Fri Oct 27, 2017 06:24

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. : )
 


Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 1 guest