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.

Food used once after battle

I have a food items in my game. What I want is when a player use a "food" type item, the player cannot use another food type item until s/he finish at least one battle. Also I want it to show a test box in the center saying [We already ate.]

It kinda like we already ate and we are not hungry until we finish a battle.

I'll will try to explain better when it needed to.
 
You can do this with events, if you like.

Make a Common Event something like this (I'll use Switch 0001, as an example):

@Conditional Branch: Switch [0001] is On
...<>Text: We already ate.
@Else:
...<>Turn Switch [0001] On
@End Branch

Have all of your items call this Common Event.

Now, go into the Troops tab in the database and in each troop you have, include a command in the event handler at the bottom that turns Switch [0001] Off.

What this does is, after you eat the food, it will call the Common Event which checks if the switch is on or not. If it is on, you will get the "We already ate" text, and if it is Off, the event will turn it On.

Then, after each battle, the Switch will be turned Off, allowing you to eat a new piece of food.
 
Hmm...how many different food items do you have?

If you don't have that many different foods, then what you could do is make 2 versions of the food. Have one version be consumable and the other not.

Create a new Common Event set for when Switch: [0001] is On. In the event, set one variable equal to the number of steaks in inventory.

For example (I'll use Variable [0001: Steaks] as an example):

Common Event: Switch [0001] is On
@ Set Variable [0001: Steaks] = Steaks (consumable ones in inventory)
@ Change Items: Remove Steaks (equal to variable)
@ Change Items: Add Steaks (non-consumable ones, and add # equal to variable)

Now, make another Common Event for when Switch [0001] is Off, and does the exact opposite:

Common Event: Switch [0001] is Off
@ Set Variable [0001: Steaks] = Steaks (non-consumable ones in inventory)
@ Change Items: Remove Steaks (non-consumable ones, equal to variable)
@ Change Items: Add Steaks (consumable ones, and add # equal to variable)

These Common Events should activate when the Switch is thrown (having it split into two Common Events saves you from having to put a parallel process event on every map to check whether the switch is On or Off).

That way, when the switch is On and you can't eat, it will remove all of your edible steaks and replace them (without the player knowing) with the steaks you can't eat. If the player tries to use the item again, they should get the text box that says they already ate (if you had it call your first Common Event). When the switch is Off, it will remove the non-edible steaks and replace them with edible ones.
 
Not too hard to do s:
First, add this block of code in a new spot above main:
Code:
class Game_Temp
  attr_accessor :alreadyate
  alias foodinit initialize; def initialize; foodinit
    @alreadyate = 0
  end
end
Next, go to Window_Item (or whatever item window script you're using)
and find 'def draw_item(index)'.
Find this part:
Code:
if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
and add this right below it:
Code:
if item.element_set.include?($data_system.elements.index("Food")) and $game_temp.alreadyate != 0
      self.contents.font.color = disabled_color
    end
Then, still in Window_Item (or your item script)
and change 'def update_help' to this:
Code:
def update_help
  if self.item.element_set.include?($data_system.elements.index("Food")) and $game_temp.alreadyate != 0
    @help_window.set_text("We already ate.")
  else
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
Then, go into Scene Battle 1 (or whatever battle system you're using)
and find 'def battle_end(result)' and add this line:
Code:
$game_temp.alreadyate = 0
right under 'def battle_end(result)'.
Next, go into Scene_Battle 3 (or your battle system, again)
and find 'def update_phase3_item_select'.
Scroll down to this part:
Code:
# If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @item_window.item
      # If it can't be used
      unless $game_party.item_can_use?(@item.id)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
and add this:
Code:
if @item.element_set.include?($data_system.elements.index("Food"))
        if $game_temp.alreadyate != 0
          $game_system.se_play($data_system.buzzer_se)
          return
        else
          $game_temp.alreadyate = @active_battler.index + 1
        end
      end
right beneath the '@item = @item_window.item' line.
Next, still in Scene_Battle 3, find this block of code:
Code:
def update_phase3_basic_command
    # If B button was pressed
    if Input.trigger?(Input::B)
and right beneath the 'if Input.trigger?(Input::B)' line, add this:
Code:
$game_temp.alreadyate = 0 if @active_battler.index == $game_temp.alreadyate
And finally, in Scene_Battle 4, find this line: 'def start_phase4', and add this:
Code:
$game_temp.alreadyate = -2 if $game_temp.alreadyate != 0
right below the '@active_battler = nil' line.
Now you can mark any item that targets your entire party with an element named Food and it'll only let you use one of any item marked with that element per battle o_ob I would reccomend making it usable only in battle <.< Would have to make it call a common event with a script call with
'$game_temp.alreadyate = -2 if $game_temp.in_battle == false' in it if you want to be able to use it outside of battle s:
Also, it will only let 1 person use the item, so if you're using the DBS or something, and have more than 1 of that food type, 2 people won't be able to use it on the same turn. It disables it's use immediately after selecting it, and if you decide to reselect that person's action for that turn, it'll reenable it so a different actor can use it [/confusing] o_ob
 

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