Unlocking 'Special' Moves via an item or armour / Common Events with variable names / words?

Hi, RPGMaker forums, sorry if I ramble a bit with this one, been struggling with this for a while now.
I had the idea of letting the player obtain a 'Special Unlock' item, that unlocks a specified special attack for any Actor they want. Each Actor can only have one special attack at a time. It'd look something like this:
1590493062541.png
1590493538825.png

Problem is, I have no idea how to unlock these skills for a specific Actor. I have 'Use Special' as a Skill Type that will be unlocked later on in the game via BOB_BattleCommandList, but I can't figure out how to unlock that skill for the actor that the item is used on. There's the 'Learn Skill' effect but I'd want to also remove any Special the Actor already had, or check if the Actor has a Special 'equipped' and tell the player so. I'd also need to execute a Common Event with the text above, or with different text if the actor already has a Special. I don't know how to call the name of the Actor the item was used on, nor how to use that data in a 'Change Skills' or a 'Show Text' command.

Can anyone think of a proper way to be able to use an item to check if the Actor the item is used on has a specific skill, if ithey don't then unlock a specific skill, if they do then execute a Common Event with the specified actors name in the event?

Sorry if this is a bit of a windy request, I'm probably overthinking this a lot and there's a much simpler way to do this that I haven't thought of yet. I could use an armour or something so the player can actually see what Special is equipped to what actor, I wasn't planning on using armour in my game anyway, changing the names of armours to 'Specials' wouldn't be too difficult. Maybe that could be used to check if the actor has a specific armor equipped and use that as data? I don't know, any help would be appreciated.
Thanks!
Sounds like it would take a lot of eventing to pull off or some clever loops with scripting. To solve one of your issues the way you access the actorId of the actor the item was used on is done with this script call.

$gameParty._targetActorId

to get the name of the actor the item was used on you would do:

$gameActors.actor($gameParty._targetActorId)._name

I would probably set this up by making the item not consumable and have it run a common event that runs a script with some loops.

JavaScript:
var target = $gameActors.actor($gameParty._targetActorId);
var newSkill = 13; //New Skill Learned
var specials = [10, 11, 12, 13]; // put your special skill IDs here as shown.
var skill = [];
for (var i = 0; i < target._skills.length; i++) {
for (var j = 0; j < specials.length; j++) {
  if (target._skills[i] === specials[j]) skill.push(specials[j]);
}
}
if (skill.length > 0) { target.forgetSkill(skill); };
target.learnSkill(newSkill);

