Set variable to ActorID (Edit of Vel System - Chapter Indicator v1.00)

I am absolutely certain this should be incredibly simple but I am just banging my head against the wall.

I know you can set ActorID to variable using Control Variables in the event window but I can't figure out how to do it in a custom script.

I need it in script as I am modifying Vel's Chapter Indicator script to show various bits of other information in concert with Yanfly's save engine. Everything is working perfectly except in order to display the current outfit of the actor I need to set a variable to the party leaders ActorID as I have used different ActorID slots for each of the different outfits. This needs to happen whilst in the save menu and so cannot be done through event-ing.

I have tried a number of different methods, most of which should have worked from what my minuscule understanding of ruby tells me but none of them has. I am obviously missing a definition here but from everything I have managed to find online all the different ways of getting ActorID I am trying should be global and reference-able from my script but clearly I just don't understand it enough to make it work.

I have tried the following...

Spoiler: Attempt 1:
def set_var_actoid_a
var100a = $game_party.members[0].id
$game_variables[100] = var100a
end

Spoiler: Attempt 2:
def set_var_actoid_b
var100b = $game_party.all_members[0]
$game_variables[100] = var100b
end

Spoiler: Attempt 3:
def set_var_actoid_c
$gameVariables.setValue(100, $gameParty.leader().actorId())
end

Spoiler: Attempt 4:
def set_var_actoid_d
var100d = $game_actors[actor_id]
$game_variables[100] = var100d
end

I am sure for anyone who has any real experience with scripting I am making an obvious error and would very much appreciate any and all help you can give. In case it is not clear I have absolutely no idea what I am doing and have only gotten this far through literal guess work. This isn't for any actual real game or project just my messing about but it's frustrating me no end and I would love to be able to put it behind me and maybe learn something in the process.

I have attached my modified Vel Chapter Indicator script below.

Code:
#==============================================================================
#
# ▼ Vel System - Chapter Indicator v1.00
# -- Last Updated: 2/15/2013
# -- Author: Ven01273
# -- Level: Normal
# -- Requires: Yanfly Engine Ace - Ace Save Engine v1.00+
#  *Based on Chapter Teller by wltr3565
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YEA-VS-CTI"] = true

#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2/15/2013 - Started Script and finished.
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script enables Yanfly's Ace Save Engine to display the Chapter you're in.
# This'll be shown right below Variable Column 1 in the Ace Save Engine.
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below the Ace Save Engine Script but above ▼ Main Process.
#
# If you want to have more chapters, just follow the template below:
#
# CHAPTER_WORDS[n] = "string"
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script was made with RGSS3. I don't use the other versions, so I don't
# know if it'll work. See for yourself.
#
# This script requires Yanfly Engine Ace - Ace Save Engine v1.00+ and the
# script must be placed under Ace Save Engine in the script listing.
#==============================================================================
# ▼ Commercial?
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script itself is allowed to be used in commercial games.
# However it requires Yanfly's 'Ace Save Engine' to function.
# Only Yanfly can give permission for the use of the 'Ace Save Engine'
#==============================================================================

module VEL

#==============================================================================
#                         BEGIN OUTFIT EDITABLE REGION
#==============================================================================
  module OUTFIT

    OUTFIT_WORDS = [] #Do not remove or edit this.

    OUTFIT_VARIABLE = 100
# The variable referenced when indicating the outfit you're wearing.

    UNDEFINED_OUTFIT = "Outfit: None."
# What is shown when OUTFIT_VARIABLE's value is less than or greater OUTFIT_MAX.

    OUTFIT_MAX = 24
# The maximum amount of outfits you want.

    OUTFIT_WORDS[11] = "Outfit: Rookie Uniform."
    OUTFIT_WORDS[14] = "Outfit: Smart Uniform."
    OUTFIT_WORDS[22] = "Outfit: Casual Outfit."
 
  end

#==============================================================================
#                         END OUTFIT EDITABLE REGION
#==============================================================================


#==============================================================================
#                         BEGIN TITLE EDITABLE REGION
#==============================================================================
  module TITLE
 
    TITLE_WORDS = [] #Do not remove or edit this.

    TITLE_VARIABLE = 1
# The variable referenced when indicating the title you're known by.
 
    UNDEFINED_TITLE = "Rookie."
# What is shown when TITLE_VARIABLE's value is less than or greater TITLE_MAX.
 
    TITLE_MAX = 100
# The maximum amount of different Titles you want.

    TITLE_WORDS[0] = "Title: Novice."
    TITLE_WORDS[1] = "Title: Initiate."


  end

#==============================================================================
#                         END TITLE EDITABLE REGION
#==============================================================================


