The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => Topic started by: epson777341 on August 23, 2010, 03:21:01 AM

Title: [RESOLVED][RMVX]Dynamically random skills
Post by: epson777341 on August 23, 2010, 03:21:01 AM
So, I have a guy, who has a skill, that randomly uses other skills he knows.

For example:

Guy uses "Randomize"

Then he might use Fire, Ice or Lightning.

What I'm wondering, is if it's possible to let him learn... Quake, then when he uses 'randomize' there's a chance he can use Fire, Ice, Lightning or Quake.

Any thoughts?
Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 27, 2010, 11:48:56 AM
Bump.

Was I being too vague?

I know I have to use Common events, and conditional branches. I'm just stuck on how to use them.
Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 27, 2010, 10:57:26 PM
Long Way:

Check to see what skills the character has. If you don't have skill books, you can just use $game_party.members[1].skills.size to check for how many. Then randomize accordingly.

Short would be a lot more complicated, but shorter.
Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 27, 2010, 11:37:03 PM
I deal with insanely tedious and complicated events everyday.

I'm not too good with scripting and the guy learns his skills in no particular order.

What's the other way, if you don't mind me asking?
Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 28, 2010, 01:56:10 AM
Well, I was thinking of altering the force action command in Game_Interpreter to check if a certain switch is on, which would be turned on and off according to the common event. Then use force action. The problem is, I have no idea if you want randomize to activate only specific skills, or all his skills. If it's specific, it gets even more complicated.
Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 28, 2010, 03:03:59 AM
Well, all but one of his skills, which is the skill that randomizes.
Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 28, 2010, 03:32:55 AM
Oh, then that's easy.

Code: [Select]
module COZZIEKUNS
  module RANDOMIZE
    ACTOR_ID = 1 # Actor ID of the person with the skill "Randomize".
    SWITCH_ID = 1 # ID of the Switch that activates with the skill "Randomize".
    SKILL_ID = 1 # ID of the Skill "Randomize".
  end
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter 
  #--------------------------------------------------------------------------
  # * Force Action
  #--------------------------------------------------------------------------
  def command_339
    loop do
      random_skill = rand($game_actors[COZZIEKUNS::RANDOMIZE::ACTOR_ID].skills.size) + 1
      break if random_skill != COZZIEKUNS::RANDOMIZE::SKILL_ID
    end
    iterate_battler(@params[0], @params[1]) do |battler|
      next unless battler.exist?
      battler.action.kind = @params[2]
      if battler.action.kind == 0
        battler.action.basic = @params[3]
      else
        if $game_switches[COZZIEKUNS::RANDOMIZE::SWITCH_ID]
          battler.action.skill_id = random_skill
        else
          battler.action.skill_id = @params[3]
        end
      end
      if @params[4] == -2                   # Last target
        battler.action.decide_last_target
      elsif @params[4] == -1                # Random
        battler.action.decide_random_target
      elsif @params[4] >= 0                 # Index designation
        battler.action.target_index = @params[4]
      end
      battler.action.forcing = true
      $game_troop.forcing_battler = battler
      @index += 1
      return false
    end
    return true
  end
end
Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 30, 2010, 03:08:43 AM
Hmmm...

Doesn't seem to be working..

He uses randomize and that's it.
Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 30, 2010, 03:11:14 AM
Sorry for not explaining this to you. Well, what your supposed to do is:

Make the skill "Randomize" link to a common event.
Check the switch (SWITCH_ID) to ON.
Force Action: Anything.

And that's it.

Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 30, 2010, 04:01:47 AM
That's weird. Use this for now:

Code: [Select]
module COZZIEKUNS
  module RANDOMIZE
    ACTOR_ID = 1 # Actor ID of the person with the skill "Randomize".
    SWITCH_ID = 1 # ID of the Switch that activates with the skill "Randomize".
    SKILL_ID = 1 # ID of the Skill "Randomize".
  end
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter 
  #--------------------------------------------------------------------------
  # * Force Action
  #--------------------------------------------------------------------------
  def command_339
    random_skill = rand($game_actors[COZZIEKUNS::RANDOMIZE::ACTOR_ID].skills.size) + 1
    iterate_battler(@params[0], @params[1]) do |battler|
      next unless battler.exist?
      battler.action.kind = @params[2]
      if battler.action.kind == 0
        battler.action.basic = @params[3]
      else
        if $game_switches[COZZIEKUNS::RANDOMIZE::SWITCH_ID]
          battler.action.skill_id = random_skill
        else
          battler.action.skill_id = @params[3]
        end
      end
      if @params[4] == -2                   # Last target
        battler.action.decide_last_target
      elsif @params[4] == -1                # Random
        battler.action.decide_random_target
      elsif @params[4] >= 0                 # Index designation
        battler.action.target_index = @params[4]
      end
      battler.action.forcing = true
      $game_troop.forcing_battler = battler
      @index += 1
      return false
    end
    return true
  end
end

Which means he has a chance of using randomize again.
Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 30, 2010, 04:08:01 AM
I'm getting an error.

For the first code you gave me:

undefined local variable or method 'random_skill' for
#<Game_Interpreter:0xb1979a0>


When I tried the second code, he used a skill he didn't have. He used Skill #4 when his randomize skill is #220

