NilClass error when item is depleted with Action Effectiveness (great script btw)

I really like this script because you can't get this feature from anywhere else and I like how it deals with both damage and success (although attribute success isn't as important of a feature as damage rate is to me). I don't know of anything else like it. Because most scripts don't deal with individual actions.

But there are problems when you deplete an item to zero.

You get the error

Script 'Victor Action Effectiveness' line 201: NoMethodError occurred.Undefined method 'get_effectiveness' for nil:NilClassWhich is 

value *= user.get_effectiveness(item, "USE")I'm referring to 

http://victorscripts.wordpress.com/rpg-maker-vx-ace/gameplay-scripts/action-effectiveness/

Spoiler
==============================================================================

# ** Victor Engine - Action Effectiveness
#------------------------------------------------------------------------------
# Author : Victor Sant
#
# Version History:
# v 1.00 - 2012.01.16 > First release
# v 1.01 - 2012.07.12 > Action restrictions moved to another script
# > Compatibility with Element States
# v 1.02 - 2012.07.13 > Compatibility with Action Restriction
# v 1.03 - 2013.01.24 > Fixed issue with skill use and item use rate
# v 1.04 - 2013.02.13 > Compatibility with Toggle Target
#------------------------------------------------------------------------------
# This script allows to set the rate of effectivess of actions based on
# the user or target.
#------------------------------------------------------------------------------
# Compatibility
# Requires the script 'Victor Engine - Basic Module' v 1.35 or higher
#
# * Overwrite methods
# class Game_Battler < Game_BattlerBase
# def item_effect_add_state_attack(user, item, effect)
# def item_effect_add_state_normal(user, item, effect)
# def item_effect_remove_state(user, item, effect)
# def item_effect_add_debuff(user, item, effect)
#
# class Scene_ItemBase < Scene_MenuBase
# def user
#
# * Alias methods
# class Game_Battler < Game_BattlerBase
# def item_value_recover_hp(user, item, effect)
# def item_value_recover_mp(user, item, effect)
# def item_value_gain_tp(user, item, effect)
# def item_hit(user, item)
# def make_damage_value(user, item)
#
#------------------------------------------------------------------------------
# Instructions:
# To instal the script, open you script editor and paste this script on
# a new section bellow the Materials section. This script must also
# be bellow the script 'Victor Engine - Basic'
#
#------------------------------------------------------------------------------
# Actors, Classes, Enemies, States, Weapons and Armors note tags:
# Tags to be used on the Actors, Classes, Enemies, States, Weapons and Armors
# note box in the database
#
# <skill use effectiveness x: y%> <item use effectiveness x: y%>
# The actions will have it's effectiveness (damage or sucess chance) changed
# by y% when used by a battler with this attribute
# x = item or skill ID
# y = effectiveness rate
#
# <skill effect effectiveness x: y%> <item effect effectiveness x: y%>
# The actions will have it's effectiveness (damage or sucess chance) changed
# by y% when targeting a battler with this attribute
# x = item or skill ID
# y = effectiveness rate
#
#==============================================================================

#==============================================================================
# ** Victor Engine
#------------------------------------------------------------------------------
# Setting module for the Victor Engine
#==============================================================================

module Victor_Engine
#--------------------------------------------------------------------------
# * required
# This method checks for the existance of the basic module and other
# VE scripts required for this script to work, don't edit this
#--------------------------------------------------------------------------
def self.required(name, req, version, type = nil)
if !$imported[:ve_basic_module]
msg = "The script '%s' requires the script\n"
msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
msg += "Go to http://victorscripts.wordpress.com/ to download this script."
msgbox(sprintf(msg, self.script_name(name), version))
exit
else
self.required_script(name, req, version, type)
end
end
#--------------------------------------------------------------------------
# * script_name
# Get the script name base on the imported value, don't edit this
#--------------------------------------------------------------------------
def self.script_name(name, ext = "VE")
name = name.to_s.gsub("_", " ").upcase.split
name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
name.join(" ")
end
end

$imported ||= {}
$imported[:ve_action_effectiveness] = 1.04
Victor_Engine.required🙂ve_action_effectiveness, :ve_basic_module, 1.35, :above)
Victor_Engine.required🙂ve_action_effectiveness, :ve_element_states, 1.00, :bellow)
Victor_Engine.required🙂ve_action_effectiveness, :ve_action_restriction, 1.00, :bellow)

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# This class deals with battlers. It's used as a superclass of the Game_Actor
# and Game_Enemy classes.
#==============================================================================

