Szyu's Item's Class Restriction crash every time a certain skill is used (not item)

Code:
Items Class Restriction:113:in `current_item_enabled?': undefined method `include?' for nil:NilClass, NoMethodError
    from Window_Selectable:318:in `process_ok'
    from Window_Selectable:297:in `process_handling'
    from Window_Selectable:276:in `update'
    from Scene_Base:95:in `block in update_all_windows'
    from Scene_Base:93:in `each'
    from Scene_Base:93:in `update_all_windows'
    from Scene_Base:49:in `update_basic'
    from Screenshot Take:155:in `update_basic'
    from Scene_Battle:56:in `update_basic'
    from Scene_Base:41:in `update'
    from Scene_Battle:45:in `update'
    from Scene_Base:14:in `main'
    from SceneManager:22:in `run'
    from Mapshot:986:in `run'
    from Screenshot Take:167:in `run'
    from Backtrace:10:in `block in <main>'

Every time I try to have Beautiful Dragon use Dragon's Purge to cure a status effect, my game always crashes pointing to Szyu's Item's Class Restriction scrip

The skill itself has no restrictions whatsoever and Beautiful Dragon has been able to use Dragon's Purge many times prior to installing the skill restriction script.

Here is the skill in question:
1700751760562.png


The skill itself seems completely unassuming and Beautiful Dragon can use the Magic skill type.

Does anybody know what the problem could be?
the first question is are you playing from a saved game?
Did you text with a new game?
For something like this it should not matter. It is an Undefined method error, which is almost always a problem with the code itself.

I just tested the skill with a Battle Test on various enemies after saving and the game crashes with the same error every time. Since this is just a battle test in the troop menu, it should act like a new game and yet it still crashes.

I have a dedicated actor for testing certain moves in the battle test that is not in the main game and it crashes for him.


Edit: Crashes with a brand new game too. I did a quick swap of actors at the start of the game and it still crashes when I use Dragon's Purge.
which is almost always a problem with the code itself.
That is absolutely wrong.
In fact, this type of error almost always happens because data was deleted and has absolutely nothing to do with the code itself.

Please read the error message completely and carefully before assuming nonsense.

The method is undefined because it comes from a NIL object.
A NIL Object means that the reference given to a data object does not exist.

Scripts create their data on NewGame and save it into savefiles AFTER that.

If you add a script and then try to continue an older save that is missing the data that should have been added by the new game part of the new script, then the error you got is typical and normal for those cases.


ADDING A SCRIPT REQUIRES NEW GAME in most cases (whenever a script needs a setuip and stores data), and all older saves are incompatible if that is the case.

Since this is just a battle test in the troop menu, it should act like a new game
Unfortunately no - Battletest is in fact worse than savefiles because it intentionally skips the new game setup to speed directly to the battle
Please reread my reply. It crashes with a new game as well. I started a new game and used the skill in the first encounter. It crashes still. I tried it two more times, still crash. even with new game.
With your edit, please check the skill effects.

the error still means that it was given a wrong reference to an data object that does not exist.

This means either a data problem on the actor or on the item/skil (and for your info, internally all skills are handled as items in the code).

On the skill itself the only way this happens is if you have an effect like a remove state on a state that had been deleted - so look especially for empty effect lines and if there is more than one such line at the bottom.

On the actors themselves (user and target) - I don't know where it could be, but those are the only other data objects directly involved.

There is a very small chance that it could be a misconfiguration of the script itself, but I can't check that because you didn't give a link to the script
The script is here: https://forums.rpgmakerweb.com/index.php?threads/items-class-restriction.31546/
When checking the specified error line it becomes obvious that the list to forbid classes does not exists or is broken.

Since that list should be created on new game, it means that either another script broke this one or somehow the setup was still skipped.
There is also a small chance that you simply have a typo in class notetags resulting in that list not being correctly formed.
It has likely nothing to do with that specific skill/item, it is only accidental that that causes the error to happen
I only have an item with notetags for this script and it forbids the use of the item on anybody who cannot learn the "Skill" skill type. I tested it and verified that the item cannot be used on actors without the "Skill" skill type. Also, that item has already been used on Justin and it taught him Suburstable Impact which works flawlessly and the Dragon's Purge is not being used on Justin.

I only need this script for items.

There are no missing or broken classes in my game. All exist and work flawlessly.
Then it's an interaction with another script.

The computer doesn't lie - there is always a cause for all errors, it just can be hidden deeply.
The worst case I ever found and confirmed was a when a wrong mouse driver under windows caused a display pixel line under DOS. And that is no joke, somehow the driver messed up the adressing for those pixels.

The forbid list is not defined in your specific case. I provided all possible ideas why it might not be defined, but I can't help further if that is not enough to find the cause.
Did you added $data_skills to the group?
groups = [$data_items, $data_weapons, $data_armors]

It's possible that another script is causing an issue because it is using some of the same code or modified the item restrictions data. Is current_item_enabled? located in any custom scripts?