(Hope thats right and has no errors I'm tired)
you would just change the newSkill = 13; to whatever Skill ID your Item teaches the actor.
and inside var specials = [n, n, n, n, n]; those are your special skills the loops look for to remove if found.

Then after the script runs you can execute whatever other script calls you need and other eventy stuff. this would just check if your actor has any of your special skills and forget it if they do. if not it would just do nothing and learn the skill. would probably be smart to 'Change Items' and remove the item you used on an actor as well since its not consumable. Also play the animation under the script call too if you play an animation or sound effect etc. The item in the database would pretty much be empty for the most part and let the common event handle everything.

My common event would probably look something like this for each item.

Edit: This would likely mess up if your actor ever has more than 1 special skill at a time and would need a slight edit if thats ever the case.

Edit2: derped and had the conditional branch set wrong, you would want to set the condition to a script call.

$gameActors.actor($gameParty._targetActorId)._skills.contains(13)

where 13 is the skill your item teaches.
Can anyone think of a proper way to be able to use an item to check if the Actor the item is used
Don't use an item, use a special equipment slot.

Add the special slot to the equipment slots in the type tab of the database, then create an equipment that has the special skill you want to grant as a trait, as well as the trait to fix the special equipment slot.
If you then equip the special equipment to an actor, the fix will prevent the player from ever changing that equipment again, while granting the skill during that time as well.

calling the common event would have to be done seperately, but the check for equipment would be used to see if and what the actor has.
calling the common event would have to be done seperately, but the check for equipment would be used to see if and what the actor has.
That's exactly my problem, I don't know how I would get that common event to be executed, let alone with the correct names for the Special and the actor that equipped it. I do like this idea of using armours, though, I've done that exact thing, changing the armor names to Special instead. I said something similar in the post above:
"I could use an armour or something so the player can actually see what Special is equipped to what actor, I wasn't planning on using armour in my game anyway, changing the names of armours to 'Specials' wouldn't be too difficult."



My common event would probably look something like this for each item.
Jeez, this is in-depth! I'll test this out today, see if I can get this working. I'm a complete beginner to scripting so thanks for the tutorial, I'll see what I can do.
Sounds like it would take a lot of eventing to pull off or some clever loops with scripting. To solve one of your issues the way you access the actorId of the actor the item was used on is done with this script call...

This looks like it works!
My common event is shown below, it all works perfectly as far as I can tell.
The only thing left now is to get some text to show something like "<party member that the special was used on> has equipped Chloroblast!" I can't figure out how to find and show that. I only have 4 party members and it wouldn't be hard to just use Ifs and Elses to get a Show Text for any four of them for each Special but I don't know how to do the conditionals for that.
Thanks for all your help!
1590534463962.png
There's a few ways you can go about doing this, if whatever plugin you pick accepts script call values then you can use $gameActors.actor($gameParty._targetActorId)._name to show the name of the actor the item was used on.
Or a very simple way to do this using simple show text would be to throw this inside your common event.

control variables -> Operation set -> Operand script -> $gameActors.actor($gameParty._targetActorId)._name

This would store the name to a game variable.

To show this variables value within a Show Text box you would just

Show Text -> \V[n] Equipped Skill DoThingers!

Where n is the game variables Id number.

If the item was used on Harold this would output: Harold Equipped Skill DoThingers!

This would just overwrite any previous value that variable holds so you would only need to use 1 variable, doesn't matter how many different items use it as its value will be overwritten every time an item is used to display the updated actors name who the item was used on.
Or a very simple way to do this using simple show text would be to throw this inside your common event...
Yup, works perfectly. Thanks so much, Ritter, really appreciate the help. No idea how to close this thread, for anyone who wants to do this in the future this is what my Common Event looks like below. Thanks again!
1590554741456.png
One thing on that last screenshot you posted. What you have here would try to remove skill 169 but it already checks if 169 already exists in the top condition where you say This party member already has special equipped and breaks out of the common event without doing anything else.

I was under the assumption you had other special skills you wanted removed when this one is applied. Something like each actor can only have one special skill at a time type deal. If that is the case then you would want to put those skills that would get removed inside here.

var specials = [n, n, n, n];

this would make the script remove a special skill that isn't the one you are trying to apply.
One thing on that last screenshot you posted. What you have here would try to remove skill 169 but it already checks if 169 already exists in the top condition where you say This party member already has special equipped and breaks out of the common event without doing anything else.

I was under the assumption you had other special skills you wanted removed when this one is applied. Something like each actor can only have one special skill at a time type deal. If that is the case then you would want to put those skills that would get removed inside here.

var specials = [n, n, n, n];

this would make the script remove a special skill that isn't the one you are trying to apply.
Ah, yea, I should probably fix that.
I reckon I'll use some nested conditionals to make it so if you use a Special item on an Actor that already has a Special equipped, it'll give you the Special item back for that skill then apply the new one, basically what you have above.
1590582544823.png

1590582121079.png

This should work properly now. Thanks for all your help, Ritter!

One last thing though, I might also take the advice of Andar here:
Don't use an item, use a special equipment slot.
... by equipping an Armor (renamed to 'Special Slot' or something) that pairs with the skill. I'm struggling to find a way to get a script call to equip a specified armour onto the armour the Actor I've used the item on. I messed around with a script i found online but I'm trash at Javascript and have no idea how to work it in, this is what i have so far:

$gameActors.actor($gameParty._targetActorId).changeEquip(2, $dataArmors[25]);

This is probably a jumble of jscript at the moment. 2 is the equipment slot (i think) and 25 is the armor number, then i tried using the '$gameParty._targetActorId' instead of the 'ActorId' that was in the original script i found here:


Help with this would be great. Thanks again for all you've done here, it's been a great help!
the way its structured already would not consume the item if you already have the skill on that actor assuming you set it up as i said in my first post and set the item so that its not consumable in the database. the idea here was that the item would only execute a common event and then the common event would decide if it should remove the item from the player or not.

the common event i gave you is structured like this:

if actors skills list contains skill Id (aka it has the skill)
say something about having it already
play buzzer sound effect
exit common event

else: (the else here means it does not have that specific skill)
run the script which removes any other special skill the actor may have and add the new skill.
then run any other eventy things you need to after the script runs.

you don't need a lot of if statements and such as you are showing in those screenshots as the single if statement here handles all of that already. the only way the common event will enter the 'else' is if the actor does not have the skill you put inside this.

$gameActors.actor($gameParty._targetActorId)._skills.contains(169);
This script call here checks if the target actor has the skill tied to the id you fed it and returns true or false. so if its true the condition is met(true) and it shows text saying nah no way not applying this skill! but if it returns false it will go into the 'else' and carry on and run the script apply the new skill etc. you can think of that line as the question 'Does this actor have this skill'. top part of the conditional branch is yes and bottom part is no.

you should just make one common event per Skill Add Item and set them up in the same method as the original common event shown.

you can list all of your special skills in specials = [n, n, n, n, n] variable, including the one you are going to add because at the time the script runs you don't have that skill so it won't remove it (this will just make your life easier, less things to edit when setting up the other common events). the skill would only be added after the loops are completed.

in each common event you would just edit the if statement so .contains(another_skill_id_of_yours) instead of 169

and in the script edit the newSkill = anotherskillhere;

so if you were setting up skill 170 you would make copy this common event into a new common event and do this below

if $gameActors.actor($gameParty._targetActorId)._skills.contains(170)
show text saying no way jose you already have this skill!
else
run script and do the rest of the thingers.

do that for each item, its probably the simplest way to handle it using this method and cleaner than having a bunch of nested if statements. one item = one common event. two items = two common events etc etc.

as far as your other thing goes.

i mean if you wanted to go the equip an armor and learn a skill approach instead of using an item i'm sure that wouldn't be too hard to figure out, though it would likely require a small plugin to handle it which would mostly use similar code as the script already provided only a little different. it would likely need to alias the changeEquip function to check for special equipment and maybe use some armor database notetags for convenience. I have no idea if a plugin like that already exists or not, if not it probably wouldn't be too hard to whip one up as i already handle database notetags in a plugin i wrote which wouldn't be hard to convert over to this.

in the end this option would be much easier on you as you would only need to set some notetags inside the notetag field in the database for each of your special armors. let me know and if i have some time i could see about whipping that up.
do that for each item, its probably the simplest way to handle it using this method and cleaner than having a bunch of nested if statements. one item = one common event. two items = two common events etc etc.

The if/elses are to check if the player has a specific skill, not to remove it but to give the player back the Special item that that skill had, as a sort of 'Do you want to swap out <old special> for <new special>', then show the text saying 'Recieved Special <old special>' then '<actor> learned <new special>'.
I can just copy-paste this part into the other common events for each Special item, as the player will only get one of each Special item so it won't come up with 'You already have Chloroblast, swap this special with Chloroblast?' (even though thats whats happening in the pic below but thats just so i don't have to change too much when i copy-paste the common events)
1590620286990.png