#==============================================================================
#                         BEGIN BLURB EDITABLE REGION
#==============================================================================
    module BLURB

    BLURB_WORDS = [] #Do not remove or edit this.

    BLURB_VARIABLE = 1
# The variable referenced when indicating the blurb to display.

    UNDEFINED_BLURB = "Biography: None known."
# What is shown when BLURB_VARIABLE's value is less than or greater than BLURB_MAX.

    BLURB_MAX = 100
# The maximum amount of different Blurbs you want.

    BLURB_WORDS[0] = "Biography: some blurb and backstory."
    BLURB_WORDS[1] = "Biography: some other blurb and backstory."
 
  end

#==============================================================================
#                         END BLURB EDITABLE REGION
#==============================================================================


#==============================================================================
# Don't edit anything past this point, unless you know what you're doing.
#==============================================================================

end

#--------------------------------------------------------------------------
# * Edit Script: Ace Save Engine
#--------------------------------------------------------------------------

class Window_FileStatus < Window_Base

#--------------------------------------------------------------------------
# New Method: draw_save_outfit
#--------------------------------------------------------------------------
  def draw_save_outfit(dx, dy, dw)
    return if @header[:variables].nil?
    reset_font_settings
    change_color(normal_color)
    variable_id = VEL::OUTFIT::OUTFIT_VARIABLE
    return unless variable_id >= 0
    varival = @header[:variables][variable_id]
    if varival < 0
      draw_text(dx, dy, dw, line_height, VEL::OUTFIT::UNDEFINED_OUTFIT)
    end
    if varival > VEL::OUTFIT::OUTFIT_MAX
      draw_text(dx, dy, dw, line_height, VEL::OUTFIT::UNDEFINED_OUTFIT)
    end
    if varival <= VEL::OUTFIT::OUTFIT_MAX and varival >= 0
    draw_text(dx, dy, dw, line_height, VEL::OUTFIT::OUTFIT_WORDS[varival])
    end
  end

#--------------------------------------------------------------------------
# New Method: draw_save_title
#--------------------------------------------------------------------------
  def draw_save_title(dx, dy, dw)
    return if @header[:variables].nil?
    reset_font_settings
    change_color(normal_color)
    variable_id = VEL::TITLE::TITLE_VARIABLE
    return unless variable_id >= 0
    varival = @header[:variables][variable_id]
    if varival < 0
      draw_text(dx, dy, dw, line_height, VEL::TITLE::UNDEFINED_TITLE)
    end
    if varival > VEL::TITLE::TITLE_MAX
      draw_text(dx, dy, dw, line_height, VEL::TITLE::UNDEFINED_TITLE)
    end
    if varival <= VEL::TITLE::TITLE_MAX and varival >= 0
    draw_text(dx, dy, dw, line_height, VEL::TITLE::TITLE_WORDS[varival])
    end
  end

#--------------------------------------------------------------------------
# New Operation: slice_text (Automatically word wrap text onto new line)
# Gifted by Mangomight from http://rmrk.net/index.php?topic=47289.0
#--------------------------------------------------------------------------
 
  def slice_text(x, y, width, height, text)
    words = text.split
    result, current_text = [], words.shift
    words.each_index {|i|
      if current_text.sub!(/\ln/) { '' } != nil ||
        self.text_size("#{current_text} #{words[i]}").width > width
        result.push(current_text)
        current_text = words[i]
      else
        current_text = "#{current_text} #{words[i]}"
      end
      result.push(current_text) if i >= words.size-1
    }
    result.each_index { |i|
      draw_text(x, y + (height * i), width, height, result[i])
    }
  end

#--------------------------------------------------------------------------
# New Method: draw_save_blurb
#--------------------------------------------------------------------------

  def draw_save_blurb(dx, dy, dw)
    return if @header[:variables].nil?
    reset_font_settings
    change_color(normal_color)
    variable_id = VEL::BLURB::BLURB_VARIABLE
    return unless variable_id >= 0
    varival = @header[:variables][variable_id]
    if varival < 0
      slice_text(dx, dy, dw, line_height, VEL::BLURB::UNDEFINED_BLURB)
    end
    if varival > VEL::BLURB::BLURB_MAX
      slice_text(dx, dy, dw, line_height, VEL::BLURB::UNDEFINED_BLURB)
    end
    if varival <= VEL::BLURB::BLURB_MAX and varival >= 0
      slice_text(dx, dy, dw, line_height, VEL::BLURB::BLURB_WORDS[varival])
    end
  end

