[Ace] Change VARIABLE on equipment?

Anyone know made script like this??
---> https://forums.rpgmakerweb.com/index.php?threads/equipment-variables.73457/#post-700634
But it's for MV , I'm looking for Ace version !help
Tsukihime has a script that executes a common event on equip/unequip, that can be used to do anything in the common event
Tsukihime has a script that executes a common event on equip/unequip, that can be used to do anything in the common event

I'm using it. But when it run the common event it will exit from menu. That's the problem.
I could probably port LB's plugin to VX Ace but I can't access Google Drive at work so I can't get the .js file right now.
I could probably port LB's plugin to VX Ace but I can't access Google Drive at work so I can't get the .js file right now.

How about Onedrive?
https://1drv.ms/u/s!AhAbnGSwIy24c1w6Sl5zINI3WZs
Nope, the work network basically shuts down any mass storage websites.
Never mind, I can wait until you get off work. 😀

Ps. How about the raw code?
Spoiler
Code:
/*:
 * @plugindesc Allows variables to be changes by equipment.
 * @author LadyBaskerville
 *
 * @help
 * Equipment Variables
 * Version 1.01
 * by LadyBaskerville
 *
 * ---------------------
 *       Notetag
 * ---------------------
 * Use the notetag <Add to Variable: variableId, value, actorId>
 * in the note box of a piece of equipment (weapon or armor).
 * Replace variableId with the ID of the variable you want to change,
 * value with the value you want to add to the variable and actorId
 * with the ID of the actor that has to equip the item for the change to
 * take place (use 0 for all actors).
 *
 * Examples:
 * <Add to Variable: 21, 100, 2>
 * If actor #2 has this equipped, add 100 to variable #21.
 *
 * <Add to Variable: 35, 50, 0>
 * If any actor has this equipped, add 50 to variable #35.
 *
 * ---------------------
 *       Terms
 * ---------------------
 * Free for use in both non-commercial and commercial games.
 * You may repost and edit this plugin, but do not claim you wrote the original code.
 * Please credit me as LadyBaskerville if you use this plugin or edits of it.
 *
 * ---------------------
 *    Known Issues
 * ---------------------
 * - none at the moment.
 *
 * ---------------------
 *      Changelog
 * ---------------------
 * Version 1.01
 * - Added support for negative values.
 * - Fixed a bug that kept variables from resetting.
 *
 * Version 1.00
 * - Finished the plugin.
 *
 */