If they choose 'yes' to swap out they recieve the special item that was already 'equipped' back, then it jumps to label: equip to apply the new special.

i mean if you wanted to go the equip an armor and learn a skill approach instead of using an item i'm sure that wouldn't be too hard to figure out [...]
in the end this option would be much easier on you as you would only need to set some notetags inside the notetag field in the database for each of your special armors. let me know and if i have some time i could see about whipping that up.

I'd still be using the Items, the armors are just a way to show the player what Special they have equipped by going into the Equip menu and seeing 'Special: <whatever special>'. It'd be just a visual thing so they don't have to use a Special Item to see what special each actor has.

I don't know how hard the scripting for it would be, I'd just need to equip <correlating special armor number> onto <actor the item was used on>, I'd have the Equip Slot locked anyway so to remove the special/armor you'd either have to use a different Special item or use something like a Special Wrench to remove it.
I don't wanna make you write a whole plugin for this little thing if there's an easier way to do it, I'd just need to know the script to take the actor the item was used on, remove the armor they already have on in that slot, then equip the new armor. If this is possible just with scripts or variables then it'd be better to do that, don't wanna make you do more work than's needed.
Thanks again!
ok this got confusing lol. I THINK this should do whats needed. place this in a second script call below the first one. if this doesn't work then you may need to change the 5's in the script to your proper equipment slot. to find this go to your database -> types -> equipment types. find your special equipment id and subtract 1 from it. if your special armor equipment type shows as 6 in the database use 5 in the code below.

