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.

Script to Add/Remove Skills to a character...

I need a script that when I call it through an event, I can set options that will add or remove skills randomly from the numbers of skills I set.

(say I have a list of 20 skills for a character. 1-21 in the list. I want him to only have 5 of those at random, so I call the script and set an option for the 1 - 21 and then 5 for the # of skills he gets)

Possible?

I need it for the DBS, non-SDK please ^_^

EDIT:
Also, it might be needed to let me list a set of skills to have added randomly if they would be outside the list... like 1 - 21 ; 23 ; 26 or something like that, so it would give me a skill that is either #'s 1 through 21, 23, or 26.
 
Will this do?

Code:
class Game_Temp
  
  attr_accessor :potential_skills
  attr_accessor :number_of_skills
  attr_accessor :random_actors
  
  alias before_fomar_initialize initialize
  def initialize
    before_fomar_initialize
    @potential_skills = []
    @number_of_skills = 0
    @random_actors = []
  end
  
end

class Scene_Battle
  
  alias before_fomar_main main
  def main
    unless ($game_temp.random_actors == [] or $game_temp.potential_skills == []) or ($game_temp.number_of_skills == 0)
      for i in $game_temp.random_actors
        actor = $game_actors[i]
        if $game_party.actors.include?(actor)
          skills = $game_temp.potential_skills.clone
          unless $game_temp.number_of_skills > $game_temp.potential_skills.size
            y = $game_temp.number_of_skills
          else
            y = $game_temp.potential_skills.size
          end
          for k in 0...y
            x = rand(skills.size)
            actor.learn_skill(skills[x])
            skills.delete(x)
          end
        end
      end
    end
    before_fomar_main
  end
  
  alias before_fomar_battle_end battle_end
  def battle_end(result)
    unless ($game_temp.random_actors == [] or $game_temp.potential_skills == []) or ($game_temp.number_of_skills == 0)
      for i in $game_temp.random_actors
        actor = $game_actors[i]
        if $game_party.actors.include?(actor)
          skills = $game_temp.potential_skills.clone
          for k in skills
            actor.forget_skill(k)
          end
        end
      end
    end
    before_fomar_battle_end(result)
  end
  
end

Ok:
@potential_skills = []
@number_of_skills = 0
@random_actors = []

In potential skills add the id of the skills which can be randomly learnt eg.
[1, 2, 3]

In number of skills the amound of random skills.

And in random actors place in the id/s of the character/s.

To edit through an event use call script and use:
$game_temp.potential_skills = [1, 2, 3]
$game_temp.number_of_skills = 1
$game_temp.random_actors = [1]
 
Upon testing, I can't get this to work after I do it the first.

I have a skill which removes every skill besides it and it adds 5 random skills.

It removes all the skills gotten randomly, but it does NOT readd 5 new skills.
 
Maybe I misunderstood your request I didn't realise you wished to gain random skills in battle and lose them at the end.

If this doesn't work or doesn't work the way you wanted I'll write another version in the morning but be very clear about what you want it do and where you call it from.
Code:
class Game_Temp
  def random_skills
    unless ($game_temp.random_actors == [] or $game_temp.potential_skills == []) or ($game_temp.number_of_skills == 0)
      for i in $game_temp.random_actors
        actor = $game_actors[i]
        if $game_party.actors.include?(actor)
          skills = $game_temp.potential_skills.clone
          unless $game_temp.number_of_skills > $game_temp.potential_skills.size
            y = $game_temp.number_of_skills
          else
            y = $game_temp.potential_skills.size
          end
          for k in 0...y
            x = rand(skills.size)
            actor.learn_skill(skills[x])
            skills.delete(x)
          end
        end
      end
    end
  end
end

And then call it from the call script event with event with
$game_temp.random_skills

I repeat myself "If this doesn't work or doesn't work the way you wanted I'll write another version in the morning but be very clear about what you want it do and where you call it from."
 
OK basically!
I want it like the first one, with the same inputs, but they have to be able to be changed DURING a battle through a common event, if possible. Don't lose the skills after a battle, but able to be changed during one.

Maybe its my event code, but whenever I try it through a common event, it doesn't work...
 
Ok try this.
Code:
class Game_Party
  
  attr_accessor :potential_skills
  attr_accessor :number_of_skills
  attr_accessor :random_actors
  
  alias before_fomar_initialize initialize
  def initialize
    before_fomar_initialize
    @potential_skills = []
    @number_of_skills = 0
    @random_actors = []
  end
  
end

class Game_Actor
  
  def change_random_skills
    unless ($game_temp.random_actors == [] or $game_temp.potential_skills == []) or ($game_temp.number_of_skills == 0)
      if $game_party.actors.include?(self)
        skills = $game_temp.potential_skills.clone
        for k in skills
          forget_skill(k)
        end
        unless $game_temp.number_of_skills > $game_temp.potential_skills.size
          y = $game_temp.number_of_skills
        else
          y = $game_temp.potential_skills.size
        end
        for k in 0...y
          x = rand(skills.size)
          learn_skill(skills[x])
          skills.delete(x)
        end
      end
    end
  end
  
end
I've changed it so now you edit:
$game_party.potential_skills = [1, 2, 3]
$game_party.number_of_skills = 1
$game_party.random_actors = [1]
For some reason I remember seeing game_temp saved but I was wrong.

To give an actor random skills call either:
$game_actors[id_of_actor].change_random_skills
or
$game_party.actors[position_in_party].change_random_skills
 

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