(function() {
 
 
var LB = LB || {};
LB.EquipVariables = LB.EquipVariables || {};

LB.EquipVariables.notetagsLoaded = false;

// ---------------
//  my functions
// ---------------

// get notetags from a database object and return a list of lists
LB.EquipVariables.getItemNotetags = function(item) {
    if (item == null) {
        return null
    }
    var regexp = /<Add to Variable: (\d+), (-?\d+), (\d+)>/i; // variable, value, actor
    var notes = item.note.split("\n");
    var matches = [];
    for (var i = 0; i < notes.length; i++) {
        var match = notes[i].match(regexp);
        if (match) {
            match[1] = Number(match[1]);
            match[2] = Number(match[2]);
            match[3] = Number(match[3]);
            matches.push(match);
        }
    }
    
    return matches.length > 0 ? matches : null;
};

// ---------------
//   DataManager
// ---------------

// DataManager.isDatabaseLoaded()
LB.EquipVariables.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function() {
    if (!LB.EquipVariables.DataManager_isDatabaseLoaded.call(this)) {
        return false;
    }
    // the database is loaded, we can now preload the notetags if we haven't already done it
    if (!LB.EquipVariables.notetagsLoaded) {
        // preload weapon notetags
        for (var i = 0; i < $dataWeapons.length; i++) {
            if (LB.EquipVariables.getItemNotetags($dataWeapons[i])) {
                $dataWeapons[i].LB_EquipVariables = LB.EquipVariables.getItemNotetags($dataWeapons[i]);
            }
        }
        // preload armor notetags
        for (var i = 0; i < $dataArmors.length; i++) {
            if (LB.EquipVariables.getItemNotetags($dataArmors[i])) {
                $dataArmors[i].LB_EquipVariables = LB.EquipVariables.getItemNotetags($dataArmors[i]);
            }
        }
        LB.EquipVariables.notetagsLoaded = true;
    }
    return true;
};

// ---------------
//   Game_Item
// ---------------

// Game_Item.prototype.LB_toDatabaseObject()
// return the corresponding database object
Game_Item.prototype.LB_toDatabaseObject = function() {
    if (this.isWeapon()) {
        return $dataWeapons[this._itemId];
    } else {
        return $dataArmors[this._itemId];
    }
};

// ---------------
//   Game_Actor
// ---------------

// Game_Actor.prototype.LB_updateEquipVariables(item, reset)
// item is a database object
// reset is a boolean; if true, the value is subtracted from the variable
Game_Actor.prototype.LB_updateEquipVariables = function(item, doReset) {
    if (item && item.LB_EquipVariables) {
        for (var i = 0; i < item.LB_EquipVariables.length; i++) {
            // store the three notetag "parameters" in variables for less confusion
            var variable = item.LB_EquipVariables[i][1];
            var value = item.LB_EquipVariables[i][2];
            var actor = item.LB_EquipVariables[i][3];
            // update the variable value
            if (this.actorId() == actor || actor == 0) {
                if (doReset) {
                    var newValue = $gameVariables.value(variable) - value;
                } else {
                    var newValue = $gameVariables.value(variable) + value;
                }
                //var newValue = reset ? $gameVariables.value(variable) - value : $gameVariables.value(variable) + value;
                $gameVariables.setValue(variable, newValue);
                
                // want to do something with the updated variables? add your code here
                
            }
        }
    }
};

// Game_Actor.prototype.initEquips(equips)
// equips is a list of numbers
// _equips is a list of Game_Items
LB.EquipVariables.Game_Actor_initEquips = Game_Actor.prototype.initEquips;
Game_Actor.prototype.initEquips = function(equips) {
    // call the original function
    LB.EquipVariables.Game_Actor_initEquips.call(this, equips);
    
    // update the variables for all pieces of equipment
    for (var i = 0; i < this._equips.length; i++) {
        this.LB_updateEquipVariables(this._equips[i].LB_toDatabaseObject(), false);
    }
};

// Game_Actor.prototype.changeEquip(slotId, item)
// slotId is the id of the slot for the equipment
// item is a database object
LB.EquipVariables.Game_Actor_changeEquip = Game_Actor.prototype.changeEquip;
Game_Actor.prototype.changeEquip = function(slotId, item) {
    // save old equipment
    var oldEquipment = this._equips[slotId].LB_toDatabaseObject();
    
    // call the original function
    LB.EquipVariables.Game_Actor_changeEquip.call(this, slotId, item);
    
    // reset the variables from the old equipment
    this.LB_updateEquipVariables(oldEquipment, true);
    
    // update the variables from the new equipment
    this.LB_updateEquipVariables(item, false);
};

})();
That works, I'll see if I can find some time to look at it.
That works, I'll see if I can find some time to look at it.
Thanks!
I'm pretty much done with the port, just testing it to make sure it works the same way.

Edit: Here you go. Exactly the same notetag as the original.

Spoiler
Code:
#------------------------------------------------------------------------------#
#  LadyBaskerville's Equipment Variables (port)
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.0
#------------------------------------------------------------------------------#
#  2017-02-15 - Version 1.0 - Initial port
#------------------------------------------------------------------------------#
#
#  This script allows variables to be changed by equipment.
#
#  To use it use the notetag <Add to Variable: variableId, value, actorid>
#  in the notebox of a piece of equipment (weapon or armour).
#  Replace variable id with the ID of the variable you want to change, value
#  with the value you want to add to the variable and actorId with the ID of
#  the actor that has to equip the item for the change to take place (use 0 for
#  all actors)
#
#  Examples:
#  <Add to Variable: 21, 100, 2>
#  If actor #2 has this equipped, add 100 to variable #21.
#
#  <Add to Variable: 35, 50, 0>
#  If any actor has this equipped, add 50 to variable #35.
#
#--------------
#    Terms
#--------------
#  Free for use in both non-commercial and commercial games.
#  You may repost and edit this script, but do not claim you wrote the original
#  code.
#  Please credit LadyBaskerville if you use this script or edits of it.
#  Credit to Trihan for the port is appreciated but unnecessary.
#
#----------------
#  Known issues
#----------------
#  None at the moment.
#------------------------------------------------------------------------------#

$imported = {} if $imported.nil?
$imported["LBTri_EquipVariables"] = true

puts 'Loaded: Equipment Variables by LadyBaskerville (ported by Trihan)'
 
module DataManager
  class << self
    alias_method(:lbtri_ev_dm_load_database, :load_database)
  end
  def self.load_database
    lbtri_ev_dm_load_database
    load_equipvar_notetags
  end
 
  def self.load_equipvar_notetags
    groups = [$data_weapons, $data_armors]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_equipvar_notetags
      end
    end
    puts "Read: Equipment variable notetags"
  end
end

