Need help defining user for custom skill cost script

Status
Not open for further replies.

Howard_Bentley

Villager
Member
Joined
Jul 5, 2019
Messages
14
Reaction score
8
First Language
English
Primarily Uses
RMVXA
So I have a skill called Shield Bash, and the user needs to have a shield equipped to use it. I am currently using Yanfly's Custom Skill Manager cost script, and have the following code in the note tag:

Code:
$game_actors[1].equips[1] && $game_actors[1].equips[1].etype_id >= 1

The code checks to see if actor 1 has a shield, and makes the skill usable. However, I don't need it to check if actor 1 has a shield equipped, I need it to check if the user has a shield equipped.

Thanks in advance!
 

B3N4ZC4L

Regular
Regular
Joined
Aug 15, 2023
Messages
43
Reaction score
26
First Language
German
Primarily Uses
RMMZ
You could add another Skill Category for the Shield specifically, for every Shield you have in your Armor Index, you want to add the Skilltype Shield in there. This way the skills will only appear If any Shield is equipped. Or better yet, Assign Skills onto the Shields themselves and that leaves you the trouble to add another Skill type into your Skill type Index.

The higher level the Shield, the better the Skill.
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,924
Reaction score
977
First Language
English
Primarily Uses
RMXP
I'm not used to Yanfly scripts so there are one default way of doing it in normal RGSS3 and possibly also another one, a copycat of the damage formula's format.

The default way would be using BattleManager.actor and the damage formula way would be using just a. Or it could be user if that's how Yanfly has configured such script.
 

Howard_Bentley

Villager
Member
Joined
Jul 5, 2019
Messages
14
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Code:
<custom cost requirement>
BattleManager.actor.equips[1] && BattleManager.actor.equips[1].etype_id >= 1
 </custom cost requirement>

Unfortunately, I can't seem to get it to work. When scrolling through the menus, it works exactly as intended. Actors with shields can select the skill, and actors without cannot. However, when the skill processing starts, the game gives me the error:
Code:
Script 'Battle Cost Manager' line 577: NoMethodError occured.

Undefined method 'equips' for nil:NilClass

I didn't want to get another script if I didn't have to(I already have a lot), but I'm probably using the wrong plugin for the wrong thing.
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,924
Reaction score
977
First Language
English
Primarily Uses
RMXP
There are 2 reasons reasons for that. That actor can be either an actor, an enemy or simply nil...
 

Howard_Bentley

Villager
Member
Joined
Jul 5, 2019
Messages
14
Reaction score
8
First Language
English
Primarily Uses
RMVXA
@kyonides Thanks for the help! After trying out WAY too many things(that didn't work, of course) I finally arrived at the solution that did work:
Code:
if BattleManager.actor;
then BattleManager.actor && BattleManager.actor.equips[1] && BattleManager.actor.equips[1].etype_id >= 1;
else;
true;
end

Btw, how do I close threads?
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,924
Reaction score
977
First Language
English
Primarily Uses
RMXP
Not so fast, my cyber friend! :o
That might still throw an error, at least potentially...
Just make sure that no enemy could be selected (by the battle system) or else it will fail as well. :eswt:
Right... Hit the report button and tell them this issue of yours has been solved.
EDIT: See answer below
Weird, because no enemy has anything like an equips array but if it doesn't throw an error...
 
Last edited:

Howard_Bentley

Villager
Member
Joined
Jul 5, 2019
Messages
14
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Not so fast, my cyber friend! :o
That might still throw an error, at least potentially...
Just make sure that no enemy could be selected (by the battle system) or else it will fail as well. :eswt:
Right... Hit the report button and tell them this issue of yours has been solved.
You mean like letting the enemy use the skill?
I tested that out as well, and no errors showed up. (I used the actual playtest, and not the troop battle test)
 

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,534
Reaction score
12,008
First Language
Indonesian
Primarily Uses
N/A
If you do us a favor by linking the script, maybe we could provide a more accurate answer.
I didn't use the script, so it isn't in my script list.
 

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,534
Reaction score
12,008
First Language
Indonesian
Primarily Uses
N/A
Judging by how the script checks the condition, it should work even without actor checks. So it goes straight like
Ruby:
equips[1] && equips[1].etype_id >= 1
Have you tried it?
 

Howard_Bentley

Villager
Member
Joined
Jul 5, 2019
Messages
14
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Judging by how the script checks the condition, it should work even without actor checks. So it goes straight like
Ruby:
equips[1] && equips[1].etype_id >= 1
Have you tried it?
I tried it with just that, and it works for the actors, but if an enemy has the skill, the game crashes immediately due to the enemy not being able to equip shields.

EDIT: Due to TheoAllen's knowledge, I was able to condense the check down to:
Ruby:
if BattleManager.actor;
then equips[1] && equips[1].etype_id >= 1;
else;
true;
end
 
Last edited:

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,924
Reaction score
977
First Language
English
Primarily Uses
RMXP
Bad suggestion, Theo.

Ruby:
class Game_BattlerBase
 # Some Code Here
  def custom_cost_met?(skill)
    return true unless skill.use_custom_cost
    return eval(skill.custom_cost_requirement)
  end
end

According to this section, Howard could get in trouble if equips is not defined. The current battler can find it only if it's a Game_Actor but not a Game_Enemy for neither Game_BattlerBase nor Game_Battler nor Game_Enemy have any equips method.

Thus the requirement should include this condition:

Ruby:
BattlerManager.actor.is_a?(Game_Actor)
 

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,534
Reaction score
12,008
First Language
Indonesian
Primarily Uses
N/A
it's not a bad suggestion, my point is you don't need BattleManager.actor nor $game_actors to do that. It adds unnecessary complexity. Besides, you can make a different skill for actors and enemies.

But if you insist on using the same skill, you can use this.
Ruby:
actor? && equips[1] && equips[1].etype_id >= 1
(enemies won't be using the skill)
or
Ruby:
enemy? || (equips[1] && equips[1].etype_id >= 1)
(enemies will be using the skill)
 
Last edited:

Ms Littlefish

Time Traveling Victorian Vampire
Global Mod
Joined
Jan 15, 2014
Messages
9,007
Reaction score
14,555
First Language
English
Primarily Uses
RMMV
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!
 
Status
Not open for further replies.

Latest Posts

Latest Profile Posts

Help, I can't stop! :kaohi:

alice_ornament.png
I'm happy to join this community.
about this argument. I expressed myself badly, I did it on my own, my English was mixed with Google Translate. And I believe chatGPT didn't even exist in 2016
I have to take sleeping pills :rtear:
Now that the forum is running smoothly, I can run around and react to posts the millisecond they're posted.
patrick-star-spongebob.gif

Forum statistics

Threads
136,812
Messages
1,270,316
Members
180,574
Latest member
PastorGary
Top