JavaScript:
var target = $gameActors.actor($gameParty._targetActorId);
$gameParty.gainItem($dataItems[$dataArmors[target._equips[5]._itemId].meta.SpecialItem], 1);
target.changeEquip(5, $dataArmors[$dataItems[$gameParty._lastItem._itemId].meta.SpecialArmor]);
$gameParty.gainItem($dataItems[$gameParty._lastItem._itemId], -1);

inside the item in the database add the notetag <SpecialArmor:n>
where n is the id of the armor that item is tied to.
inside the armor in the database add the notetag <SpecialItem:n>
where n is the id of the item that armor is tied to.

don't use any spaces in the notetags. Example: <SpecialArmor:12> or <SpecialItem:169>

assuming i did this correctly this should switch your armor to the new armor and give you back the item tied to the armor you had on before the switch.

essentially what i added here is the target.gainItem line checks the notetag of the armor you currently have equipped and gives you the item back for the armor you are unequipping.
the target.changeEquip line will check the notetag of the last item you just used and change your equipment to equip the armor id of the notetag in that item.

this would assume though that you do already have an armor equipped that has a notetag, so i guess when you get your first special in the game per actor you'd want to forcefully equip it onto the actor. really this probably would be much easier to work with if thrown into a little plugin with some plugin parameter for the special skills and a script call or two lol this got silly though.

this little script would also remove the item you just used automatically so you'd no longer need to manually remove the item in each common event as the script will recognize what item was used and remove it.

to break it down:
line 1 sets a variable to avoid a really long string of code to be used later.
line 2 gives you back the item tied to the armor you currently had equipped before equipment changes.
line 3 changes your equipped armor to the armor which is tied to the item you just used.
line 4 removes the item you just used.
ok this got confusing lol...

That, I agree. This whole using items to equip armors to add skills is a bit confusing, and i reckon it'd be doubly so for the player. Would it actually be better to just use the Armors to equip the skills? It'd just involve the text that pops up, wouldn't need to bother with the swapping out or anything because no items are removed. Could just put the 'Learn Skill' trait on the armor, then some script n variables inside a common event to show the '<orangutan> equipped special!>. I reckon it'd be more straightforward than what we've got now.

I wouldn't want to waste all of this wizardry of scripting work and I can't thank you enough for it. I can't get the above script to work, plus it'd be easier on the player to have it all in one spot.
It could be better, wouldn't know how to activate a common event with it or anything. If you reckon that'd be easier then that might be better.

Edit: this is pretty much exactly what Andar said above. He knew how convoluted this would get!
it does work on my end but i do think it would make a lot more sense to just equip an armor and learn a skill and forget whatever other skill. if you couldn't get that script to work then it may be the wrong slotId in use or the notetags might not be right in the database. each item would need to have a <SpecialArmor:n> notetag and each item would need to have a <SpecialItem:n> notetag where n is the id of the armor/item that item/armor is tied to lol. it was tricky but i was able to pull this off.


Decided to just make a small plugin to handle this using equipment. Probably should have done this from the start because this was much faster lol. I'll attach the plugin here and give a brief walk through on how to use it.

Install the plugin and put your special skills in the plugin parameter. List them using spaces.
Example: 169 170 171 172 173 etc etc

For the Special Equipment Slot Id parameter just set that to exactly what it says in your Database -> Types -> Equipment Types for the Id. So if you put Special Armors as Equipment type 6 then use 6 in that parameter.

go into your armors database and put these notetags inside each special armor.

<SpecialSkill:n>
where n is the id of the skill that armor should equip.

