RMMZ Trying to write a common event to play a message when learning a skill

Oggy

Villager
Member
Joined
Jun 1, 2022
Messages
24
Reaction score
12
First Language
English
Primarily Uses
RMMZ
I'm trying to use an item to learn a skill. In MZ there is an option to add a skill on use, however the item doesn't display a message saying you have learned said skill. I want to create a common event (as generic as possible) that basically calls on the obtainskill message. This is what I tried as a common event. It doesn't give an error but does nothing when a skill book is used.

Game_Actor.prototype.displayObtainSkill = function(newSkills) {
const text = TextManager.obtainSkill.format(this._name, skill.iconIndex, skill.name);
}

Any help would be great.
Thanks
 
Last edited:

KawaiiKid

Local Weeb
Veteran
Joined
Oct 13, 2015
Messages
389
Reaction score
214
First Language
English
Primarily Uses
RMMV
If you can't figure it out in Javascript, it would be incredibly easy to event~
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
509
Reaction score
485
First Language
English
Primarily Uses
RMMZ
There are a surprisingly large number of reasons why that script call didn't work for you. But before getting into how to fix it, it'd be helpful to have a better idea of exactly what you're trying to do. Can you please explain why you don't want to just use a "Show Text" event command, and just type "You have learned Blah Blah Blah" in it?

Is it that you intend to have a ton of these skill learning items, and you don't want to have to make a separate common event (or conditional branch) for each of them, or something like that?
 

Oggy

Villager
Member
Joined
Jun 1, 2022
Messages
24
Reaction score
12
First Language
English
Primarily Uses
RMMZ
@Arthran
I want to have an message show up when you use an item to learn a skill.

The reason I haven't used show text is because I dont want to create a massive amount of messages/events (ie one for each spell and each person who can learn each spell) As far as I now with show text there is no way to make an ambiguous message that will detect the actor and the skill and the skill icon. Which is what i have the obtainskill message set to show. So i was trying to call on the obtainskill message for item use skill learning.

@KawaiiKid
Full eventing of it is what i considered first. It works but its a lot of extra messages. I was hoping that i could use the learn skill effect on the item and trigger an ambiguous message so it would be handled much simpler.
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
509
Reaction score
485
First Language
English
Primarily Uses
RMMZ
Here, try this script call in your common event:

JavaScript:
const actor = $gameActors.actor($gameTemp.lastActionData(2));
const item = $dataItems[$gameTemp.lastActionData(1)];

for (const effect of item.effects) {
    if (effect?.code === Game_Action.EFFECT_LEARN_SKILL) {
        const skill = $dataSkills[effect.dataId];
        $gameMessage.add(`${actor.name()} has learned \\I[${skill.iconIndex}]${skill.name}.`);
    }
}

*** Note to anyone who stumbles across this thread and wants to try this code: This will only work for MZ. It would be a bit trickier to pull off in MV.
 

Oggy

Villager
Member
Joined
Jun 1, 2022
Messages
24
Reaction score
12
First Language
English
Primarily Uses
RMMZ
Here, try this script call in your common event:

JavaScript:
const actor = $gameActors.actor($gameTemp.lastActionData(2));
const item = $dataItems[$gameTemp.lastActionData(1)];

for (const effect of item.effects) {
    if (effect?.code === Game_Action.EFFECT_LEARN_SKILL) {
        const skill = $dataSkills[effect.dataId];
        $gameMessage.add(`${actor.name()} has learned \\I[${skill.iconIndex}]${skill.name}.`);
    }
}

*** Note to anyone who stumbles across this thread and wants to try this code: This will only work for MZ. It would be a bit trickier to pull off in MV.
Thank you very much! That is exactly what I was trying to do. My js code knowledge is not as good as I would like. Some of the simpler stuff I've been able to work out but this one was rough. I was looking at the effects section of the code and recognize come of the parts you have there.

Again, thanks for helping me get this fixed up.
 

Oggy

Villager
Member
Joined
Jun 1, 2022
Messages
24
Reaction score
12
First Language
English
Primarily Uses
RMMZ
After further testing, the only problem this creates is, it makes a consumable reuseable on the same target for some reason. Without the script call it auto prevents reusing a learn skill effect if they have the skill. In its current form it will be reusable and consume the item even if they already know the skill. For basic consumables that is still fine. For my purposes I need the reuse prevent.

I was able to convert it into a plugin that still makes the message appear and prevents the item reuse as intended for learn skills.

Game_Action.prototype.apply = function(target) {
const result = target.result();
this.subject().clearResult();
result.clear();
result.used = this.testApply(target);
result.missed = result.used && Math.random() >= this.itemHit(target);
result.evaded = !result.missed && Math.random() < this.itemEva(target);
result.physical = this.isPhysical();
result.drain = this.isDrain();
if (result.isHit()) {
if (this.item().damage.type > 0) {
result.critical = Math.random() < this.itemCri(target);
const value = this.makeDamageValue(target, result.critical);
this.executeDamage(target, value);
}
for (const effect of this.item().effects) {
this.applyItemEffect(target, effect);
if (effect?.code === Game_Action.EFFECT_LEARN_SKILL) {
const item = $dataItems[$gameTemp.lastActionData(1)];
const skill = $dataSkills[effect.dataId];
SceneManager.push(Scene_Map);
$gameMessage.add(`${target.name()} has learned \\I[${skill.iconIndex}]${skill.name}`);
}
}
this.applyItemUserEffect(target);
}
this.updateLastTarget(target);
};

It DOES overwrite the code for this section so may conflict with other plugins. It's probably not as good as it could be, but it works perfect for my project, and I thought I would share it.

Thanks again @Arthran for the assist!
 

Latest Threads

Latest Posts

Latest Profile Posts

I just got all of my wisdom teeth out today, thankfully I have the rest of the week off.
Man I am learning I am bad at naming armor lmao.
The game's opening, now fully polished! :LZScheeze:





Aaand, here's me working on it in today's "Game Making Every Day" video! :LZSooo:

Hello! Can anyone help me? I followed making cooking tutorial for RPG Maker MV. But for some reason buff state that food gives doesn't work in overworld. It disappears. What am I supposed to do?
A shotgun is not a rifle. Huh.

Forum statistics

Threads
124,406
Messages
1,163,384
Members
163,201
Latest member
YoBa
Top