#--------------------------------------------------------------------------
# Overwrite Method: draw_save_contents
#--------------------------------------------------------------------------
  def draw_save_contents
    draw_save_slot(4, 0, contents.width/2-8)
    draw_save_playtime(contents.width/2+4, 0, contents.width/2-8)
    draw_save_total_saves(4, line_height, contents.width/2-8)
    draw_save_gold(contents.width/2+4, line_height, contents.width/2-8)
    draw_save_location(4, line_height*2, contents.width-8)
    draw_save_characters(0, line_height*5 + line_height/3)
    draw_save_outfit(4, line_height*7, contents.width-8)
    draw_save_column1(16, line_height*8, contents.width/2-48)
    draw_save_column2(contents.width/2+16, line_height*8, contents.width/2-48)
    draw_save_title(4, line_height*9, contents.width-8)
    draw_save_blurb(4, line_height*10, contents.width)
  end
end

#==============================================================================
#                               END OF FILE
#==============================================================================

Original script was sourced from...
https://rpgmaker.net/scripts/270/

Script requires Yanfly Ace Save Engine from...
https://yanflychannel.wordpress.com/rmvxa/menu-scripts/ace-save-engine/

If someone could let me know the exact code to get the party leader ActorID and pass that ID into variable 100 and the exact place to put that code in the above script it would be tremendously satisfying. If you can explain the how and why of it as well that would be even more gratifying.

Whatever the case may be please Help.
Thanks, Daede

P.S. I have thoroughly googled every variation of Set variable to ActorID and there are a handful of similar requests but none seem to have been answered, or at least not in anyway I could understand or replicate. Most just seem to end with using Control Variable via Common Event which is of no use in this circumstance that I can see.

Note: Edited to add source links to original scripts as per Mod advice.
Just a heads up for the future. We prefer it if you can possibly give a link to the web page where you got a particular script, rather than copy/pasting it here. That is because sometimes the original page contains additional info and/or discussion which could be helpful. Also, many scripters do not like their scripts being reposted as it means that inevitably there are different versions floating around the internet.

Thanks.
In script call: Just do this:
$game_variables[100] = $game_party.members[0].id
This will take the id of the leader then pass it to variable #100.
Btw, if you call those methods descibed above on boot. It will crash. Try to call it somewhere else.
$game_variables[100] = $game_party.members[0].id just spits out the undefined method error, I believe because game_variables isn't initialized in this script.

As far as I can figure it in order for that to work a bunch of code has to be added to the script first to define those calls.

Ideally I would like to know what the initialization code is and where to put it in this script or failing that what script and where I can put the $game_variables[100] = $game_party.members[0].id command where it will be run and update the variable prior to a game save operation being performed.

Remember I need this operation to be performed in a custom script not in an event that is the problem.
You can try this instead. Pastebin
Ok that does set the variable when starting a new game but the variable doesn't update.

I need that variable to be updated each time the game is saved prior to the save taking place so that the correct outfit is reflected.

It did however give me an idea that does work if not exactly where I want it to...

The game_variables I need are apparently initialized in the Yanfly 'Ace Save Engine' script itself so I can set my variable via $game_variables[100] = member.id in that script rather than in the Vel 'Chapter Indicator' script and it does work and update each time the save menu is accessed.

Partial Script below lines 384ish-410ish from the original Yanfly Ace Save Engine from https://yanflychannel.wordpress.com/rmvxa/menu-scripts/ace-save-engine/ with my edit notated
Code:
  #--------------------------------------------------------------------------
  # draw_save_characters
  #--------------------------------------------------------------------------
  def draw_save_characters(dx, dy)
    return if @header[:party].nil?
    reset_font_settings
    make_font_smaller
    dw = (contents.width - dx) / @header[:party].max_battle_members
    dx += dw/2
    for member in @header[:party].battle_members
      next if member.nil?
      member = @header[:actors][member.id]
      change_color(normal_color)
      draw_actor_graphic(member, dx, dy)
# BEGIN EDIT BY DAEDE
      $game_variables[100] = member.id #Addition by Daede
# END EDIT BY DAEDE
      text = member.name
      draw_text(dx-dw/2, dy, dw, line_height, text, 1)
      text = member.level.group
      cx = text_size(text).width
      change_color(system_color)
      text = Vocab::level_a
      dx += dw
    end
  end

This kind of means personal problem solved but I would rather not leave it there as it is a very specific use solution. Any chance we can keep this going until we get a code snipet that can be added into any existing or new custom script to make the actorID or any ID be it ItemID, WeaponID, ArmorID, EnemyID accessible in an easy manor.

I don't know if that is outside the intent of the forum, I am obviously very new here but I feel it would be a more universally useful result than just your particular issue solved, thread closed, move along?

Cheers,
Daede.

Original thread: https://forums.rpgmakerweb.com/threads/set-variable-to-actorid-edit-of-vel-system-chapter-indicator-v1-00.90917/