EDIT: He'll use a random skill from #1 to #however many skills he knows.
Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 30, 2010, 04:09:32 AM
That's weird. I'll have to check it out later though. Sorry for the inconvenience.
Title: Re: [RMVX]Dynamically random skills
Post by: erenik on August 30, 2010, 02:51:19 PM
The kind of common event you are looking for should be pretty simple to do.
Just a loop, conditional branches for each skill that may be usable in the random-skill, and loop-breaks whenever a skill got chosen and casted.

This will only properly work if your characters are locked however... like the 1st char always is Actor No. 1. If you want that random ability to work no matter how your characters are grouped you need it in script, yeah.

Gonna try to show it with event code/whatever:
I skipped all "Else" clauses that wouldn't affect the code beside making it less readable.

@>Loop
     @>Control Variables: [000#: Random] = Random No. (1...# skills usable by the ability)
     @>Conditional Branch: Variable [000#: Random] == 1
          @>Conditional Branch: [CharacterX] is [Skill A] learned
               @>Force action: Actor No.1, [Skill A], Random, Execute Now
               @>Exit Event Processing or Break Loop
     @>Conditional Branch: Variable [000#: Random] == 2
          @>Conditional Branch: [CharacterX] is [Skill B] learned
               @>Force action: Actor No.1, [Skill B], Random, Execute Now
               @>Exit Event Processing or Break Loop

        .....

     @>Conditional Branch: Variable [000#: Random] == # skills usable by ability
          @>Conditional Branch: [CharacterX] is [Skill Omega] learned
               @>Force action: Actor No.1, [Skill Omega], Last Target, Execute Now
               @>Exit Event Processing or Break Loop

 : Repeat Above (Until a usable skill has been randomly selected and executed, at which point the Event or Loop will stop processing and the battle should then proceed as normal.)

Now I lost track of where I placed that new event on my map... x_x
Hope this helps.
Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 30, 2010, 03:59:57 PM
Wouldn't work, My characters can be in any position...

Thanks anyway.
Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 30, 2010, 10:03:32 PM
Code: [Select]
module COZZIEKUNS
  module RANDOMIZE
    ACTOR_ID = 1 # Actor ID of the person with the skill "Randomize".
    SWITCH_ID = 1 # ID of the Switch that activates with the skill "Randomize".
    SKILL_ID = 1 # ID of the Skill "Randomize".
  end
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Force Action
  #--------------------------------------------------------------------------
  def command_339
    random_skill = 0
    loop do
      random_skill = rand($game_actors[COZZIEKUNS::RANDOMIZE::ACTOR_ID].skills.size) + 1
      break if random_skill != COZZIEKUNS::RANDOMIZE::SKILL_ID
    end
    iterate_battler(@params[0], @params[1]) do |battler|
      next unless battler.exist?
      battler.action.kind = @params[2]
      if battler.action.kind == 0
        battler.action.basic = @params[3]
      else
        if $game_switches[COZZIEKUNS::RANDOMIZE::SWITCH_ID]
          battler.action.skill_id = random_skill
        else
          battler.action.skill_id = @params[3]
        end
      end
      if @params[4] == -2                   # Last target
        battler.action.decide_last_target
      elsif @params[4] == -1                # Random
        battler.action.decide_random_target
      elsif @params[4] >= 0                 # Index designation
        battler.action.target_index = @params[4]
      end
      battler.action.forcing = true
      $game_troop.forcing_battler = battler
      @index += 1
      return false
    end
    return true
  end
end

I actually tested this code, so I'm really sure it works this time.
Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 31, 2010, 12:28:34 AM
Argh, nope.

He still uses a random skill from 1 to 'however many skills he has'

Could it be because I'm using Battle engine Melody?
Title: Re: [RMVX]Dynamically random skills
Post by: cozziekuns on August 31, 2010, 01:37:13 AM
Maybe, but it's probably my lack of judgement.

Code: [Select]
module COZZIEKUNS
  module RANDOMIZE
    ACTOR_ID = 1 # Actor ID of the person with the skill "Randomize".
    SWITCH_ID = 1 # ID of the Switch that activates with the skill "Randomize".
    SKILL_ID = 1 # ID of the Skill "Randomize".
  end
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Force Action
  #--------------------------------------------------------------------------
  def command_339
    random_skill = 0
    loop do
      random_skill = rand($game_actors[COZZIEKUNS::RANDOMIZE::ACTOR_ID].skills.size)
      break if random_skill != COZZIEKUNS::RANDOMIZE::SKILL_ID
    end
    iterate_battler(@params[0], @params[1]) do |battler|
      next unless battler.exist?
      battler.action.kind = @params[2]
      if battler.action.kind == 0
        battler.action.basic = @params[3]
      else
        if $game_switches[COZZIEKUNS::RANDOMIZE::SWITCH_ID]
          battler.action.skill_id = $game_actors[COZZIEKUNS::RANDOMIZE::ACTOR_ID].skills[random_skill].id
        else
          battler.action.skill_id = @params[3]
        end
      end
      if @params[4] == -2                   # Last target
        battler.action.decide_last_target
      elsif @params[4] == -1                # Random
        battler.action.decide_random_target
      elsif @params[4] >= 0                 # Index designation
        battler.action.target_index = @params[4]
      end
      battler.action.forcing = true
      $game_troop.forcing_battler = battler
      @index += 1
      return false
    end
    return true
  end
end

This SHOULD work, but seeing as I've been saying that a lot, I'm not so sure now.



Title: Re: [RMVX]Dynamically random skills
Post by: epson777341 on August 31, 2010, 02:36:25 AM
Awesome, it works.

Thanks a lot, Cozziekuns!

I'll change the topic to [Resolved]