Need help with a script - Seal by Weapon/Armor Type

Hey guys, I could really use some help with this script as I really want to implement it to my project. Unfortunately I don't have any scripting experience and am having issues getting this script working on a blank project. The error is "line 131 nomethoderror occurred. undefined method scan for nil nil class." This happens as soon as I load the game after tagging an armor with <seal atype: 7>. As soon as I delete the tag, the blank project works fine.

Here's the script I found that I would like to use.

#===============================================================================
#
# Seal by Weapon/Armor Type v1.0
# by Shad3Light
#
# 2014/03/06
# URL: http://shad3light.blogspot.com/2014/03/seal-by-eq-type.html
#===============================================================================

=begin
================================================================================
Description

By default, VX Ace does not offer equipment restriction by weapon or armor
types, only equipment slots can be sealed. This script tries to rectify that
so we can prohibit equipping a specific weapon/armor types.
--------------------------------------------------------------------------------
History

v1.0 - Initial Release (2014/03/06)

--------------------------------------------------------------------------------
Terms of Use

- You are free to use this script for non-commercial projects.
- For commercial projects, at least contact me first.
- This script is provided as-is. Don't expect me to give support.
- Reported bug will be fixed, but no guarantee on requested features.
- No guarantee either for compatibility fixes.
- Give credit to Shad3Light (me), and do not delete this header.
--------------------------------------------------------------------------------
Installation

Put this script below Бе Materials and above Бе Main Process.
If there are scripts that overwrite the aliased methods below,
put this script below said script.
--------------------------------------------------------------------------------
Usage

To make an actor, class, enemy (even though it does not make sense),
equipment, or state to seal a specific weapon or armor types, use
these notetag:
<seal wtype: x>
<seal atype: x>
This will make the weapon/armor with specified types cannot be equipped.

You can also specify more than one types in the notetag:
<seal wtype: x, y, z>
<seal atype: x, y, z>

Example:
<seal wtype: 1>
This will make Axe-type weapons unequippable for the battler.
================================================================================
=end

if $imported && $imported[:SHD_SealByWAType]
msgbox "Warning: Seal by Weapon/Armor Type script is imported twice."
else

$imported = {} if $imported.nil?
$imported[:SHD_SealByWAType] = true

module SHD
#===============================================================================
# Configuration Module
#
# None
#
# Configuration Module End
#===============================================================================

#===============================================================================
# Code Start
# Configuration ends here. Edit what's below at your own risk.
#-------------------------------------------------------------------------------
# Aliased methods:
# DataManager
# self.load_database
# Game_BattlerBase
# equippable?
#
# New methods:
# DataManager
# self.load_notetags_shd_eqt_rest
# RPG::BaseItem
# load_notetags_shd_eqt_rest
# wtype_seal
# atype_seal
# Game_BattlerBase
# wtype_sealed?
# atype_sealed?
#===============================================================================

module REGEXP
RESTRICT_WTYPE = /<seal wtype:[ ]*(?:\d+(\s*,\s*\d+)*)>/i
RESTRICT_ATYPE = /<seal atype:[ ]*(?:\d+(\s*,\s*\d+)*)>/i
end

end

module DataManager

class <<self; alias :load_database_shd_eqt_rest :load_database; end
def self.load_database
load_database_shd_eqt_rest
load_notetags_shd_eqt_rest
end

def self.load_notetags_shd_eqt_rest
for i in $data_actors+$data_classes+$data_enemies+$data_weapons+$data_armors+$data_states
next if i.nil?
i.load_notetags_shd_eqt_rest
end
end

end

class RPG::BaseItem

def load_notetags_shd_eqt_rest
@wtype_seal = []
@atype_seal = []
self.note.split(/\r\n/).each do |line|
case line
when SHD::REGEXP::RESTRICT_WTYPE
$1.scan(/\d+/).each { |n| @wtype_seal << n.to_i }
when SHD::REGEXP::RESTRICT_ATYPE
$1.scan(/\d+/).each { |n| @atype_seal << n.to_i }
end
end
end

def wtype_seal(id)
return @wtype_seal.include?(id)
end

def atype_seal(id)
return @atype_seal.include?(id)
end

end

class Game_BattlerBase

def wtype_sealed?(wtype_id)
feature_objects.each { |o| return true if o.wtype_seal(wtype_id) }
return false
end

def atype_sealed?(atype_id)
feature_objects.each { |o| return true if o.atype_seal(atype_id) }
return false
end

alias :shd_eqt_rest_equippable? :equippable?
def equippable?(item)
return false unless shd_eqt_rest_equippable?(item)
return false if item.is_a?(RPG::Weapon) && wtype_sealed?(item.wtype_id)
return false if item.is_a?(RPG::Armor) && atype_sealed?(item.atype_id)
return true
end

end

end #if $imported

I've moved this thread to Script Support. Thank you.

Welcome!

What is your Rpg Maker?
I'm using VX Ace 🙂
Could you please remove the script from your post and add a link to where you originally found it instead? A thread would be better than a link to pastebin, dropbox, git, etc, as we can see the author's comments and see if anyone else reported the issue.

Then show us which line is 131, and add a screenshot of the Armor tab with your note tag entered as required.

It seems to be looking for the string on a null line, which is a bit weird. What other scripts do you have?

When you say "as soon as I load the game" do you mean hitting test play, or actually loading a saved game to continue playing?
Hey Shaz,

I really appreciate you trying to help!

Here's the link to the script:

Here's the link to the site I got it from:

It errors out on this line when I add <seal atype: 6> to one of the default armors.
$1.scan(/\d+/).each { |n| @atype_seal << n.to_i }

It errors out on this line when I add <seal wtype: 6> to one of the default weapons.
$1.scan(/\d+/).each { |n| @wtype_seal << n.to_i }

I'm trying to get this to work on a blank/new project, so no other script is being used.
Thanks for the links.

It's very weird - it is matching the regular expression but not returning $1 as a result, yet I have done almost exactly the same thing in a VX script recently, and it works fine (I put the regexp on the when line rather than referring back to the module constant.

Try changing $1 to line on each of those lines. I'm sure it's meant to work without doing that, and based on nobody else reporting issues, it probably does. Not sure why you're getting a different result (I also got the same error when I used the script as-is).

But this works for me:

Code:
    self.note.split(/\r\n/).each do |line|
      case line
      when SHD::REGEXP::RESTRICT_WTYPE
        line.scan(/\d+/).each { |n| @wtype_seal << n.to_i }
      when SHD::REGEXP::RESTRICT_ATYPE
        line.scan(/\d+/).each { |n| @atype_seal << n.to_i }
      end
    end

I only tested with a single weapon/armor type per line.
Thanks Shaz, you're awesome! That seems to have fixed it.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-script-seal-by-weapon-armor-type.135874/