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.

Rmxp default battle script problem

Hi guys,

I found out that there is a problem in the default battle system.
The following is the problem:

Enemy will do nothing when they try to use skill without having sufficient SP

For example , if I set an enemy's Maxsp to 100, and he has a skill which costs 100 sp.
so after he used the skill once,the AI still try to use the skill ,thus causing nothing happened
instead of turning in to doing normal attack.

Is there any way to solve it?
 
[create a new state] (triggered when the enemy is low or out of sp)

call it "NO SP" for example...

now in your data base, choose [that enemy's troop/group tab]

set your condition,

then create a conditional branch

3rd tab ~enemy state~

the rest is up to you...

~g/A\/\/\|=|F/A\C|=
 
All right. First off, you haven't even told us what you want the enemy to do instead of the blank action. I assume you want them to choose automaticaly from the other available options, but everyone knows what happens when you assume something. As to the solution, it would require a modification of whatever battle system you are using, at a part of the system that most people wouldn't touch with a ten foot pole. (Not that most people avoid editing battle systems anyway) Anyway, be clear and concise in what you need, and someone will be more likely to finish a script to fill your needs.
 
Try this.. it prevents a skill from being added to the actions list if there is not enough SP
Paste above Main

Code:
class Game_Enemy

  #--------------------------------------------------------------------------

  # * Make Action

  #--------------------------------------------------------------------------

  def make_action

    # Clear current action

    self.current_action.clear

    # If unable to move

    unless self.movable?

      # End Method

      return

    end

    # Extract current effective actions

    available_actions = []

    rating_max = 0

    for action in self.actions

      # Confirm turn conditions

      n = $game_temp.battle_turn

      a = action.condition_turn_a

      b = action.condition_turn_b

      if (b == 0 and n != a) or

         (b > 0 and (n < 1 or n < a or n % b != a % b))

        next

      end

      # Confirm HP conditions

      if self.hp * 100.0 / self.maxhp > action.condition_hp

        next

      end

      # Confirm level conditions

      if $game_party.max_level < action.condition_level

        next

      end

      # Confirm switch conditions

      switch_id = action.condition_switch_id

      if switch_id > 0 and $game_switches[switch_id] == false

        next

      end

      ### CUSTOM CODE - Don't add skill action if enemy is out of SP - BREW

      if action.kind == 1  #skill

        skill_id = action.skill_id

        skill_cost = $data_skills[skill_id].sp_cost

        if @sp < skill_cost

          next

        end

      end

      ### END CUSTOM CODE - BREW

      # Add this action to applicable conditions

      available_actions.push(action)

      if action.rating > rating_max

        rating_max = action.rating

      end

    end

    # Calculate total with max rating value at 3 (exclude 0 or less)

    ratings_total = 0

    for action in available_actions

      if action.rating > rating_max - 3

        ratings_total += action.rating - (rating_max - 3)

      end

    end

    # If ratings total isn't 0

    if ratings_total > 0

      # Create random numbers

      value = rand(ratings_total)

      # Set things that correspond to created random numbers as current action

      for action in available_actions

        if action.rating > rating_max - 3

          if value < action.rating - (rating_max - 3)

            self.current_action.kind = action.kind

            self.current_action.basic = action.basic

            self.current_action.skill_id = action.skill_id

            self.current_action.decide_random_target_for_enemy

            return

          else

            value -= action.rating - (rating_max - 3)

          end

        end

      end

    end

  end

end
 
Glitchfinder":2cnscc2v said:
All right. First off, you haven't even told us what you want the enemy to do instead of the blank action. I assume you want them to choose automaticaly from the other available options, but everyone knows what happens when you assume something. As to the solution, it would require a modification of whatever battle system you are using, at a part of the system that most people wouldn't touch with a ten foot pole. (Not that most people avoid editing battle systems anyway) Anyway, be clear and concise in what you need, and someone will be more likely to finish a script to fill your needs.

Oops...sorry for not explaining clearly.
What I need is simple,just that when enemy has insufficient sp, he'll do normal attack instead of using skill.
 
Brewmeister":3os6xxu7 said:
Try this.. it prevents a skill from being added to the actions list if there is not enough SP
Paste above Main

Code:
class Game_Enemy

  #--------------------------------------------------------------------------

  # * Make Action

  #--------------------------------------------------------------------------

  def make_action

    # Clear current action

    self.current_action.clear

    # If unable to move

    unless self.movable?

      # End Method

      return

    end

    # Extract current effective actions

    available_actions = []

    rating_max = 0

    for action in self.actions

      # Confirm turn conditions

      n = $game_temp.battle_turn

      a = action.condition_turn_a

      b = action.condition_turn_b

      if (b == 0 and n != a) or

         (b > 0 and (n < 1 or n < a or n % b != a % b))

        next

      end

      # Confirm HP conditions

      if self.hp * 100.0 / self.maxhp > action.condition_hp

        next

      end

      # Confirm level conditions

      if $game_party.max_level < action.condition_level

        next

      end

      # Confirm switch conditions

      switch_id = action.condition_switch_id

      if switch_id > 0 and $game_switches[switch_id] == false

        next

      end

      ### CUSTOM CODE - Don't add skill action if enemy is out of SP - BREW

      if action.kind == 1  #skill

        skill_id = action.skill_id

        skill_cost = $data_skills[skill_id].sp_cost

        if @sp < skill_cost

          next

        end

      end

      ### END CUSTOM CODE - BREW

      # Add this action to applicable conditions

      available_actions.push(action)

      if action.rating > rating_max

        rating_max = action.rating

      end

    end

    # Calculate total with max rating value at 3 (exclude 0 or less)

    ratings_total = 0

    for action in available_actions

      if action.rating > rating_max - 3

        ratings_total += action.rating - (rating_max - 3)

      end

    end

    # If ratings total isn't 0

    if ratings_total > 0

      # Create random numbers

      value = rand(ratings_total)

      # Set things that correspond to created random numbers as current action

      for action in available_actions

        if action.rating > rating_max - 3

          if value < action.rating - (rating_max - 3)

            self.current_action.kind = action.kind

            self.current_action.basic = action.basic

            self.current_action.skill_id = action.skill_id

            self.current_action.decide_random_target_for_enemy

            return

          else

            value -= action.rating - (rating_max - 3)

          end

        end

      end

    end

  end

end

Yes! This is what I am asking for!
Thanks again,Brewmeister!

I will credit you for this :thumb:
 

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