class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * Overwrite method: item_effect_recover_hp
#--------------------------------------------------------------------------
alias :item_value_recover_hp_ve_action_effectiveness :item_value_recover_hp
def item_value_recover_hp(user, item, effect)
value = item_value_recover_hp_ve_action_effectiveness(user, item, effect)
value * effectiveness(user, item)
end
#--------------------------------------------------------------------------
# * Overwrite method: item_effect_recover_mp
#--------------------------------------------------------------------------
alias :item_value_recover_mp_ve_action_effectiveness :item_value_recover_mp
def item_value_recover_mp(user, item, effect)
value = item_value_recover_mp_ve_action_effectiveness(user, item, effect)
value * effectiveness(user, item)
end
#--------------------------------------------------------------------------
# * Overwrite method: item_effect_recover_yp
#--------------------------------------------------------------------------
alias :item_value_recover_tp_ve_action_effectiveness :item_value_recover_tp
def item_value_recover_tp(user, item, effect)
value = item_value_recover_tp_ve_action_effectiveness(user, item, effect)
value * effectiveness(user, item)
end
#--------------------------------------------------------------------------
# * Overwrite method: item_effect_add_state_normal
#--------------------------------------------------------------------------
def item_effect_add_state_normal(user, item, effect)
chance = effect.value1
chance *= effectiveness(user, item)
chance *= state_rate(effect.data_id) if opposite?(user)
chance *= luk_effect_rate(user) if opposite?(user)
if rand < chance
add_state(effect.data_id)
@result.success = true
end
end
#--------------------------------------------------------------------------
# * Overwrite method: item_effect_remove_state
#--------------------------------------------------------------------------
def item_effect_remove_state(user, item, effect)
chance = effect.value1
chance *= effectiveness(user, item)
if rand < chance
remove_state(effect.data_id)
@result.success = true
end
end
#--------------------------------------------------------------------------
# * Overwrite method: item_effect_add_debuff
#--------------------------------------------------------------------------
def item_effect_add_debuff(user, item, effect)
chance = debuff_rate(effect.data_id) * luk_effect_rate(user)
chance *= effectiveness(user, item)
if rand < chance
add_debuff(effect.data_id, effect.value1)
@result.success = true
end
end
#--------------------------------------------------------------------------
# * Alias method: item_hit
#--------------------------------------------------------------------------
alias :item_hit_ve_action_effectiveness :item_hit
def item_hit(user, item)
rate = item_hit_ve_action_effectiveness(user, item)
rate *= effectiveness(user, item)
rate
end
#--------------------------------------------------------------------------
# * Alias method: make_damage_value
#--------------------------------------------------------------------------
alias :make_damage_value_ve_action_effectiveness :make_damage_value
def make_damage_value(user, item)
@effectivess_rate = effectiveness(user, item)
make_damage_value_ve_action_effectiveness(user, item)
end
#--------------------------------------------------------------------------
# * Alias method: apply_guard
#--------------------------------------------------------------------------
alias :apply_guard_all_ve_action_effectiveness :apply_guard
def apply_guard(damage)
damage = apply_guard_all_ve_action_effectiveness(damage)
damage *= @effectivess_rate
damage
end
#--------------------------------------------------------------------------
# * New method: effectiveness
#--------------------------------------------------------------------------
def effectiveness(user, item)
value = 1.0
value *= user.get_effectivenes(item, "USE")
value *= self.get_effectivenes(item, "EFFECT")
value
end
#--------------------------------------------------------------------------
# * New method: get_effectivenes
#--------------------------------------------------------------------------
def get_effectivenes(item, type)
action = item.skill? ? "SKILL" : "ITEM"
regexp = /<#{action} #{type} EFFECTIVENESS #{item.id}: *(\d+)%?>/i
get_all_notes.scan(regexp).inject(1.0) {|r, i| r *= i.first.to_f / 100.0 }
end
end

#==============================================================================
# ** Scene_ItemBase
#------------------------------------------------------------------------------
# This is the superclass for the classes that performs the item and skill
# screens.
#==============================================================================

class Scene_ItemBase < Scene_MenuBase
#--------------------------------------------------------------------------
# * Overwrite method: user
#--------------------------------------------------------------------------
def user
users = $game_party.movable_members.select {|member| member.usable?(item)}
users.max_by {|member| item_modifier(member, item) }
end
#--------------------------------------------------------------------------
# * New method: item_modifier
#--------------------------------------------------------------------------
def item_modifier(member, item)
value = member.pha
value *= member.effectiveness(member, item)
value
end

end
May I please ask for help? 
I removed the script from your post - a link is sufficient, and the spoiler tag didn't work because you'd added color tags to one of the spoiler tags


Where does "depleting the item to 0" come into it? Sounds like you're using another script to do that, which says to me that it could be a compatibility issue. If you start a new project and ONLY add this script, does the problem still happen?


The error does not refer to an item being depleted to 0. It refers to there being no user (user is nil, thus no such method). If you have another script that handles depleting items, try putting this one below that one and see if it still happens.
People can't always easily access his scripts for some reason, may be mobile, idk. That's why I put up the spoiler.

And no, it's this script alone.

I tested.

I think it has to do with the item success rate aspect of the script. 
If I knew how, I would remove all parts besides the aspect of increasing or receiving damage from a given skill from a notetag, if need be. Although the other aspects are good, too. Chest armor decreasing damage and ailments from high attacks is a nice concept. 
I still don't see any reference to reducing anything to 0.


If you insist on putting scripts in your post, at least wrap them in code tags so they're easier to read.


