Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
xplosion
Newbie
Posts: 9
Joined: Sat Jul 21, 2018 3:49 pm
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#61 Post by xplosion » Sat Jul 28, 2018 9:51 am

Does not work argh
EDIT
Seems like there is no issue if i move to another label then save, but IF i do move items to chest then immediatly save/load it doesnt save.

Code: Select all

init:
    default cookbook = list()
    default inv = Inventory("Inventory")
    default jane_inv = Inventory("Jane")
    default chest = Inventory("Storage Chest")
    default mindy_inv = Inventory("Mindy", 500, 75)

    ### Items without icons are created like this:      
    #$ quarter = Item("Quarter", "A new quarter)
    
    ### Items with icons are created like this:
    $ eye = Item(name="Eyeball", desc="A human eyeball, how creepy!", icon="images/eye.png", value=250)

    # Items that can be used in crafting
    $ but = Item("Button", "A shiny button", "images/button.png", 100, act=Show("inventory_popup", message="This item is only used in crafting"))
    
    $ yarn = Item("Yarn", "Yarny yarny yarn.", "images/yarn.png", 30, act=Show("inventory_popup", message="This item is only used in crafting"))  
    
    $ fabric = Item("Fabric", "You know, cloth.", "images/fabric.png", 100, act=Show("inventory_popup", message="This item is only used in crafting"))
    
    $ coin = Item("Coin", "An old coin", "images/coin.png", 1, act=Show("inventory_popup", message="This item is only used in crafting"))
    
    # An item with a unique action (shows screen with custom message)
    $ sword = Item("Awesome Sword", "An awesome sword.", "images/sword.png", 500, Show("inventory_popup", message="You wave the sword around wildly but nothing happens."))
    

label start:
    $ cookbook = list() 
    $ jane_inv = Inventory("Jane")
    
    #GIVE ITEMS START GAME#
    $ jane_inv.take(sword)
    $ jane_inv.take(eye)
    $ jane_inv.money = 500  
    $ mindy_inv = Inventory("Mindy", 500, 75)
    $ mindy_inv.take(eye,4)
    $ mindy_inv.take(but,3)
    $ mindy_inv.take(coin,2)
    #############
 

User avatar
enrohk
Newbie
Posts: 7
Joined: Tue Jun 19, 2018 6:32 pm
Location: Spain
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#62 Post by enrohk » Tue Jul 31, 2018 6:25 am

Hi !
I'm new to python but I'm using your Inventory System for my project. It works very well with others things I'm implementing.

Learning still the basic of this language (moving from C#) but i was in need of a method for returning True or False if a item exists in the inventory (for example , make a button sensitive if you have THAT item in the inventory) . And the only methods I see is for returning ID's and those stuff.
I want to share if someone find useful or even can be better written or even that method already exists and I'm missing something Hahah.
Well... Open Inventory.rpy and inside Inventory class add :

Code: Select all

def check_item(self, item):
            if self.qty(item):
                return True
            else:
                return False
This can allow to check inventory and make options or buttons if player or other inventory has that item like

Code: Select all

sensitive inv_player.check_item(item_example)
Sorry for my noobish english and noobish code ;)
Do I live in a friendly or a hostile universe? Which is it? Is it a universe that is filled with hostility and anger and people wanting to hate each other and people wanting to kill each other, is that what you see?Because when you see the world that way that’s exactly what you will create for yourself in your life.

User avatar
niannn
Regular
Posts: 41
Joined: Tue Jun 27, 2017 1:04 am
Completed: Keynote, Die.Alone?, The Villaintine
Tumblr: niaaannn
itch: niannn
Location: Philippines
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#63 Post by niannn » Tue Jul 31, 2018 9:02 pm

xplosion wrote:
Sat Jul 28, 2018 9:51 am
Does not work argh
EDIT
Seems like there is no issue if i move to another label then save, but IF i do move items to chest then immediatly save/load it doesnt save.
Hey, xplosion. I'm sorry, I can't help you with that. I didn't use the merchant-like part of the system (if I understood correctly, that's what you're having troubles with, right? if I'm wrong, I'm sorry again) so I don't really know how I can help you. I hope someone can help with your issue though (alternatively, you can try posting about this problem on the 'Ren'Py Questions and Announcements' board and attach some of the code you've done so far).
Image Image Image

xplosion
Newbie
Posts: 9
Joined: Sat Jul 21, 2018 3:49 pm
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#64 Post by xplosion » Sun Aug 05, 2018 6:51 am

