Aslanemperor 49 Posted January 17 Hey! I'm not sure how often Yanfly checks their scripts page for questions, so I'm posting this here as well to see if someone knows the answer. I'm wondering if there's a way to have the script choose a skill within a range instead of a single skill. This is for my wizard character, who is using something like the Caster weapon from Outlaw Star. Anyway, hopefully someone has a clue on this topic. Share this post Link to post Share on other sites
roninator2 258 Posted January 18 (edited) This will do a range 10, 15. Working on having it as a list. 1, 2, 3, 4 etc. Added list option Spoiler # ╔═════════════════════════════════════╦════════════════════╗ # ║ Title: Weapon Attack Replace Mod ║ Version: 1.01 ║ # ║ Author: Roninator2 ║ ║ # ╠═════════════════════════════════════╬════════════════════╣ # ║ Function: ║ Date Created ║ # ║ ╠════════════════════╣ # ║ Add on function to Yanfly's script ║ 18 Jan 2022 ║ # ╚═════════════════════════════════════╩════════════════════╝ # ╔══════════════════════════════════════════════════════════╗ # ║ Requires: Yanfly - Weapon Attack Replace ║ # ╚══════════════════════════════════════════════════════════╝ # ╔══════════════════════════════════════════════════════════╗ # ║ Instructions: Put below Yanfly's script ║ # ║ ║ # ║ Adds options to select a random skill in either ║ # ║ A range or from the list created in the note tags ║ # ║ ║ # ║ Also has the option to change the skill tp/mp cost ║ # ║ But will not change it if the skill tp/mp cost is lower ║ # ║ Does not have an affect on selecting skills ║ # ║ If the actor does not have enough TP/MP to start with ║ # ║ then the skill will not be selected. ║ # ║ ║ # ║ Skill Range: ║ # ║ <skill range: 5, 9> ║ # ║ first skill, to last skill ║ # ║ a random one will be picked (5, 6, 7, 8, 9) ║ # ║ ║ # ║ Skill List: ║ # ║ <skill list: 4, 8, 12, 22> ║ # ║ Randomly select one of the skills in the list ║ # ║ ║ # ║ Skill TP Cost: ║ # ║ <skill tp: 5> ║ # ║ will set the new skill used 5 tp cost ║ # ║ if the actor does not have enough tp or the skill tp ║ # ║ cost is lower, this will not have any effect ║ # ║ ║ # ║ Skill MP Cost: ║ # ║ <skill mp: 5> ║ # ║ will set the new skill used 5 mp cost ║ # ║ if the actor does not have enough mp or the skill mp ║ # ║ cost is lower, this will not have any effect ║ # ╚══════════════════════════════════════════════════════════╝ # ╔══════════════════════════════════════════════════════════╗ # ║ Updates: ║ # ║ 1.00 - 18 Jan 2022 - Initial publish ║ # ╚══════════════════════════════════════════════════════════╝ # ╔══════════════════════════════════════════════════════════╗ # ║ Terms of use: ║ # ║ Follow the Original Authors terms ║ # ╚══════════════════════════════════════════════════════════╝ module YEA module REGEXP module BASEITEM SKILL_RANGE = /<(?:SKILL_RANGE|skill range):[ ](\d+),[ ](\d+)>/i SKILL_LIST = /<(?:SKILL_LIST|skill list):[ ]*(\d+(?:\s*,\s*\d+)*)>/i SKILL_TP = /<(?:SKILL_TP|skill tp):[ ](\d+)>/i SKILL_MP = /<(?:SKILL_MP|skill mp):[ ](\d+)>/i end # BASEITEM module WEAPON SKILL_RANGE = /<(?:SKILL_RANGE|skill range):[ ](\d+),[ ](\d+)>/i SKILL_LIST = /<(?:SKILL_LIST|skill list):[ ]*(\d+(?:\s*,\s*\d+)*)>/i SKILL_TP = /<(?:SKILL_TP|skill tp):[ ](\d+)>/i SKILL_MP = /<(?:SKILL_MP|skill mp):[ ](\d+)>/i end # WEAPON end # REGEXP end # YEA class RPG::BaseItem #-------------------------------------------------------------------------- # public instance variables #-------------------------------------------------------------------------- attr_accessor :skill_range_start attr_accessor :skill_range_end attr_accessor :skill_list_pick attr_accessor :skill_tp_r2 attr_accessor :skill_mp_r2 #-------------------------------------------------------------------------- # common cache: load_notetags_war #-------------------------------------------------------------------------- alias r2_load_war_92347fhb load_notetags_war def load_notetags_war #--- self.note.split(/[\r\n]+/).each { |line| case line #--- when YEA::REGEXP::BASEITEM::SKILL_RANGE @skill_range_start = $1.to_i @skill_range_end = $2.to_i when YEA::REGEXP::BASEITEM::SKILL_LIST list = $1 change = list.split(",") @skill_list_pick = change.map(&:to_i) when YEA::REGEXP::BASEITEM::SKILL_TP @skill_tp_r2 = $1.to_i when YEA::REGEXP::BASEITEM::SKILL_MP @skill_mp_r2 = $1.to_i #--- end } # self.note.split #--- r2_load_war_92347fhb end end # RPG::BaseItem class RPG::Weapon < RPG::EquipItem #-------------------------------------------------------------------------- # public instance variables #-------------------------------------------------------------------------- attr_accessor :skill_range_start attr_accessor :skill_range_end attr_accessor :skill_list_pick attr_accessor :skill_tp_r2 attr_accessor :skill_mp_r2 #-------------------------------------------------------------------------- # common cache: load_notetags_war #-------------------------------------------------------------------------- alias r2_load_notetags_war_9237u4bv load_notetags_war def load_notetags_war #--- self.note.split(/[\r\n]+/).each { |line| case line #--- when YEA::REGEXP::BASEITEM::SKILL_RANGE @skill_range_start = $1.to_i @skill_range_end = $2.to_i when YEA::REGEXP::BASEITEM::SKILL_LIST list = $1 change = list.split(",") @skill_list_pick = change.map(&:to_i) when YEA::REGEXP::BASEITEM::SKILL_TP @skill_tp_r2 = $1.to_i when YEA::REGEXP::BASEITEM::SKILL_MP @skill_mp_r2 = $1.to_i #--- end } # self.note.split r2_load_notetags_war_9237u4bv #--- end end # RPG::Weapon class Game_BattlerBase #-------------------------------------------------------------------------- # new method: set_skill_tp_replace #-------------------------------------------------------------------------- def set_skill_tp_replace tp = skill_tp_replace if actor? return tp end #-------------------------------------------------------------------------- # new method: set_skill_mp_replace #-------------------------------------------------------------------------- def set_skill_mp_replace mp = skill_mp_replace if actor? return mp end #-------------------------------------------------------------------------- # overwrite method: attack_skill_id #-------------------------------------------------------------------------- def attack_skill_id skill = weapon_attack_skill_id if actor? range = weapon_range_attack_id if actor? sklist = weapon_list_skill_id if actor? attack = sklist.nil? ? (range.nil? ? (skill.nil? ? nil : skill) : range) : sklist if actor? skl = attack if !attack.nil? && (attack > 0) player = $game_actors[actor.id] skltp = $data_skills[attack] return skl if player.tp > skltp.tp_cost end return YEA::WEAPON_ATTACK_REPLACE::DEFAULT_ATTACK_SKILL_ID end end # Game_BattlerBase class Game_Actor < Game_Battler attr_accessor :skill_range_r2 attr_accessor :skill_list_r2 #-------------------------------------------------------------------------- # new method: skill_tp_replace #-------------------------------------------------------------------------- def skill_tp_replace for weapon in weapons next if weapon.nil? tp = weapon.skill_tp_r2 return tp if !tp.nil? return nil end end #-------------------------------------------------------------------------- # new method: skill_mp_replace #-------------------------------------------------------------------------- def skill_mp_replace for weapon in weapons next if weapon.nil? mp = weapon.skill_mp_r2 return mp if !mp.nil? return nil end end #-------------------------------------------------------------------------- # new method: weapon_list_skill_id #-------------------------------------------------------------------------- def weapon_list_skill_id @skill_list_r2 = false for weapon in weapons next if weapon.nil? sklist = weapon.skill_list_pick @skill_list_r2 = true if !sklist.nil? return nil if sklist.nil? num = sklist.size - 1 pick = rand(num) skill = sklist[pick] return skill unless skill.nil? return nil end end #-------------------------------------------------------------------------- # new method: weapon_range_attack_id #-------------------------------------------------------------------------- def weapon_range_attack_id @skill_range_r2 = false for weapon in weapons next if weapon.nil? skstart = weapon.skill_range_start skend = weapon.skill_range_end skrange = skend.to_i - skstart.to_i sksel = rand(skrange) + skstart.to_i @skill_range_r2 = true if !sksel.nil? return sksel unless sksel.nil? return nil end end end # Game_Actor class Scene_Battle < Scene_Base #-------------------------------------------------------------------------- # overwrite method: command_attack #-------------------------------------------------------------------------- def command_attack @skill = $data_skills[BattleManager.actor.attack_skill_id] tp = BattleManager.actor.set_skill_tp_replace mp = BattleManager.actor.set_skill_mp_replace @skill.tp_cost = tp if !tp.nil? && (BattleManager.actor.tp > tp) && (@skill.tp_cost > tp) && (BattleManager.actor.skill_range_r2 == true || BattleManager.actor.skill_list_r2 == true) @skill.mp_cost = mp if !mp.nil? && (BattleManager.actor.mp > mp) && (@skill.mp_cost > mp) && (BattleManager.actor.skill_range_r2 == true || BattleManager.actor.skill_list_r2 == true) BattleManager.actor.input.set_skill(@skill.id) if $imported["YEA-BattleEngine"] status_redraw_target(BattleManager.actor) $game_temp.battle_aid = @skill if @skill.for_opponent? select_enemy_selection elsif @skill.for_friend? select_actor_selection else next_command $game_temp.battle_aid = nil end else if !@skill.need_selection? next_command elsif @skill.for_opponent? select_enemy_selection else select_actor_selection end end end end Edited January 18 by roninator2 updated script 1 Share this post Link to post Share on other sites
Aslanemperor 49 Posted January 18 So, I'm completely untrained when it comes to code. Where do I add this in? Honestly, I was hoping it would be as easy as a damage formula, maybe a single line of code. Is this the only way to get that effect? Share this post Link to post Share on other sites
roninator2 258 Posted January 18 As with all scripts they go in the script editor. You can't expect to have a modification to a script function without putting in some code. Damage formulas can not make changes to the skill used in that manner. As the name says, it's the damage formula, not skill selection formula. You said you wanted a range. How did you expect to have that work? I'm asking because maybe you have an idea that is possible. I've almost got the list selection working. One thing I've noticed though is that you will not be able to attack unless you have enough tp for the skill. So having a random selection will sometimes cause the actor to not act or not allow you to select attack. Share this post Link to post Share on other sites
Aslanemperor 49 Posted January 18 I kinda figured it would go into the script editor. I was more wondering if it should be by itself, or is this an edit to the Yanfly script I'm asking about. I kinda hoped that maybe there was some bit of shorthand the same way as when I have my character talking I can use "/N[001]" to make the speech editor understand I want to list the player's chosen name in that spot. Wishful thinking, I guess. Currently, the Yanfly script works so that you simply put "<attack skill: ###>" and whatever number you put in becomes the number for the attack. I was hoping that someone knew a way to make that be a range of skills instead of just one specific one. TP wouldn't be an issue with what I was thinking of. I was thinking of a range between skill number slots because I tend to keep my skills very orderly. I wanted to make it so that the player could equip different versions of the gun and how strong the spell cast would be somewhat random when using the gun. I don't want to make it to complex and I don't want to work outside the Yanfly script if I can help it. This is only my second game, and I'm trying to take things slow getting used to scripts. Share this post Link to post Share on other sites
roninator2 258 Posted January 18 6 hours ago, Aslanemperor said: a range of skills The code I posted previously and now the finished product will do just that. The choice of TP swap and MP swap is an option. 6 hours ago, Aslanemperor said: an edit to the Yanfly script Yes. require yanfly's script. 6 hours ago, Aslanemperor said: I don't want to make it to complex It's your choice to use as little or as much as you want for the note tags. Share this post Link to post Share on other sites
Aslanemperor 49 Posted January 18 Nice! the edit makes things much clearer, thanks! I think this solves my issue! 1 Share this post Link to post Share on other sites