RPG::EquipItem.class_eval do
  attr_reader :ev_variable
  attr_reader :ev_value
  attr_reader :ev_actor
 
  def load_equipvar_notetags
    @note.split(/[\r\n]+/).each do |line|
      case line
      when /<Add to Variable: (\d+), (-?\d+), (\d+)>/i
        @ev_variable = $1.to_i
        @ev_value = $2.to_i
        @ev_actor = $3.to_i
      end
    end
  end
end

Game_Actor.class_eval do
  def update_equip_variables(item, reset)
    if item && item.ev_variable
      variable = item.ev_variable
      value = item.ev_value
      actor = item.ev_actor
      if @actor_id == actor || actor == 0
        if reset
          new_value = $game_variables[variable] - value
        else
          new_value = $game_variables[variable] + value
        end
        $game_variables[variable] = new_value
      end
    end
  end
 
  alias_method(:lbtri_ev_ga_init_equips, :init_equips)
  def init_equips(equips)
    lbtri_ev_ga_init_equips(equips)
    for i in 0...equips.size
      update_equip_variables(@equips[i].object, false)
    end
  end
 
  alias_method(:lbtri_ev_ga_change_equip, :change_equip)
  def change_equip(slot_id, item)
    old_equipment = equips[slot_id].object
    lbtri_ev_ga_change_equip(slot_id, item)
    update_equip_variables(old_equipment, true)
    update_equip_variables(item, false)
  end
end
Thanks bro! Now i can move on with my game!
I'm pretty much done with the port, just testing it to make sure it works the same way.

Edit: Here you go. Exactly the same notetag as the original.

Spoiler
Code:
#------------------------------------------------------------------------------#
#  LadyBaskerville's Equipment Variables (port)
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.0
#------------------------------------------------------------------------------#
#  2017-02-15 - Version 1.0 - Initial port
#------------------------------------------------------------------------------#
#
#  This script allows variables to be changed by equipment.
#
#  To use it use the notetag <Add to Variable: variableId, value, actorid>
#  in the notebox of a piece of equipment (weapon or armour).
#  Replace variable id with the ID of the variable you want to change, value
#  with the value you want to add to the variable and actorId with the ID of
#  the actor that has to equip the item for the change to take place (use 0 for
#  all actors)
#
#  Examples:
#  <Add to Variable: 21, 100, 2>
#  If actor #2 has this equipped, add 100 to variable #21.
#
#  <Add to Variable: 35, 50, 0>
#  If any actor has this equipped, add 50 to variable #35.
#
#--------------
#    Terms
#--------------
#  Free for use in both non-commercial and commercial games.
#  You may repost and edit this script, but do not claim you wrote the original
#  code.
#  Please credit LadyBaskerville if you use this script or edits of it.
#  Credit to Trihan for the port is appreciated but unnecessary.
#
#----------------
#  Known issues
#----------------
#  None at the moment.
#------------------------------------------------------------------------------#

$imported = {} if $imported.nil?
$imported["LBTri_EquipVariables"] = true

puts 'Loaded: Equipment Variables by LadyBaskerville (ported by Trihan)'
 
module DataManager
  class << self
    alias_method(:lbtri_ev_dm_load_database, :load_database)
  end
  def self.load_database
    lbtri_ev_dm_load_database
    load_equipvar_notetags
  end
 
  def self.load_equipvar_notetags
    groups = [$data_weapons, $data_armors]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_equipvar_notetags
      end
    end
    puts "Read: Equipment variable notetags"
  end
end

RPG::EquipItem.class_eval do
  attr_reader :ev_variable
  attr_reader :ev_value
  attr_reader :ev_actor
 
  def load_equipvar_notetags
    @note.split(/[\r\n]+/).each do |line|
      case line
      when /<Add to Variable: (\d+), (-?\d+), (\d+)>/i
        @ev_variable = $1.to_i
        @ev_value = $2.to_i
        @ev_actor = $3.to_i
      end
    end
  end
end

Game_Actor.class_eval do
  def update_equip_variables(item, reset)
    if item && item.ev_variable
      variable = item.ev_variable
      value = item.ev_value
      actor = item.ev_actor
      if @actor_id == actor || actor == 0
        if reset
          new_value = $game_variables[variable] - value
        else
          new_value = $game_variables[variable] + value
        end
        $game_variables[variable] = new_value
      end
    end
  end
 
  alias_method(:lbtri_ev_ga_init_equips, :init_equips)
  def init_equips(equips)
    lbtri_ev_ga_init_equips(equips)
    for i in 0...equips.size
      update_equip_variables(@equips[i].object, false)
    end
  end
 
  alias_method(:lbtri_ev_ga_change_equip, :change_equip)
  def change_equip(slot_id, item)
    old_equipment = equips[slot_id].object
    lbtri_ev_ga_change_equip(slot_id, item)
    update_equip_variables(old_equipment, true)
    update_equip_variables(item, false)
  end
