{Closed} Inventory and items with modifiers

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Verstehen
Newbie
Posts: 10
Joined: Sun Sep 15, 2013 5:40 pm
Contact:

{Closed} Inventory and items with modifiers

#1 Post by Verstehen » Wed Sep 18, 2013 1:36 am

I'm trying to work on an inventory and I haven't been able to figure it out.
I get how the inventory from the cookbook works but I want something a little more advanced; I want items which apply modifiers to the character when they have it equipped. As an example : if you're wearing this certain necklace that was given to you, you receive a 5% boost in the affection of one individual but on the downside you receive 5% less affection from certain other people.

Is there anywhere I can learn how to create something like an item catalog or library where I can make a large amount of items with modifiers and have it so they don't apply the modifiers while in the inventory but apply then when equipped?
The basic inventory in the cookbook seems way too scarce to supply any of the information I need to get started on this other than storing items and making direct if statements.
I was considering just looking for an already made framework to look at how it was done but I'd prefer to learn how to make one myself so I'm not just mimicking, otherwise I would get stuck with a lot of problems I wouldn't know how to solve.

I'd also like to know if there was anywhere I could get a more in depth learning of inventories, because the equipment screen I have made is pretty much just a skeleton "$ equipped = []" with a transfer screen call, and I'd like to know if I could make it more extravagant; like using image buttons and sprites. I've seen a few number of Ren'py games which use this type of set-up for inventories, although they're usually more action orientated games, I'd still like to create something similar and know where to start.
Last edited by Verstehen on Mon Sep 23, 2013 4:57 pm, edited 1 time in total.

User avatar
jesusalva
Regular
Posts: 85
Joined: Mon Jul 22, 2013 5:05 pm
IRC Nick: jesusalva
Github: pazkero
Location: Brazil
Contact:

Re: Inventory and items with modifiers

#2 Post by jesusalva » Sun Sep 22, 2013 12:45 pm

Hmm... Let's see... That is hard, but well, let's try anyway.

if you using something like

Code: Select all

    for i in range(0, len(items)):
                item_name = items[i].title()
                if i > 0:
                    inventory_show += ", "
                inventory_show += item_name
you can change it to:

Code: Select all

    for i in range(0, len(items)):
                item_name = items[i].title()
                if i > 0:
                    inventory_show += ", "
                inventory_show += "{image=" + item_name + ".png} "
                inventory_show += item_name
of course, that won't help much.
us declared BEFORE showing the item name, show a image called (the item name goes here).png, like, if item_name is "glove", then the image is "glove.png".

yeah, that should be enough for you, you just need place

Code: Select all

                inventory_show += "{image=" + item_name + ".png} "
before the name, remember to change inventory_show before using it.

maybe that helps:

Code: Select all


    def add_item(item_name, description, effect_type, effect_value):
        store.itens.append( (item_name, description, effect_type, effect_value) )


that place in the “skelton” called “store.itens” a full array, with many camps.

huh... the following code is Ctrl+C Ctrl+V, but you can learn something about seeking the camp in it:

Code: Select all

        # set a index value
        index = 0
        for message in store.messages:
            if (message[3] == None or eval(message[3]) == True):
                    styleIndex = "Message"



                    # is the current item/message?
                    if (index == currentMessage):

                        
                        if not store.messages[currentMessage][4] == "no":
                         styleIndex = "CurrentMessage"

                        
                        
                    #if not store.messages[currentMessage][4] == "no":
                    ui.button(clicked=ui.returns(index),
                        style=style.messageButton[styleIndex])
                    ui.text(message[0] + " \n{size=-3}From:{/size} " + message[1], style=style.messageButtonText[styleIndex])
                        
                        
            index = index + 1
in that, “store.itens[currentMessage][2]” will take the effect_type of item “currentMessage”. I hope that it *somehow* help!!!
☆ ♔ Jesusaves/Jesusalva ♚ ★

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Inventory and items with modifiers

#3 Post by xela » Mon Sep 23, 2013 5:47 am

Verstehen wrote:I'm trying to work on an inventory and I haven't been able to figure it out.
I get how the inventory from the cookbook works but I want something a little more advanced; I want items which apply modifiers to the character when they have it equipped. As an example : if you're wearing this certain necklace that was given to you, you receive a 5% boost in the affection of one individual but on the downside you receive 5% less affection from certain other people.

Is there anywhere I can learn how to create something like an item catalog or library where I can make a large amount of items with modifiers and have it so they don't apply the modifiers while in the inventory but apply then when equipped?
The basic inventory in the cookbook seems way too scarce to supply any of the information I need to get started on this other than storing items and making direct if statements.
I was considering just looking for an already made framework to look at how it was done but I'd prefer to learn how to make one myself so I'm not just mimicking, otherwise I would get stuck with a lot of problems I wouldn't know how to solve.

