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.

[Resolved] Calling Battle Through RGSS?

poccil

Sponsor

I've finished a function that allows you to call a battle from script:

pbStartBattle(troopID, canEscape, canLose) - Starts a battle with the specified troop ID ("troopID").  The player may or may not escape (set "canEscape" to true or false), and may or may not be allowed to lose (set "canLose" to true or false).  An optional block specifies the result of the battle.  See the code for an example.

The code follows.

Code:
def pbStartBattle(troopID, canEscape, canLose, &block)
 return if $game_temp.in_battle
 if $game_temp.respond_to?("next_scene")
  # For RPGVX style
  $game_troop.setup(troopID)
  $game_troop.can_escape = canEscape
  $game_troop.can_lose = canLose
  $game_temp.next_scene = "battle"
 else
  # For RPGXP style
  $game_temp.battle_abort = true
  # Set battle calling flag
  $game_temp.battle_calling = true
  $game_temp.battle_troop_id = troopID
  $game_temp.battle_can_escape = canEscape
  $game_temp.battle_can_lose = canLose
 end
 if block_given?
#  The block given takes a single parameter, n, which contains the result of the battle.
#  Example:
#  pbStartBattle(20, true, true) {|n|
#   case n
#    when 0;print "Player won"
#    when 1;print "Player escaped"
#    when 2;print "Player lost"
#   end
#  }
  $game_temp.battle_proc = block
 else
  $game_temp.battle_proc = nil
 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