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.

Potion-like items?

Kaito

Member

Hiya,

Well...This is pretty confusing...
How would I make an item, that raises a value when used?
Yes, I can make a common event, and call script,ex:
$game_actors[id].ap += 50
but the problem is, how would I make it so the game knows which actor to add the value like potions?

It;s really hard to explain...I hope this is enough.^^"

cya~
 
Instead, alias you item_effect method.

Code:
class Game_Battler
  alias seph_itemap_gmbtlr_ie item_effect
  def item_effect(item)
    result = seph_itemap_gmbtlr_ie(item)
    if result && self.is_a?(Game_Actor)
      # Add your results here
    end
  end
end

For something like adding ap depending on item effects, I suggest something such as this:

Code:
class Game_Battler
  Item_AP_Effects = {}
  alias seph_itemap_gmbtlr_ie item_effect
  def item_effect(item)
    result = seph_itemap_gmbtlr_ie(item)
    if result && self.is_a?(Game_Actor)
      if Item_AP_Effects.has_key?(item.id)
        self.ap += Item_AP_Effects[item.id]
      end
    end
  end
end


That should do the trick.
 

Kaito

Member

Sorry...But I don't have a clue... ;_;
What's the difference between code 1&2?
How do you determine the value?
What do you mean by "your effects here"?

'thanks for the reply,
cya~!
 
The first one is just a basic template (for any script that wants to have item effects), where the second one is more of what you need.

In the second one, I created a hash that will be used as basically nothing more than an extension of the database.

Item_AP_Effects = { item_id => ap_gain, ...}

When an item is used, it checks to see if the person used on is effected. If they were effected by it, it scans if the person is an Actor (not Enemy)and if the item has a defined item gain. If it does, it gives the person AP.

Code:
class Game_Battler                            # Defines Game_Battler Mod
  Item_AP_Effects = {}                        # Defines AP Item Effects Hash
  alias seph_itemap_gmbtlr_ie item_effect     # Alias our Item Effect Method
  def item_effect(item)                       # Defines Item_Effect Method
    result = seph_itemap_gmbtlr_ie(item)      # Gets Result of Original Item Effect
    if result && self.is_a?(Game_Actor)       # If Positive Result and target is Actor
      if Item_AP_Effects.has_key?(item.id)    # If Item has Defined AP
        self.ap += Item_AP_Effects[item.id]   # Gives Target Defined AP Value
      end                                     # End
    end                                       # End
  end                                         # End
end                                           # 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