phiny

Villager
Member
Joined
Feb 21, 2020
Messages
5
Reaction score
2
First Language
Korean
Primarily Uses
RMMV
Hey there!
I wanted to make a skill, which performs another skill based on equipped weapon type.
So I used yanfly's skill core and somehow it's not working.
What I wrote was like this;

<After Eval>
var possibleSkills = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
var equipMainhand = user._equips[0];
var mainhandId = equipMainhand._itemId;
var MainWeaponType = $dataWeapons[mainhandId].wtypeId;
var index = MainWeaponType;
var skillId = possibleSkills[index];
BattleManager.queueForceAction(user, skillId, target);
}
</After Eval>

anyone can help me for this script? thank you
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,667
Reaction score
2,758
First Language
EN
Primarily Uses
RMMZ
Looks mostly OK, but:
  • There's a mismatched } at the end, remove that.
  • If there is no main hand equip, equipMainhand._itemId will cause an error, e.g. "cannot read property _itemId of undefined".
Also, as written it looks like you're getting skill ID 2 when no weapon is equipped. By default that's the skill used when selecting Guard from the Attack, Guard, [Skill Type] list in battle.

Maybe try this instead (untested):

<After Eval> var possibleSkillIds = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]; var equipMainhand = user.equips()[0]; // get $dataWeapon var mainWeaponType = equipMainhand ? equipMainhand.wtypeId : 0; var skillId = possibleSkillIds[mainWeaponType]; BattleManager.queueForceAction(user, skillId, target); </After Eval>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,512
Reaction score
2,877
First Language
English
Primarily Uses
RMMV
Just out of curiosity...why do you declare MainWeaponType, only to declare another variable, index, on the very next line, and you never use MainWeaponType again? Seems like you should just declare that as index in the first place :wink:
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,667
Reaction score
2,758
First Language
EN
Primarily Uses
RMMZ
@ATT_Turan - I assume it's for:
  • Readability - they clearly intended to index the value by main weapon type; and/or
  • Ease of maintenance - e.g. if they later decide to make index and type different values.
(For precompiled code I would expect the compiler to optimise out unnecessary variables. That might not apply to JavaScript depending on how its just-in-time compiler is structured.)
 

phiny

Villager
Member
Joined
Feb 21, 2020
Messages
5
Reaction score
2
First Language
Korean
Primarily Uses
RMMV
Looks mostly OK, but:
  • There's a mismatched } at the end, remove that.
  • If there is no main hand equip, equipMainhand._itemId will cause an error, e.g. "cannot read property _itemId of undefined".
Also, as written it looks like you're getting skill ID 2 when no weapon is equipped. By default that's the skill used when selecting Guard from the Attack, Guard, [Skill Type] list in battle.

Maybe try this instead (untested):

<After Eval> var possibleSkillIds = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]; var equipMainhand = user.equips()[0]; // get $dataWeapon var mainWeaponType = equipMainhand ? equipMainhand.wtypeId : 0; var skillId = possibleSkillIds[mainWeaponType]; BattleManager.queueForceAction(user, skillId, target); </After Eval>


wow, thanks a lot!! it works fine :) Thank for your help and have a good day!!



Just out of curiosity...why do you declare MainWeaponType, only to declare another variable, index, on the very next line, and you never use MainWeaponType again? Seems like you should just declare that as index in the first place :wink:

oh.. since I'm pretty noob to code, I just wrote what I know.. but seems like it was unnecessary o_O
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,512
Reaction score
2,877
First Language
English
Primarily Uses
RMMV
I just wrote what I know.. but seems like it was unnecessary
Technically speaking, since you never modify the values in any of your variables once you declare them, they're all unnecessary. You could put your entire notetag in two lines of code:
Code:
<After Eval>
var possibleSkills = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
BattleManager.queueForceAction(user, possibleSkills[$dataWeapons[user._equips[0]._itemId].wtypeId],  target);
</After Eval>
Now, as caethyril mentioned above about readability, if you're not keeping notes about what things do, it might be a bit difficult to come back to that in a few months and just look at it and know what it's doing. So if you're at all concerned about that, it makes sense to split some of that up into variables, even though you don't need to.

Incidentally, you can add comments by typing // at the beginning of a line. So I might do, before the BattleManager line,
Code:
// Use the listed skill determined by the type of the equipped weapon
and the whole thing still takes up significantly fewer lines (which, to me, is readability in and of itself).

But completely regardless of whether you choose to use some variables or not, it's certainly a bit redundant to make two variables with the same value when you never change either :wink:

Good luck with your game!
 

Latest Threads

Latest Profile Posts

Mixing different pixi filters over a picture. :MV3:

lumina_in_space.jpg

I don't know if my game dev skills are improving... But my waifu making ones sure are. :LZSwink:
Who wants to solve a riddle from my game?
"I prayed for her to lay down her worldly habit and accept the invitation to change her life forever." From lost to found. From past to present, From frown to smile. From the way people treat her as nothing but something to say wow about. From faithless to faithful. From something no one wants to something valuable, someone will respect and love. Thank you, Jesus.
Two new amazing plugins from @NhatNguyen! Footsteps & Stamina. Video on Twitter showcasing:

Forum statistics

Threads
123,095
Messages
1,153,937
Members
161,423
Latest member
Sandrolion
Top