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.

Give item instead of gold

Hi this is what I need, I need this;

Code:
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    @gold = [[@gold + n, 0].max, 9999999].min
  end

To add an item with the id of 39 instead of gold.

Thanks,
Catkitten
 
If you look a little further down in that script (Game_Party) you'll see

Code:
  #--------------------------------------------------------------------------
  # * 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
      @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
    end
  end
 
Brewmeister":1d6up14t said:
If you look a little further down in that script (Game_Party) you'll see

Code:
  #--------------------------------------------------------------------------
  # * 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
      @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
    end
  end
ya I saw that, would I rewrite the gold thing to look like this;
Code:
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    # Update quantity data in the hash.
      @items[39] = [[@gold + n, 0].max, 9999999].min
  end
 
I think I may have misunderstood what you are trying to do.
I meant just use the "Gain Items" method instead of the "Gain Gold" method.

Can you explain why you want to do this?

without testing, I think it should be...
Code:
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    # Update quantity data in the hash.
      @items[39] = [[@items[39] + n, 0].max, 99].min
  end
 
Brewmeister":2nv92wrl said:
I think I may have misunderstood what you are trying to do.
I meant just use the "Gain Items" method instead of the "Gain Gold" method.

Can you explain why you want to do this?

without testing, I think it should be...
Code:
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    # Update quantity data in the hash.
      @items[39] = [[@items[39] + n, 0].max, 99].min
  end
I would like the gold command to add X amount to item 39. Why, Because my shops and stuff now use item 39 as it's gold, but I have to use the item command to give gold and that only allows me to give 99gold at a time. That's why I  want the Gold command to give X amount of gold. Hope I explained that ok.

K, I'll test it when I get home.
 
Code:
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    # Update quantity data in the hash.
      @items[39] = [[@items[39] + n, 0].max, 99].min
  end
after adding that I get this error Script 'Game Party' line 142: NomethodError occurred undefined method '+' for nil:NilClass


Fixed it! and it works
Code:
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    # Update quantity data in the hash.
      if $game_party.item_number(39) >= 9999999
        else
      $game_party.gain_item(39, n)
      end
  end
It checks to see if item 39 is greeater than or = to 9999999 if it isn't it adds X amount of potions!
Thanks everyone who helped!
 
it's not really necessary but it can be changed to
Code:
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    # Update quantity data in the hash.
    $game_party.gain_item(39, n) if !$game_party.item_number(39) >= 9999999
  end
 

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