Need help defining user for custom skill cost script

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!
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.
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.
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.
There are 2 reasons reasons for that. That actor can be either an actor, an enemy or simply nil...
@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?
Not so fast, my cyber friend! 😮
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...
Not so fast, my cyber friend! 😮
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)
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 I probably should have done that first. Here's the script.

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?
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
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)
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)
Both of the solutions work, although I'll probably use TheoAllen's due to its simplicity. Again, thanks for your help, @TheoAllen and @kyonides .
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/need-help-defining-user-for-custom-skill-cost-script.161565/