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.

Watch and learn?

How would I go about writing a small script to check if an actor is in the battling party, and then checking if another certain actor uses a skill, and then having the actor I checked for earlier learn that skill? I am trying to make it so that if an actor is in the battling party when another actor unleashes a certain skill, that actor learns by observation. also, is there a way to set it so that the actor that learns by observation has to watch that skill more than once?
 
Checking if actor is in party:
Code:
$game_party.actors.include?($game_actors[actor_id])

Checking if battler uses a skill (In Scene_Battle 4)
Code:
  #--------------------------------------------------------------------------

  # * Make Skill Action Results

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

  def make_skill_action_result

    if @active_battler.is_a?(Game_Actor)

      # learn skill by @active_battler.current_action.skill_id

    end

    # ...

  end

Syntax to learn a skill:
Code:
$game_actors[actor_id].learn_skill(skill_id)


This script should take care of everything:
Code:
module WatchAndLearn

  Actors = []

  Skills_That_Can_Be_Learned = []

  Can_Learn_From_Enemies = false

end

 

class Scene_Battle

  alias_method :seph_watchandlearn_scnbtl_msar, :make_skill_action_result

  def make_skill_action_result

    if @active_battler.is_a?(Game_Actor) || WatchAndLearn::Can_Learn_From_Enemies

      skill_id = @active_battler.current_action.skill_id

      if WatchAndLearn::Skills_That_Can_Be_Learned.include?(skill_id)

        for actor in $game_party.actors

          if WatchAndLearn::Actors.include?(actor.id)

            actor.learn_skill(skill_id)

          end

        end

      end

    end

    seph_watchandlearn_scnbtl_msar

  end

end

Setup
Foe each actor that can learn skills from watching, add their actor ids to the Actors array:
- Example: Actor 3 & 5
Code:
  Actors = [3, 5]

For each skill that can be learned this way, add the skill id into the Skills_That_Can_Be_Learned list (as you did above)

Finally, if you can learn from enemies, make that line = true

Let me know how it works
 
Just insert that script I gave you above Main. Then follow the setup instructions in the post. I didn't do that "way to set it so that the actor that learns by observation has to watch that skill more than once" but I did everything else for you.

The top part of the post was just for learning purposes for you.
 
Let me guess. The fact that I forgot to mention that I am using VX means that the error:

Script 'watch and learn' line 8: NameError occurred.
undefined method 'make_skill_action_result' for class 'scene_battle'

Will occur.
 
I apologize for not having the solution you are looking for, but my question is to Sephiroth who posted the script but for XP.

Is there any way to get a message show up during battle that says a character has learned an ability after seeing it through this script?

Please and thank you my good sir!
 

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