I've been trying to create a skill that will cast a random skill from a specific skill type. Scripts like Yanfly's Random Skill Invoke isn't exactly what I need because it needs to be a random selection of skills that the actor already learned.
I.E.
Special skill 'Random' will randomly select a Magic skill from the Actor. If the actor knows the spells Cure, Fire, and Ice, it will randomly cast one of those spells and nothing else.
I've moved this thread to RGSS3 Script Requests . Please be sure to post your threads in the correct forum next time. Thank you.
Oh, I guess there was issue after all. Hm, first, probably easier and safer to make a new array to hold your skills. Second, I didn't consider the issue of the skill itself being selected. Let's see, two ways to deal with this is either to loop the results if that id is selected or to drop the results from the current array. Yanfly's Target Manager shows an array in the example of "everyone but user", so we might be looking at something like this:
random_skill_array = subject.usable_skills
random_skill_array -= $data_skills[RANDOM]
As for skill types, skill_type_sealed under Game_BattlerBase shows stype_id, and usable_skills under Game_Actor shows that the array comes from skills.select, meaning that it returns an array of qualifying items like how you would put all ice cream from your groceries into your freezer. I also checked Window_SkillList.
Anyway, here's the correction, if I'm correct:
#Replace RANDOM with your skill id.
#Replace MAGICTYPE with your type id.
class Game_Actor < Game_Battler
def random_spell_id
random_spell = usable_skills
random_spell -= [$data_skill[RANDOM]] #You could remove this since you said RANDOM skill is a different skill type.
random_spell.select {|item| item.stype_id == MAGICTYPE}
return random_spell.sample.id
end
end
class Game_Action
def set_skill(skill_id)
skill_id = subject.random_spell_id if skill_id == RANDOM
@item.object = $data_skills[skill_id]
self
end
end
If removing the Random skill doesn't work, you could remove that line and try random_spell.select {|item| item.stype_id == MAGICTYPE and item.id != RANDOM} instead. Or since you say RANDOM is a Special and you're only casting a random Magic type, you could just remove the -= data skills line.
Also, I haven't the opportunity to test this, but how would this affect MP? Does the MP get removed based on Random's cost or the Magic's cost, and which cost are you looking for?
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.