Above line 111 we can add in a few print lines to get data to display and see what object is is calling as nil.
Ruby:
class Window_BattleActor < Window_BattleStatus
  #--------------------------------------------------------------------------
  # * Get Activation State of Selection Item
  #--------------------------------------------------------------------------
  def current_item_enabled?
  p('actor')
  p(BattleManager.actor)
  p('input')
  p(BattleManager.actor.input)
  p('item')
  p(BattleManager.actor.input.item)
    return false if !BattleManager.actor.input.item.is_a?(RPG::UsableItem) ||
      BattleManager.actor.input.item.forbid_classes.include?(BattleManager.actor.input.subject.class_id) ||
      BattleManager.actor.input.item.forbid_actors.include?(BattleManager.actor.input.subject.id)
    return true
  end
end
You need the console window open to see this.
current_item_enabled is only in default scripts and the script in question.

1700763248262.png
Code:
Items Class Restriction:71:in `item_test': undefined method `class_id' for #<Game_Enemy:0x13b65310>, NoMethodError
    from Game_Battler:501:in `item_apply'
    from Yanfly cooldown:796:in `item_apply'
    from Scene_Battle:605:in `apply_item_effects'
    from Scene_Battle:597:in `invoke_item'
    from Yanfly Target Manager:430:in `invoke_item'
    from Scene_Battle:586:in `block (2 levels) in use_item'
    from Scene_Battle:586:in `times'
    from Scene_Battle:586:in `block in use_item'
    from Scene_Battle:586:in `each'
    from Scene_Battle:586:in `use_item'
    from Scene_Battle:573:in `execute_action'
    from Scene_Battle:550:in `process_action'
    from Scene_Battle:48:in `update'
    from Scene_Base:14:in `main'
    from SceneManager:22:in `run'
    from Mapshot:986:in `run'
    from Screenshot Take:167:in `run'
    from Backtrace:10:in `block in <main>'


I just had the same crash when using a slot machine item that deals a random amount of damage to an enemy based on a formula.

This item has no restrictions, there are no restrictions on who can use it but I get this crash.

I found two common denominators for both the skill crash and the item crash. Both happen during battle and both the skill and item are set to be used "Only in battle." under "Occasion"

I am guessing that there is a conflict somewhere with the script and the default "Only in battle" occasion flag. Both crashes have that in common.

I was able to comment out the areas in the script that cause the crash as a workaround, and both areas relate to battle and it does not seem to affect restrictions on item use (at least through the menu where I intend it to be).

I do now know if the battle section of the script needs to be rewritten or what, but it is during battle when the crash occurs and it is only with things defined to be used only in battle.
Did you added $data_skills to the group?
groups = [$data_items, $data_weapons, $data_armors]

It's possible that another script is causing an issue because it is using some of the same code or modified the item restrictions data. Is current_item_enabled? located in any custom scripts?

Above line 111 we can add in a few print lines to get data to display and see what object is is calling as nil.
Ruby:
class Window_BattleActor < Window_BattleStatus
  #--------------------------------------------------------------------------
  # * Get Activation State of Selection Item
  #--------------------------------------------------------------------------
  def current_item_enabled?
  p('actor')
  p(BattleManager.actor)
  p('input')
  p(BattleManager.actor.input)
  p('item')
  p(BattleManager.actor.input.item)
    return false if !BattleManager.actor.input.item.is_a?(RPG::UsableItem) ||
      BattleManager.actor.input.item.forbid_classes.include?(BattleManager.actor.input.subject.class_id) ||
      BattleManager.actor.input.item.forbid_actors.include?(BattleManager.actor.input.subject.id)
    return true
  end
end
You need the console window open to see this.
This is almost guaranteed to be the cause. $data_skills not being in groups means that forbid_classes and forbid_actors never get initialised for skills, and that means that when it checks that property on a skill, it doesn't exist to call include? on.
Where do I add that? I did not know that there is some kind of "group". Where can I find this group so I can add it?
Where do I add that? I did not know that there is some kind of "group". Where can I find this group so I can add it?
Line 92 in the script.
I just had the same crash when using a slot machine item that deals a random amount of damage to an enemy based on a formula.
Well not technically true.
The first was
Items Class Restriction:113:in `current_item_enabled?': undefined method `include?
and now you have
Items Class Restriction:71:in `item_test': undefined method `class_id'

So a question comes to mind.
What version of the script are you using?
In the page you linked to where you got the script I made a post with changes to fix issues people were having.
Perhaps you can try that.
Well not technically true.
The first was

and now you have


So a question comes to mind.
What version of the script are you using?
In the page you linked to where you got the script I made a post with changes to fix issues people were having.
Perhaps you can try that.
I was going to ask this as well.
Well not technically true.
The first was

and now you have


So a question comes to mind.
What version of the script are you using?
In the page you linked to where you got the script I made a post with changes to fix issues people were having.
Perhaps you can try that.

Yours is definitely different than the one I have. The groups being on line 92 of mine and 100 on yours.
Yours is definitely different than the one I have. The groups being on line 92 of mine and 100 on yours.
The line numbers don't always mean it's different. Sometimes it can be different because people add extra blank lines or remove some.
But I had put several adjustments in that thread, so try them out.

Original thread: https://forums.rpgmakerweb.com/threads/szyus-items-class-restriction-crash-every-time-a-certain-skill-is-used-not-item.163193/