Victor uses AdF.ly - maybe people having troubles accessing them are because they have something installed to block this?
Chest armor decreasing damage and ailments from high attacks is a nice concept.


--> You can probably utilize elements for the high attacks I think, or if you know a bit of scripting you can even use the damage formula alone for that


Also when exactly does the problem happens? You'd probably also want to show the notetags that you use


@Shaz - to me the problem lies when it comes to his dropbox links... 🙂
No notetags were used. I remembered this script had problems with using items down to zero, and went to a fresh project to test then gave the party 3 Life Ups and when the 3rd one was used up, it would give me that listed error.

Yes, I can use elements.

But there is no way to change the ailment rate of a skill based on element resistance.

That, and when combining different ailments, even using scripts, it doesn't work how I want it.

I don't want Low Slash to have the element of Low and Slash.

I want to just have it so that steel boots reduces the damage taken from low slash, and Crouch adds a chance to dodge high attacks.

But what about me wanting armor to reduce the damage from a spell meant to affect the whole body? I add the attribute "Whole" to a skill then have each armor piece reduce damage from the "Whole" element slightly? (you can say that in that case, I could just have armor raise Def and Mdf, but a helmet wouldn't be adding to your magical defense against a low attack.

There are times where it gets complicated and I want to be very specific.

Oh, right, there was another reason I use Action Effectiveness. I have it so that certain skill ignore certain kinds of guard.

So say that Fire III ignores and removes Guard, and removes-but-doesn't-ignore-Magic-Guard.

The notetag on the Guard state would be

<skill effect effectiveness (id for Fire III skill): 200%>basically having it so that Guard doesn't halve the damage of Fire III (and I think that would also make it so that it doesn't reduce the ailment rate, too).

That spoiler is still up btw if need be.
You could just put a

return 1.0 if user.nil?as the first line of that method. I'm not sure if it'd give you the result you're after though. Maybe a 0 return value might be more appropriate.
I don't understand why it's a nil USER that's causing the trouble, and not a nil ITEM. Maybe once the item has been used, user is reset?
Thanks, that solves that part  🙂

Oh right, I forgot, when I'd 

"#" out to remove that line, value *= user.get_effectiveness(item, "USE"), (or just use the fix you gave me to fix that problem), the other problem I got was 

line 707 of Game_Battler

Game_Battler < Game_BattlerBase def item_user_effect(user, item) user.tp += item.tp_gain * user.tcr endwhere the error would be

Script 'Game_Battler' line 707: NoMethodError occurredundefined method 'tp' for nil:NilClass and I know it doesn't have to do with 

#-------------------------------------------------------------------------- # * Overwrite method: item_effect_recover_tp #-------------------------------------------------------------------------- alias :item_value_recover_tp_ve_action_effectiveness :item_value_recover_tp def item_value_recover_tp(user, item, effect) value = item_value_recover_tp_ve_action_effectiveness(user, item, effect) value * effectiveness(user, item) end (the only part of Action Effectiveness that deals with TP) because when I'd remove that part, I'd still get that error.

This error occurs when an item is used up, and does not occur when Action Effectiveness is removed.

When I would get rid of that line, 707,

user.tp += item.tp_gain * user.tcrI would no longer receive that error and could deplete items as I please.

The script doesn't overwrite item_user_effect(user, item)

# Compatibility

#   Requires the script 'Victor Engine - Basic Module' v 1.35 or higher

#

# * Overwrite methods

#   class Game_Battler < Game_BattlerBase

#     def item_effect_add_state_attack(user, item, effect)

#     def item_effect_add_state_normal(user, item, effect)

#     def item_effect_remove_state(user, item, effect)

#     def item_effect_add_debuff(user, item, effect)

#

#   class Scene_ItemBase < Scene_MenuBase

#     def user

#

# * Alias methods

#   class Game_Battler < Game_BattlerBase

#     def item_value_recover_hp(user, item, effect)

#     def item_value_recover_mp(user, item, effect)

#     def item_value_gain_tp(user, item, effect)

#     def item_hit(user, item)

#     def make_damage_value(user, item)
So I wouldn't know.

Edit-

Apparently it has to do with

class Scene_ItemBase < Scene_MenuBase #-------------------------------------------------------------------------- # * Overwrite method: user #-------------------------------------------------------------------------- def user users = $game_party.movable_members.select {|member| member.usable?(item)} users.max_by {|member| item_modifier(member, item) } endWould you know what's up with that?
Oh now it's clear... since item is probably not usable when it's already 0, user now returns nil...


you can try finding the original user method and put it in an extra script below that one and see if it still works fine
Put in an extra script?

There's the original

def user $game_party.movable_members.max_by {|member| member.pha } endand

def user users = $game_party.movable_members.select {|member| member.usable?(item)} users.max_by {|member| item_modifier(member, item) } endand looks like Victor's doesn't use pharmacology
you can comment out Victor's user method or add the original method on another script line after Victor's script

Original thread: https://forums.rpgmakerweb.com/threads/nilclass-error-when-item-is-depleted-with-action-effectiveness-great-script-btw.26095/