and thats it. let the player equip the armors as they please or handle it yourself, whenever changeEquip is called everything you needed will be handled automatically... on the skills end at least. nothing here on the popping up a message end though. It just reads the notetag on the new armor and gives the new skill while removing any other special skill you may have. same rule applies as before though, this is meant for only 1 special skill equipped at a time and if you have any more than 1 special skill at a time things may happen.

i also added in compatibility with 'Clear Equipment' as well so if the player removes ALL equipment then any special skill would also be removed. If you can think of anything else this needs let me know and i can probably add it quickly... compared to what i was figuring out on the item end this was a piece of cake :mrsatan:

Code below for anyone who wants to see it without needing to download the plugin.
JavaScript:
/*:
*
* @plugindesc Change Special Skills on Equipment Change
*
* @author Ritter
*
* @param Special Skills
* @default 0
* @desc List special skills here with a space between each.
* Example: 1 2 3 101 102 103
*
* @param Special Equipment Slot Id
* @type number
* @desc The ID # of the Special Equipment Type from the database.
* Use the exact number shown under Equipment Type.
*
*/

var Imported = Imported || {};
Imported.EquipmentSkills = true;

var EquipmentSkills = EquipmentSkills || {};
EquipmentSkills.Param = EquipmentSkills.Param || {};


var parameters = PluginManager.parameters('EquipmentSkills');
EquipmentSkills.Param.Specials = String(parameters["Special Skills"]);
EquipmentSkills.Param.Specials = EquipmentSkills.Param.Specials.split(' ');
for (var i = 0; i < EquipmentSkills.Param.Specials.length; i++) {
    EquipmentSkills.Param.Specials[i] = Number(EquipmentSkills.Param.Specials[i]);
}
EquipmentSkills.Param.eSlotId = Number(parameters["Special Equipment Slot Id"]);



var _Game_Actor_changeEquip = Game_Actor.prototype.changeEquip;
Game_Actor.prototype.changeEquip = function(slotId, item) {
    if (item !== null) {
        if (item.etypeId === EquipmentSkills.Param.eSlotId && item.meta.SpecialSkill) {
            var Specials = EquipmentSkills.Param.Specials;
            var skill = [];
            for (var i = 0; i < this._skills.length; i++) {
                for (var j = 0; j < Specials.length; j++) {
                    if (this._skills[i] === Number(Specials[j])) {
                        skill.push(this._skills[i]);
                    }
                }
            }
            if (skill) {
                this.forgetSkill(Number(skill[0]));
            }
            this.learnSkill(Number(item.meta.SpecialSkill));
            this.refresh();
        }
    }
    var realSlotId = slotId + 1;
    if (item === null && this.hasSpecialSkill() > 0 && realSlotId === EquipmentSkills.Param.eSlotId) {
        this.forgetSkill(this.hasSpecialSkill());
    };
    _Game_Actor_changeEquip.call(this,slotId,item);
};

Game_Actor.prototype.hasSpecialSkill = function() {
    var Specials = EquipmentSkills.Param.Specials;
    for (var i = 0; i < this._skills.length; i++) {
        for (var j = 0; j < Specials.length; j++) {
            if (this._skills[i] === Number(Specials[j])) {
                return this._skills[i];
            }
        }
    }
}

var _Game_Actor_clearEquipments = Game_Actor.prototype.clearEquipments
Game_Actor.prototype.clearEquipments = function() {
    var Specials = EquipmentSkills.Param.Specials;
    for (var i = 0; i < this._skills.length; i++) {
        for (var j = 0; j < Specials.length; j++) {
            if (this._skills[i] === Number(Specials[j])) {
                this.forgetSkill(this._skills[i]);
            }
        }
    }
    _Game_Actor_clearEquipments.call(this);
};
Decided to just make a small plugin to handle this using equipment. Probably should have done this from the start because this was much faster lol. I'll attach the plugin here and give a brief walk through on how to use it...
You, my friend, are an amazing person. It works perfectly, thank you infinitely.
I hope other people can get use out of this, thank you so much, I'm definitely putting you in the credits!

Original thread: https://forums.rpgmakerweb.com/threads/unlocking-special-moves-via-an-item-or-armour-common-events-with-variable-names-words.122070/