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.

HBGames

Hey all!

This topic is for scripts snippets made specifically for providing extra building blocks. Both scripts to you have copy-paste and scripts which are small to fit in the call script window are fine.
Here is for example a snippet I cooked up which can help in spicing up battles:

[rgss]class Interpreter
  ##
  # Battler id (-1 returned when not in battle)
  #
  def get_battler_id(variable=id)
    unless $game_temp.in_battle
      return $game_variables[variable] = -1
    end
    $game_variables[variable] = $scene.get_active_battler_id
    return
  end
 
  ##
  # Battler id (-1 returned when not in battle)
  #
  def get_battler_index(variable=id)
    unless $game_temp.in_battle
      return $game_variables[variable] = -1
    end
    $game_variables[variable] = $scene.get_active_battler_index
    return
  end
 
  ##
  # Battler enemy? (Return false when not in battle)
  #
  def is_battler_enemy?(switch=id)
    unless $game_temp.in_battle
      $game_switches[switch] = false
      return true
    end
    $game_switches[switch] = $scene.instance_eval("@active_battler.is_a?(Game_Enemy)")
    return true
  end
end
 
class Scene_Battle
  ##
  # Return the index of the current active battler. (-1 with no active battler)
  #
  def get_active_battler_id
    unless @active_battler.nil?
      return @active_battler.id
    end
    return -1
  end
 
  ##
  # Return the index of the current active battler. (-1 with no active battler)
  #
  def get_active_battler_index
    unless @active_battler.nil?
      return @active_battler.index
    end
    return -1
  end
end
[/rgss]

You can then use a script call where you call the methods. It could for example be:
[rgss]get_battler_id(2)
get_battler_index(3)
is_battler_enemy?(1)
[/rgss]

get_battler_id(2) will set variable 2 to be the id of the battler. (The one they have in the database) this is the one you'll want.
get_battler_index(3) will set variable 3 to the index of the battler. If Arshes is the left-most hero then the index will be 0, then 1, then 2, etc.
is_battler_enemy?(1) will set switch 1 to ON if the battler is an enemy and OFF otherwise.

When I talk about battler I talk about the one who triggered common event. I.e. the one doing the skill.

*hugs*
- Zeriab

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