Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Multiusables items

This script recovers a function that was in old rpgmakers: creating items with any limited number of uses(not just 0 or unlimited).
Also adds the option to show the uses ratio in the item description.

Under development. Bugs, suggrences, compatibility issues... just ask.

Code:
#==============================================================================

# Multiusable items

# By gerkrt/gerrtunk

# Version: 1.5

# License: GPL, credits

#==============================================================================

=begin

 

--------Instructions-----------

 

Just add new items in the variable Multiusable_items. You have to do this to

add a new item every time.

 

Ex: If you wanted to add the item number 5 of the database with 3 uses:

 

Multiusable_items = {1=>3, 3=>2, 5=>3}

 

First goes the item id, then the uses. Note that you can remove the two examples

i have add:

 

Multiusable_items = {5=>3}

 

This works like in old Rpgmakers. Internally it will be used the item with less 

number of uses left.

 

----------Options-------------

 

Show_uses: If you turn this option on it will add to every multiusable descriptions

the number of uses left, example:

 

Super Potion

Description: 2/2 uses. Recovers 300 HP.

 

Uses_text: You can modify here the text that is add before the uses ratio.

 

 

----------Compatibality-------------

 

The show uses option modifies the shop and item menu, if you have some script

that changue that it can give you problems. Turn this option off if something goes

wrong.

 

=end

 

module Wep

    # By uses. {Item_id=> number of uses}

    Multiusable_items = {1=>3, 3=>2}

    Show_uses = true

    Uses_text = ' uses. '

end

 

class Game_Party

   attr_reader :multiusable_items

   alias wep_gm_par_init initialize

   def initialize

     wep_gm_par_init

     @multiusable_items = []

  end

 

  #--------------------------------------------------------------------------

  # * Gain Items (or lose)

  #     item_id : item ID

  #     n       : quantity

  #--------------------------------------------------------------------------

  def gain_item(item_id, n)

    # Update quantity data in the hash.

    if item_id > 0

     # Check if multiusable

     if multiusable?(item_id) and n > 0

       for i in 0...n

        # Push a new item with uses and item id 

        uses = Wep::Multiusable_items[item_id]

        @multiusable_items.push([item_id,uses])

       end

      end

      @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min

    end

  end

 

  #--------------------------------------------------------------------------

  # * Lose Items

  #     item_id : item ID

  #     n       : quantity

  #--------------------------------------------------------------------------

  def lose_item(item_id, n)

     if multiusable?(item_id) and have_multiusables?(item_id) and not $scene.is_a?(Scene_Shop) 

       # Sort by uses

       @multiusable_items.sort! {|a,b|a[1]<=> b[1]}

       # Iterate over all items in search of what have the lowest uses

       i=0

       for item in @multiusable_items

        if item[0] == item_id

          @multiusable_items[i][1]-=1

          # If have no more uses, delete it

          if @multiusable_items[i][1] == 0

           @multiusable_items.delete(item)

           @items[item_id] = [[item_number(item_id) -1, 0].max, 99].min

         end

         break

       end

       i+=1

       end

      elsif $scene.is_a?(Scene_Shop) and multiusable?(item_id)

        i=0

        to_lose = n

        @multiusable_items.sort! {|a,b|a[1]<=> b[1]}

        for item in @multiusable_items

          if to_lose == 0

            break

          end

          if item[0] == item_id

             @multiusable_items.delete_at(i)

             to_lose-=1

          end

          i+=1

        end

        @items[item_id] = [[item_number(item_id) -n, 0].max, 99].min

       else

       # Reverse the numerical value and call it gain_item

        gain_item(item_id, -n)

      end

    end

    

  #--------------------------------------------------------------------------

  # * Have Multiusables?

  #--------------------------------------------------------------------------

  def have_multiusables?(item_id)

       for item in @multiusable_items

         if item[0] == item_id

           return true

         end

       end

      return false

  end

    

  #--------------------------------------------------------------------------

  # * Multiusables?

  #--------------------------------------------------------------------------

  def multiusable?(item_id)

    return Wep::Multiusable_items[item_id]

  end

end

  