niannn wrote:
Tue Jul 31, 2018 9:02 pm
xplosion wrote:
Sat Jul 28, 2018 9:51 am
Does not work argh
EDIT
Seems like there is no issue if i move to another label then save, but IF i do move items to chest then immediatly save/load it doesnt save.
Hey, xplosion. I'm sorry, I can't help you with that. I didn't use the merchant-like part of the system (if I understood correctly, that's what you're having troubles with, right? if I'm wrong, I'm sorry again) so I don't really know how I can help you. I hope someone can help with your issue though (alternatively, you can try posting about this problem on the 'Ren'Py Questions and Announcements' board and attach some of the code you've done so far).
I don't really know I haven't looked for a solution since it's not a gamebreaking bug I guess.
niannn wrote:
Sat Jan 06, 2018 11:07 am
just wondering if there's a way to solve this one?

Image

As you can see from the image, the description of an item upon hovering doesn't show up where it's supposed to be. I don't have any idea how to fix this and I would really appreciate help. Also, thank you in advance!

sidenote: I am not so well-versed with python and modified the code only a little based on the basic guidelines on how to use it (I did try to fix this with my basic understanding but I think all my attempts are not getting me anywhere and I need help). So, I'm still a rookie. I might ask again if I don't understand the answer so I hope you'll be patient with me. Once again, thank you very much in advance.
Check Inventory.rpy for this code and modify the numbers to your choice, this code fix the issue. from yalign 1.0 to 0.9.

Code: Select all

screen tooltip(item=False,seller=false):      
    if item:
        hbox:
            xalign 0.5 yalign 0.9
            if seller:
                text ("[item[0].name]: [item[0].desc] (Sell Value: " + str(calculate_price(item, seller)) + ")")
            else:
                text "[item[0].name]: [item[0].desc] (Value: [item[0].value])" 
enrohk wrote:
Tue Jul 31, 2018 6:25 am
Hi !
I'm new to python but I'm using your Inventory System for my project. It works very well with others things I'm implementing.

Learning still the basic of this language (moving from C#) but i was in need of a method for returning True or False if a item exists in the inventory (for example , make a button sensitive if you have THAT item in the inventory) . And the only methods I see is for returning ID's and those stuff.
I want to share if someone find useful or even can be better written or even that method already exists and I'm missing something Hahah.
Well... Open Inventory.rpy and inside Inventory class add :

Code: Select all

def check_item(self, item):
            if self.qty(item):
                return True
            else:
                return False
This can allow to check inventory and make options or buttons if player or other inventory has that item like

Code: Select all

sensitive inv_player.check_item(item_example)
Sorry for my noobish english and noobish code ;)
That's a nice addition thank you, It made checking for items much simplier, since I was planning to add stuff like a Fridge with an inventory and have a character notices you that we're out of certain items.

Code: Select all

    if fridge_inv.check_item(beer):
        "We still have some beer on the fridge if you'd like to grab one."
    else:
        "Oh snap we're out of beer, I gotta run to the store for a pack."
 
But I wish I know how to make an action happen after closing the inventory, like if I bought the beer from store, a check will happen

Code: Select all

    if myinventory_inv.check_item(beer):
        "Thanks for your purchase!."
    else:
        "See you next time!"
 

User avatar
enrohk
Newbie
Posts: 7
Joined: Tue Jun 19, 2018 6:32 pm
Location: Spain
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#65 Post by enrohk » Sun Aug 05, 2018 9:00 pm

xplosion wrote:
Sun Aug 05, 2018 6:51 am
But I wish I know how to make an action happen after closing the inventory, like if I bought the beer from store, a check will happen

Code: Select all

    if myinventory_inv.check_item(beer):
        "Thanks for your purchase!."
    else:
        "See you next time!"
 
Hi! I like you find that useful ;-) I'm thinking on what you asked . And is viable ... I think :lol:

One "tricky method" is to save info on your inventory money.
For example , create a "stamp" each time you visit the shop and save the amount of money you have BEFORE BUYING.
If you have 3000$ , create a stamp like

Code: Select all

$ money_stamp = myinventory_inv.money
When the shop window is closed , make a statement to look if you have LESS money AFTER . Something like :

Code: Select all

	if money_stamp < myinventory_inv.money:
		"Thanks for your purchase!."
    	else:
        	"Purchase something!"
That should save check for individually items .... i think. Is viable that method for you ?
Do I live in a friendly or a hostile universe? Which is it? Is it a universe that is filled with hostility and anger and people wanting to hate each other and people wanting to kill each other, is that what you see?Because when you see the world that way that’s exactly what you will create for yourself in your life.

xplosion
Newbie
Posts: 9
Joined: Sat Jul 21, 2018 3:49 pm
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#66 Post by xplosion » Tue Aug 07, 2018 6:36 am

enrohk wrote:
Sun Aug 05, 2018 9:00 pm
xplosion wrote:
Sun Aug 05, 2018 6:51 am
But I wish I know how to make an action happen after closing the inventory, like if I bought the beer from store, a check will happen

Code: Select all

    if myinventory_inv.check_item(beer):
        "Thanks for your purchase!."
    else:
        "See you next time!"
 