I'd also like to know if there was anywhere I could get a more in depth learning of inventories, because the equipment screen I have made is pretty much just a skeleton "$ equipped = []" with a transfer screen call, and I'd like to know if I could make it more extravagant; like using image buttons and sprites. I've seen a few number of Ren'py games which use this type of set-up for inventories, although they're usually more action orientated games, I'd still like to create something similar and know where to start.
I've never seen a good inventory tutorial, maybe because from programming viewpoint, inventories/items are not that complicated. If you want to create a decent system, you might want to consider learning some Python, up to the point where the task doesn't seem complicated anymore. I doubt that there is another way to create your own design that you'd understand full 100%.
Like what we're doing? Support us at:
Image

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: Inventory and items with modifiers

#4 Post by Elmiwisa » Mon Sep 23, 2013 7:43 am

Inventory system have been covered by the cookbook.
To add in modifier that is sufficient to cover what you are describing is rather simple. For simplicity, first store all your character stats in a single object (of a class that descend from renpy.store to make it work with rollback). You would want to store 2 stats object for each character that can equip item: the base stats and the final stats. Now for the items, you simply add in one more field (or element if you use tuple, or entry if you use dictionary to store item information) that is a list that specify the effects of the item (this might be needed if, for example, your effect consist of +5 to lockpicking and also +5% to lockpicking, and you want to ensure that all percentage-based change to take place before the absolute stats change). Each effect is something that consist of a priority number and a function that take in a single argument which is the object that store all the stats. The function simply modify the object they receive in the way you want (for example, something like stats.sitting=(int)(stats.sitting*1.05)+stats.meditation would increase the stat sitting by 5% and round down then add meditation bonus to it). Maintain a priority queue of the effects of currently equipped items where the priority is specify by the priority number. This is to ensure that, for example, if you want absolute stats change (e.g. +5 to swimming) to always take place after a percentage change (e.g. +5% to magic). Effects should only have the same priority if they are commutative. Whenever the character attempt to change equipment, or whenever the base stats change for some reason, you simply refresh the value for the final stats object. First update the base stats (if the base stats change), or add or remove the effects from the priority queue (if the equipment change). Then first copy everything from the base stats object to the final stats object, and then go through the priority queue and apply the function to the final stats object one by one according to the priority. After all effect are applied, the final stats object will have the stats for to be used.

User avatar
jesusalva
Regular
Posts: 85
Joined: Mon Jul 22, 2013 5:05 pm
IRC Nick: jesusalva
Github: pazkero
Location: Brazil
Contact:

Re: Inventory and items with modifiers

#5 Post by jesusalva » Mon Sep 23, 2013 2:59 pm

hmm... I think that I need a example... your text is a bit hard to read, Elmiwisa... but if I understood it (if I understood something!) it is the right way. Maybe I should read it more detailed... or you should insert “enters” and code tags to your text, to make the reading easier.
☆ ♔ Jesusaves/Jesusalva ♚ ★

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Inventory and items with modifiers

#6 Post by xela » Mon Sep 23, 2013 4:07 pm

Like I've said, decent knowledge of python would be required to write an inventory system to the specs. Using a function like Elmiwisa suggested is one of many good options, for example in my game that has inventory/item/character/shops system that is a lot more complex than what Verstehen is looking for, "Special" __getattr__ and __setattr__ methods that apply all basestats and any augmentations that come from items "on the fly" are used. It's a little bit harder to code but the idea is the same as with function, only it would never have to be called by the programmer.

Both function and special methods (and several containers that would be required in both cases) are also great ways to solve common inventory system issues like:

- Checking boundaries (If stat is between Min/Max limits)
- Making sure no progress is lost (If stat was maxed out by an item, game would still count stat increases so when item is unequipped, both original value and progress made in the meanwhile are applied)
- Making sure there is no loss on removal of item (If stat with max value of 100 and present value 95 is augmented with an item by a value of 20, when item is taken off, stat remains at 95 and not decreased to 80)
Like what we're doing? Support us at:
Image

User avatar
Verstehen
Newbie
Posts: 10
Joined: Sun Sep 15, 2013 5:40 pm
Contact:

Re: Inventory and items with modifiers

#7 Post by Verstehen » Mon Sep 23, 2013 4:56 pm

This helped a lot.
I wasn't really focused on the inventory I was just asking if I could find somewhere that I could learn more advanced ways to go about it, the inventory I have in the game works fine already.
My question was more focused on an item library and modifiers.

Post Reply

Who is online

Users browsing this forum: Google [Bot]