end

I got an error!
e4ObkrD.jpg
[/IMG]
e4ObkrD.jpg

mpokdYu.jpg
It will only work with straight numbers at the moment. Did the original allow you to slot in variables via script?
It will only work with straight numbers at the moment. Did the original allow you to slot in variables via script?

I'm not sure about that. but the error pop up when I put straight numbers too.
0qlsr7F.jpg
Is this without having the $game_variables stuff on ANY item? Like, that is literally the only thing you have?

Are you using any other scripts that affect equipment slots?
Is this without having the $game_variables stuff on ANY item? Like, that is literally the only thing you have?

Are you using any other scripts that affect equipment slots?

Yes, I remove all of $ stuff and still got an error ,and also
I'm using Common Event on Equipment script
Code:
=begin
#===============================================================================
 ** Equip Events
 Author: Hime
 Date: Feb 26, 2013
--------------------------------------------------------------------------------
 ** Change log
 Feb 26, 2014
   - re-ordered event execution .dequip event is executed before equip event.
 Jun 7, 2013
   - updated common event queue for backwards compatibility. common event ID
     returns the first element in the queue list
 Jun 6, 2013
   - equip events do not automatically run in scenes now. You will need
     the Scene Interpreter script
 May 20, 2013
   - common events now queue up and will be run automatically
 Feb 15, 2013
   - added support for dequipping items
 Sep 21
   - fixed bug where equipping nothing threw NoMethod error
 Sep 6, 2012
   - initial release
--------------------------------------------------------------------------------   
 ** Description
 
 Assign common events to equips and have them run when you change your equips.

--------------------------------------------------------------------------------   
 ** Installation
 
 Place this below Materials and above Main.
 
--------------------------------------------------------------------------------   
 ** Usage
 
 Tag your equips with
 
    <equip event: x>
    <dequip event: x>
    
 For some common event ID x.
#===============================================================================
=end
$imported = {} if $imported.nil?
$imported["Tsuki_EquipEvents"] = true
#===============================================================================
# ** Configuration
#===============================================================================
module Tsuki
  module Equip_Events
    
    Equip_Regex = /<equip[-_ ]event:\s*(\d+)>/i
    Dequip_Regex = /<dequip[-_ ]event:\s*(\d+)>/i
  end
end
#===============================================================================
# ** Rest of script
#===============================================================================
module RPG
  class EquipItem
    
    def equip_event_id
      return @equip_event_id unless @equip_event_id.nil?
      res = Tsuki::Equip_Events::Equip_Regex.match(self.note)
      return @equip_event_id = res ? res[1].to_i : 0
    end
    
    def dequip_event_id
      return @dequip_event_id unless @dequip_event_id.nil?
      res = Tsuki::Equip_Events::Dequip_Regex.match(self.note)
      return @dequip_event_id = res ? res[1].to_i : 0
    end
  end
end

class Game_Actor
 
  alias :th_equip_events_change_equip :change_equip
  def change_equip(slot_id, item)
    old_item = @equips[slot_id].object
    th_equip_events_change_equip(slot_id, item)
    if @equips[slot_id].object == item
      $game_temp.reserve_common_event(old_item.dequip_event_id) if old_item
      $game_temp.reserve_common_event(item.equip_event_id) if item
    end
  end
end

unless $imported["TH_CommonEventQueue"]
  class Game_Temp

    attr_reader :reserved_common_events
    alias :th_common_event_queue_init :initialize
    def initialize
      th_common_event_queue_init
      @reserved_common_events = []
    end

    # re-write
    def reserve_common_event(common_event_id)
      @reserved_common_events.push(common_event_id) if common_event_id > 0
    end
    
    def common_event_id
      @reserved_common_events[0]
    end

    # Note that I don't actually need to clear it out. It's done
    # by the queue.

    # true if list is not empty
    def common_event_reserved?
      !@reserved_common_events.empty?
    end

    # Grab the first one, first-in-first-out order
    def reserved_common_event
      $data_common_events[@reserved_common_events.shift]
    end
  end
end
Does it work if you remove that script?
Nope.😐
Blarg, I see what I've done.

Line 111 should be:

"old_equipment = @equips[slot_id].object"

I forgot the @ before equips.

I suppose the follow-up question based on your original issue needs to be: do you WANT to be able to specify the value of a variable for the variable to change as well as a specific variable ID?
Edit: Never mind .I don't want to disturb you so much .

It's fine now! Works like a charm !Thanks again bro.

Original thread: https://forums.rpgmakerweb.com/threads/ace-change-variable-on-equipment.74899/