Hi! I like you find that useful ;-) I'm thinking on what you asked . And is viable ... I think :lol:

One "tricky method" is to save info on your inventory money.
For example , create a "stamp" each time you visit the shop and save the amount of money you have BEFORE BUYING.
If you have 3000$ , create a stamp like

Code: Select all

$ money_stamp = myinventory_inv.money
When the shop window is closed , make a statement to look if you have LESS money AFTER . Something like :

Code: Select all

	if money_stamp < myinventory_inv.money:
		"Thanks for your purchase!."
    	else:
        	"Purchase something!"
That should save check for individually items .... i think. Is viable that method for you ?
I wanted something for items giving a check for a certain item if it was sold after closing the inventory

Edit

@niannn Fixed the saving issue I had using "renpy.retain_after_load()" everytime I wanted to open inventory.

also make sure to have "default mc_inv = Inventory("[mc]")" before label start.

Code: Select all

action renpy.retain_after_load(), ToggleScreen("inventory_screen", first_inventory=mc_inv, second_inventory=lucas_inv)

User avatar
enrohk
Newbie
Posts: 7
Joined: Tue Jun 19, 2018 6:32 pm
Location: Spain
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#67 Post by enrohk » Tue Aug 07, 2018 6:41 pm

xplosion wrote:
Tue Aug 07, 2018 6:36 am

I wanted something for items giving a check for a certain item if it was sold after closing the inventory
I think your answer is in the method "transaction" inside Inventory class:

Code: Select all

def transaction(seller, buyer, item):
        price = calculate_price(item, buyer)
        if buyer.money >= price:   
            seller.sell(item, price)
            buyer.buy(item, price)
        else:
            message = "Sorry, %s doesn't have enough money!" % (buyer.name)
            renpy.show_screen("inventory_popup", message=message)
Idk your level of python but mine is very basic and I just started, but maybe you can do something like that:

First create a List to add what items you buy each time you shop (this method can work with all shops also)

Code: Select all

$ buyed_items = []
and in the transaction method do something like

Code: Select all

def transaction(seller, buyer, item):
        price = calculate_price(item, buyer)
        if buyer.money >= price:   
            seller.sell(item, price)
            buyer.buy(item, price)
            #mod- Add the item to a list
            buyed_items.append(item)
        else:
            message = "Sorry, %s doesn't have enough money!" % (buyer.name)
            renpy.show_screen("inventory_popup", message=message)
Just remember to add your list to the globals for use in inventory script.
later you can add a mehod that checks for items in that list. something like the mine for check for true :

Code: Select all

def check_item(item):
	global buyed_items
                for i in buyed_items:
                    if i[0] == item:        
                        return True
                    else:
                        return False

I just wrote that code without checking , but the concept is that :
- Add the item to a list if you buy
- When shop is closed run the check item method looking for the item
- Do something if find
- Clear list (for don't take problems next time you buy)

With that you can have custom actions sayed if items are buyed , something like : "Remember to put those in the fridge !" or "That cheese comes from a local place, enjoy it ! "
Do I live in a friendly or a hostile universe? Which is it? Is it a universe that is filled with hostility and anger and people wanting to hate each other and people wanting to kill each other, is that what you see?Because when you see the world that way that’s exactly what you will create for yourself in your life.

User avatar
niannn
Regular
Posts: 41
Joined: Tue Jun 27, 2017 1:04 am
Completed: Keynote, Die.Alone?, The Villaintine
Tumblr: niaaannn
itch: niannn
Location: Philippines
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#68 Post by niannn » Thu Aug 09, 2018 10:32 pm

xplosion wrote:
Sun Aug 05, 2018 6:51 am
Check Inventory.rpy for this code and modify the numbers to your choice, this code fix the issue. from yalign 1.0 to 0.9.

Code: Select all

screen tooltip(item=False,seller=false):      
    if item:
        hbox:
            xalign 0.5 yalign 0.9
            if seller:
                text ("[item[0].name]: [item[0].desc] (Sell Value: " + str(calculate_price(item, seller)) + ")")
            else:
                text "[item[0].name]: [item[0].desc] (Value: [item[0].value])" 
Been busy and unable to log in here, but I'm glad I did now! Thank you very much for helping me out with this one! I shall keep this code for future use :)
xplosion wrote:
Tue Aug 07, 2018 6:36 am
Edit

@niannn Fixed the saving issue I had using "renpy.retain_after_load()" everytime I wanted to open inventory.

also make sure to have "default mc_inv = Inventory("[mc]")" before label start.

Code: Select all

action renpy.retain_after_load(), ToggleScreen("inventory_screen", first_inventory=mc_inv, second_inventory=lucas_inv)
And I'm glad that it worked out for you! This code looks useful, thanks a lot for sharing :D
Image Image Image

Post Reply

Who is online

Users browsing this forum: No registered users