So question is how do make this code to be usable for defined number of characters without needing it to retype over and over...
I tried to explain the best I could most of line so you can understand the way it work. I know there are other examples of similar inventory systems but this one I can understand the way it works however I cant figure out how to make it for multiple characters without it being copy-pasted many times which I don't really like
Code: Select all
# First Backpack is defined this has nothing to do with the question but I included it so you can have better understanding of how my code works
# Here we add items that will be stored in backpack list so later we can chose which item we want to equip
class Backpack(store.object):
def __init__(self, maxwt, gold, **kwargs):
self.maxwt = maxwt
self.space_left = maxwt
self.mySet = set()
self.gold = gold
def add_Item(self, item, found=False):
if item.KG <= self.space_left and (item.COST <= self.gold or found):
self.mySet.add(item)
self.space_left -= item.KG
item.AMOUNT += 1
if not found:
self.gold -= item.COST
return "{0} added to inventory.".format(item.NAME)
else:
if item.KG > self.space_left:
return "There is not enough space in your inventory!"
elif item.COST > self.gold:
return "You don't have enough gold!"
else:
return "There is some problem here."
# Here I defined player his DAMAGE stats will be changed dependent of item that we are wearing
init -1 python:
class Player(renpy.store.object):
def __init__(self, NAME, DAMAGE):
self.NAME = NAME # Player name
self.DAMAGE = DAMAGE # Player damage
#Here is class that is used for items
init -1 python:
class Item(store.object):
def __init__(self, NAME, COST=0, KG=0, DAMAGE=0, AMOUNT=0, DESCRIPTION = "No Description", PICTURE="No Picture"):
self.NAME = NAME # Item name
self.COST = COST # Item cost
self.KG = KG # I disabled this feature I do not need it and it is only used while adding items to backpack
self.DAMAGE = DAMAGE # Item damage
self.AMOUNT = AMOUNT # Will display how many same items we have stacks up best used for consunables 1,2,3... for weapons just leave 0
# After item is added to backpack amount will be +1 so starting amount is best to stay at 0
self.DESCRIPTION = DESCRIPTION # Item description
self.PICTURE = PICTURE # Image of item used at screen
def equip(self, item):
if item.EQUIPMENT_TYPE == "WEAPON":
item.AMOUNT -= 1 # If weapon is equipped it will act as item was consumed until it is de equipped
self.WEAPON = item.NAME
self.PLAYER_DAMAGE += item.DAMAGE # Sums up with bob.PLAYER_DAMAGE=10 + item.DAMAGE = 700 which will result in 710 total
renpy.show_screen("inventory_popup", message="You equiped [bob.WEAPON] now Bob damage is [bob.DAMAGE].") #Display what i said up there
def de_equip(self, item):
if item.EQUIPMENT_TYPE == "WEAPON":
item.AMOUNT += 1 # Now item is no more equipped so we add extra amount
self.WEAPON = None
self.PLAYER_DAMAGE -= item.DAMAGE # After item is de equipped just remove stats from current item that was equipped which means
# -700
renpy.show_screen("inventory_popup", message="You de-equiped [bob.WEAPON].") #Display what i said up there
screen item_description(item):
add "gui/inventory_blank.png"
modal True
frame align (0.4, 0.5):
style_group "item_desc_grp"
at Position(xanchor = 0.0,xpos = 0.001, yanchor = 0.0, ypos = 0.80, xminimum = 10)
xminimum 1439
xmaximum 1439
yminimum 200
ymaximum 200
vbox:
text "[item.DESC]"
$ renpy.block_rollback()
frame:
xpos 10
style_group "nice_looking"
xalign 0
yalign 0.015
textbutton "CLOSE" action Hide("item_desc"), Hide("deequip_item")
frame align (0.5, 0.3):
image "[item.PICTURE]"
frame align (0.010, 0.770):
text "[item.NAME]"
if item.EQUIPMENT_TYPE == "WEAPON":
if bob.WEAPON == None or "Fist" and item.AMOUNT >= 1:
screen EQUIP_WEAPON_SCREEN:
frame align (0.5, 0.550):
style_group "item_desc_grp"
textbutton "EQUIP WEAPON" action Hide("EQUOP_WEAPON_SCREEN"), Function(bob.equip, item)
elif bob.WEAPON == item.NAME and item.AMOUNT <= 0:
screen WEAPON_DEQ:
frame align (0.5, 0.550):
style_group "item_desc_grp"
textbutton "DE-EQUIP WEAPON!" action Hide("WEAPON_DEQ"), Function(bob.de_equip, item), Hide("item_close_button_screen")
else:
frame align (0.5, 0.550):
style_group "item_desc_grp"
textbutton "TO WEAR DE-EQUIP YOUR CURRENT WEAPON" action Show("inventory_popup", message="Weapon is not useable by you or someone is wearing it!")
label start:
# Define player
default bob = Player(
NAME = "Bob",
DAMAGE = 10) # On forum image i posted you will see that bob damage is 710 it is because weapon damage is now added to player damage which
# means that our code works!
# So now that I have 2 characters how do I make this code work for BOTH of them without needing to copy-paste over and over this same code
default emma = Player(
NAME = "Emma",
DAMAGE = 5)
# Define item
default gun = item(
NAME = "Gun",
COST = 10,
DAMAGE = 700,
KG = 1,
AMOUNT = 0,
DESCRIPTION = "This is a nice gun!",
PICTURE = "gun.png")
"Game continues..."
"Now defining the party_list"
$ party_list = [bob, emma]