Yanfly Skill Core | Adding Variable on Skill Use Depending on Weapon

So I hope you guys can help figure this out with me. My plan is to add 1 to a variable every time a skill ("Attack") is used, depending on their weapon. If they have "this weapon," then "add 1" to "variable ID 1." If they have "this other weapon," then "add 1" to "variable ID 2." And so on. There are 4 weapons.


I tried using a simple common event that was called on every time they used "Attack." This didn't do anything.


rpgmaker-variables1.PNG


So then I thought I'd use Yanfly's Lunatic mode. This is the script I came up with for the Attack notetag:


<Custom Execution>
if ($gameActors.actor(1).equips().contains($dataWeapons[1])
{
$gameVariables.setValue(1, $gameVariables.value(1) + 1);
}
else {
}
</Custom Execution>


This is giving me an error. SyntaxError: Unexpected token { {stack: (...), message: "Unexpected token {"}


Any ideas? 
I didn't try it in game, but by quickly looking at it, you're missing a ")"


<Custom Execution>
if ($gameActors.actor(1).equips().contains($dataWeapons[1]) ) //you didn't close the if () there
{
$gameVariables.setValue(1, $gameVariables.value(1) + 1);
}
else {
}
</Custom Execution>


I don't see anything else, so try it like this and tell me how it goes.
I didn't try it in game, but by quickly looking at it, you're missing a ")"



<Custom Execution>
if ($gameActors.actor(1).equips().contains($dataWeapons[1]) ) //you didn't close the if () there
{
$gameVariables.setValue(1, $gameVariables.value(1) + 1);
}
else {
}
</Custom Execution>


I don't see anything else, so try it like this and tell me how it goes.

Haha awesome, thank you. I asked my javascript-knowing buddy if he saw anything wrong with it, and he didn't (pfff). So I thought it was something else.


So this isn't giving me any errors anymore *cheer!* But the variable is not going up whenever I finish a battle. Checking it, it still stays at 0, even after attacking 3 or 4 times. Weapon 1 is equipped, and it is Actor 1. Trying to figure out how to make this work... *chinstroke*


Edit: It works when I don't have "if [this weapon] equipped." If it's simply [add variable] on attack, it's okay. So I've gotta figure out how to make it add only if a certain weapon is on.
Well this will increase the value each time the skill is used if actors 1's weapon is n*1.


If Actor 2 uses attack and actor 1 has that weapon it will increase it too.


Also, no need to make a else statement if you don't use it.


Here is the notetag I use that works in my project (Core engine, battle engine and skill core installed):


<Custom Execution>
if (user.equips().contains($dataWeapons[1])) {
$gameVariables.setValue(7,$gameVariables.value(7)+1)
}
</Custom Execution>


Try it and if it still doesn't work if actor 1 indeed does have weapon 1 equipped, my guess would be that you have a plugin that modifies how equipment is handled.
Well this will increase the value each time the skill is used if actors 1's weapon is n*1.


If Actor 2 uses attack and actor 1 has that weapon it will increase it too.


Also, no need to make a else statement if you don't use it.


Here is the notetag I use that works in my project (Core engine, battle engine and skill core installed):



<Custom Execution>
if (user.equips().contains($dataWeapons[1])) {
$gameVariables.setValue(7,$gameVariables.value(7)+1)
}
</Custom Execution>


Try it and if it still doesn't work if actor 1 indeed does have weapon 1 equipped, my guess would be that you have a plugin that modifies how equipment is handled.

Luckily, only one actor in this game.


Just found out after quite a bit of trial and error that it's a plugin. Specifically Dreamx's Random Pre/Suffixes. I assumed the plugin used the base ID for the weapon, but I must be wrong. So I guess the game isn't seeing that the actor has indeed equipped Weapon 1. It sees something determined by the plugin.


Can I ask how to fix that here? Or should I go ahead and post to their page?
I don't use Dreamx's plugin so I wouldn't know. Ask here if you want, but I think you're more likely to get an answer if you ask the plugin creator himself.


I could think of another solution: if there are only 4 weapons in the game, make them have a different type, and just check for that type.


You can get a weapon type by using equips[0].wtypeId for example.
I don't use Dreamx's plugin so I wouldn't know. Ask here if you want, but I think you're more likely to get an answer if you ask the plugin creator himself.


I could think of another solution: if there are only 4 weapons in the game, make them have a different type, and just check for that type.


You can get a weapon type by using equips[0].wtypeId for example.

That's brilliant, I'll give it a try! 


Edit: Praise the Light! It works beautiful! I love you @Astfgl66. Let's get married.


This is the code I used:


<Custom Execution>
if ($gameActors.actor(1).isWtypeEquipped(1)) {
$gameVariables.setValue(1,$gameVariables.value(1)+1)
}
</Custom Execution>
<Custom Execution>
if ($gameActors.actor(1).isWtypeEquipped(2)) {
$gameVariables.setValue(2,$gameVariables.value(2)+1)
}
</Custom Execution>
<Custom Execution>
if ($gameActors.actor(1).isWtypeEquipped(3)) {
$gameVariables.setValue(3,$gameVariables.value(3)+1)
}
</Custom Execution>
<Custom Execution>
if ($gameActors.actor(1).isWtypeEquipped(4)) {
$gameVariables.setValue(4,$gameVariables.value(4)+1)
}
</Custom Execution>


And it works for all 4 weapons.


There was probably a more efficient and pretty way to get all that in, but hey. It works. I'm not complaining.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-skill-core-adding-variable-on-skill-use-depending-on-weapon.71176/