Script for teaching a skill with an item.

I want to create an item that teaches a skill to the actor that the item is used on. This item is a reward for doing something and I need a way to do this.

A Google search for "learn skill with item" only brings up the same bait-and-switch results on various websites. The websites have titles that say "learn skill from item." but these pages are for a script that introduces an LP system for learning skills, not learning skills from an item.

Ideally, I need something that checks whether the actor can use the skill type that the skill is (such as: skill, magic, dragon, etc) and if the actor can use that skill type, using the item on them teaches the actor that skill. If the actor cannot use the skill type, the game would play the default buzzer sound and the item is not used up.

I plan on setting the skill type to "Skill", which means three out of the four actors could learn this skill.

Could someone draw me up something like that? Please and Thank You.
You can do this through eventing (with a common event checking who is using the item), although the use of the item will throw you out of the menu. If that's a problem, this script could help.

Or, there is a script that restricts who can use an item (and gives a buzzing sound for those who can't). You can find it here. It's what I use for magic scrolls that teach magic only to one magic user in my party and it seems to me it might work fine for you.
why use a script at alol?

You didn't find a script solution BECAUSE NO ONE USES A SCRIPT FOR THIS!!!!
Just go to the database, items, effects and add the "learn skill effect" to your item

And as I( said a few times, start with learning what the engine can do natively before looking for scripts, and work through the tutorials...
The restrict script is a good thing for eliminating those that can't learn the skill.
Use it and it works well.
Or this will also work, but will not prevent the accept sound from playing.
This little script plus the item config will allow the item to be returned if it is not usable.
1700236176804.png

Ruby:
class Game_Actor < Game_Battler
  def learn_item_skill(skill_id, item_id)
    skill = $data_skills[skill_id]
    item = $data_items[item_id]
    learned = false
    self.class.features.each do |ft|
      if ft.code == 41
        learn_skill(skill_id) if ft.data_id == skill.stype_id
        learned = true if ft.data_id == skill.stype_id
      end
    end
    $game_party.gain_item(item, 1) if learned == false
    Sound.play_buzzer if learned == false
  end
end

The values for the learn_skill_item are skill id, and the item being used id.
So in the example given, the skill to learn is skill #26 (heal)
the item being used is item 18 (learn this)


You didn't find a script solution BECAUSE NO ONE USES A SCRIPT FOR THIS!!!!
Just go to the database, items, effects and add the "learn skill effect" to your item
But the problem with this is if the actor is not supposed to learn the skill, can learn the skill even if they do not have the skill type available to them. plus the item is consumed when it is not desired to be consumed if you can't 'learn' the skill.


* second option using the guide of the restrict script suggested above.
Ruby:
class Game_Battler < Game_BattlerBase
  alias r2_item_test_skill_learn   item_test
  def item_test(user, item)
    return false if item.is_a?(RPG::Item) && can_learn(user, item)
    return r2_item_test_skill_learn(user, item)
  end
 
  def can_learn(user, item)
    skill_id = 1
    item.effects.each do |ift|
      if ift.code == 43
        skill_id = ift.data_id
      end
    end
    skill = $data_skills[skill_id]
    user.class.features.each do |ft|
      if ft.code == 41
        return false if ft.data_id == skill.stype_id
      end
    end
    return true if skill_id > 1
    return false
  end
end
Then use the normal add skill command
1700239425853.png
Is this how Szyu's Items Class Restriction works if I do not want the Birdkeeper to be able to use the item?
1700241215739.png


1700241297949.png
It should work like that (I never tried with !, but the instructions say so). Consume should probably be set to Yes, if you only want the item to be used once.
This is what you can do with KItemTeachSkill ACE script:

With one of the following Note Tags you can alter that behavior!
  • Leave a Note in the Item's Note Box for specific Actors
_teach skill actors 1_
  • Leave a Note in the Item's Note Box for specific Classes
_teach skill classes 1_
  • Leave a Note in the Item's Note Box for specific States
_teach skill states 1_

Original thread: https://forums.rpgmakerweb.com/threads/script-for-teaching-a-skill-with-an-item.163017/