if Wep::Show_uses

  class Window_Item < Window_Selectable

    #--------------------------------------------------------------------------

    # * Help Text Update 

    #--------------------------------------------------------------------------

    def update_help

      if Wep::Multiusable_items[self.item.id]

        for item in $game_party.multiusable_items

         if item[0] == self.item.id

           uses=item[1]

           break

         end

       end

        description = uses.to_s+'/'+Wep::Multiusable_items[self.item.id].to_s+Wep::Uses_text+self.item.description

        @help_window.set_text(description)

      else

        @help_window.set_text(self.item == nil ? "" : self.item.description)

      end

    end

  end

  

  class Window_ShopSell < Window_Selectable

    #--------------------------------------------------------------------------

    # * Help Text Update 

    #--------------------------------------------------------------------------

    def update_help

      if Wep::Multiusable_items[self.item.id]

        for item in $game_party.multiusable_items

         if item[0] == self.item.id

           uses=item[1]

           break

         end

       end

        description = uses.to_s+'/'+Wep::Multiusable_items[self.item.id].to_s+Wep::Uses_text+self.item.description

        @help_window.set_text(description)

      else

        @help_window.set_text(self.item == nil ? "" : self.item.description)

      end

    end

  end  

end

 

   
 
Nice function, may help some people.

But I have one suggestion for the features, one improvement of the code and one bug :)

First, you could think about including a display which shows the uses you have left.

Second, you are doing it too complicated. You don't need a new Array whenever you gain a item. Instead, you should just use one Hash for all the items like:
{Item ID => Number of Uses Left}
And whenever the uses reach 0 and the item is lost, you reset it to the original value.

Third an last, you can't just alias lose_item. That may work for the things like battles or the item menu but in shops you are able to sell a single item multiple times.
 
Just to do some improvement suggesting combined with self-advertisement, lemme point out that this would HEAVILY benefit by using my Database Flag Reader (link in my signature), as that's just what it's made for. Well, at least if you plan to make a VX version ;)
 
BlueScope":35eqt4sg said:
Just to do some improvement suggesting combined with self-advertisement, lemme point out that this would HEAVILY benefit by using my Database Flag Reader (link in my signature), as that's just what it's made for. Well, at least if you plan to make a VX version ;)

¿The VX databse let use unlimited a note for each thing? I will try VX, i didnt know that.

pd: i will correct it later
 
mouse":30o8qxoh said:
Brilliant idea. This was something I missed from 2k but gradually learned to forget ever existed. :p

I have scripted some other things that i also miss from 2k, but i have to polish it. Also im creating a manual to call interpreter event commands with scripts calls: with this you can make a changue equipment where the id of the actor or the item are defined by event variables(like old makers).
 
Neo-Bahamut":28l546lo said:
Nice function, may help some people.

But I have one suggestion for the features, one improvement of the code and one bug :)

First, you could think about including a display which shows the uses you have left.

Second, you are doing it too complicated. You don't need a new Array whenever you gain a item. Instead, you should just use one Hash for all the items like:
{Item ID => Number of Uses Left}
And whenever the uses reach 0 and the item is lost, you reset it to the original value.

Third an last, you can't just alias lose_item. That may work for the things like battles or the item menu but in shops you are able to sell a single item multiple times.

Its a better idea, yes. The thing i started creating a more complex system where the idea was to make each item trully unique. But i saw that was too hard and make this quick fix to the basis of that system.

Shop bug corrected, and added a display in the help description. I suppose its correct now... i tested all, i think(added in the first post)
 
mouse":1hcak7ca said:
Brilliant idea. This was something I missed from 2k but gradually learned to forget ever existed. :p
You might have forgotten this feature because it was easy to get up to 99 items of the same kind so it wasn't necessary to reimplement the idea of reusing a single item multiple times, you simply had too many items and if you include such a feature, you'd get the same thing you'd get from 999 or more items of the same kind.
 
kyonides":xm4udypa said:
mouse":xm4udypa said:
Brilliant idea. This was something I missed from 2k but gradually learned to forget ever existed. :p
You might have forgotten this feature because it was easy to get up to 99 items of the same kind so it wasn't necessary to reimplement the idea of reusing a single item multiple times, you simply had too many items and if you include such a feature, you'd get the same thing you'd get from 999 or more items of the same kind.

There are other reasons:
-You can make Unique items of various uses. Maybe a legendary potion.
-It gives another option to create atmosphere/originality
-You can now make another range of items(yes, is the same that buying 3x, but feels different)

In my project i want to use it a lot, and in 2k i loved to create healing items underpowered/outside battle but with this options that were like food.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top