I've been modifying this old script made by Prexus and making it so I can change only a certain amount of classes. At first, I've been given problems about the script errors about the battle result window, and now I changed a few things and I get an error while trying to change the actual classes.
The Script is in here
The battle result window works perfectly, but now I'm having problems with the class changing scene. I made it so that I can only change to a certain number of classes, rather than the entire list in the database. When I go to change a class that isn't the default class, I get the following error:
"line 169: ArgumentError occurred
bad value for range"
And I can't figure out what's wrong. It worked perfectly before, and now I can't get it to work. I need help with this as soon as possible, thanks.
Edit: Nevermind, I've solved it! I found out that the problem wasn't the actual line, but in line 39 which the class levels and experience points are defined in the for loop. I put in the attribute variable "@class_id" when I'm supposed to input the number of the last Class ID in the database. In example: for i in 1..11 when I have 11 classes in the database. And when you only want to change into some of the classes in the list, you go to line 305 and change the 1..8 to the number of changeable classes for your lead party member. Regardless, this topic is already resolved, and any moderators out there can go ahead and close it.
Thanks,
Eric&TheCheat :wink:
The Script is in here
Code:
# Class and Profession System Edited
# By Prexus
# Special Thanks: Fuso, Astro_Mech
# [url=http://prexus.rmxponline.com/]http://prexus.rmxponline.com/[/url]
# All Rights Reserved
# --
# Refer to: [url=http://www.rmxp.net/forums/index.php?showtopic=9421]http://www.rmxp.net/forums/index.php?showtopic=9421[/url]
# For Additional Support.
# Redefinitions and additions to game_actor
class Game_Actor < Game_Battler
attr_accessor :class_level
attr_accessor :class_exp
attr_accessor :end_of_classes
def setup(actor_id)
actor = $data_actors[actor_id]
@actor_id = actor_id
@name = actor.name
@character_name = actor.character_name
@character_hue = actor.character_hue
@battler_name = actor.battler_name
@battler_hue = actor.battler_hue
@class_id = actor.class_id
@weapon_id = actor.weapon_id
@armor1_id = actor.armor1_id
@armor2_id = actor.armor2_id
@armor3_id = actor.armor3_id
@armor4_id = actor.armor4_id
@level = actor.initial_level
@exp_list = Array.new(101)
# Defines Class EXP Table
@class_exp_list = Array.new(101)
make_class_exp_list
make_exp_list
@exp = @exp_list[@level]
@class_level = []
@class_exp = []
for i in 1..@class_id
@class_level[i] = 1
@class_exp[i] = @class_exp_list[@class_level[i]]
end
@skills = []
@hp = maxhp
@sp = maxsp
@states = []
@states_turn = {}
@maxhp_plus = 0
@maxsp_plus = 0
@str_plus = 0
@dex_plus = 0
@agi_plus = 0
@int_plus = 0
# Skills learned are now based on class level rather
# than the character level. The character level governs statistical
# growth rather than skill growth.
# --
# Teaches initial skills for class
for i in 1..@class_level[@class_id]
for j in $data_classes[@class_id].learnings
if j.level == i
learn_skill(j.skill_id)
end
end
end
update_auto_state(nil, $data_armors[@armor1_id])
update_auto_state(nil, $data_armors[@armor2_id])
update_auto_state(nil, $data_armors[@armor3_id])
update_auto_state(nil, $data_armors[@armor4_id])
end
# Mainly used for drawing in windows [draw_text(x,y,wid,hei, @actor.show_class_level)
# or something of the like]
def show_class_exp
return @class_exp[@class_id]
end
def show_class_level
return @class_level[@class_id]
end
def make_class_exp_list
# Defines the Class EXP table based on the defined character ID in the
# database. example: actor = $data_actors[9] assigns the Class EXP table to the
# ninth actor's EXP table.
actor = $data_actors[9]
@class_exp_list[1] = 0
pow_i = 2.4 + actor.exp_inflation / 100.0
for i in 2..100
if i > actor.final_level
@class_exp_list[i] = 0
else
n = actor.exp_basis * ((i + 3) ** pow_i) / (5 ** pow_i)
@class_exp_list[i] = @class_exp_list[i-1] + Integer(n)
end
end
end
# Forgets all skills, change 80 to the maximum number of skills in the
# database (80 is default)
def forget_all
for i in 1...80
if @skills.include?(i)
@skills.delete(i)
end
end
end
def class_name
return $data_classes[@class_id].name
end
def class_exp_s
return @class_exp_list[@class_level[@class_id]+1] > 0 ? @class_exp[@class_id].to_s : "-------"
end
def next_class_exp_s
return @class_exp_list[@class_level[@class_id]+1] > 0 ? @class_exp_list[@class_level[@class_id]+1].to_s : "-------"
end
def next_class_rest_exp_s
return @class_exp_list[@class_level[@class_id]+1] > 0 ?
(@class_exp_list[@class_level[@class_id]+1] - @class_exp[@class_id]).to_s : "-------"
end
# A redeclaration of def exp=(exp) which works for different classes.
# If you wish to add EXP to a character now, if you want to add to just
# the EXP use the regular event command but if you want to add to all the
# exp types, Call Script and use this line: $game_party.actors[ID].add_exp(amount)
def add_exp(value)
@exp += value
while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
@level += 1
for j in $data_classes[@class_id].learnings
if j.level == @level
learn_skill(j.skill_id)
end
end
end
while @exp < @exp_list[@level]
@level -= 1
end
@class_exp[@class_id] += (value*0.75).floor
while @class_exp[@class_id] >= @class_exp_list[@class_level[@class_id]+1] and @class_exp_list[@class_level[@class_id]+1] > 0
@class_level[@class_id] += 1
for j in $data_classes[@class_id].learnings
if j.level == @class_level[@class_id]
learn_skill(j.skill_id)
end
end
end
while @class_exp[@class_id] < @class_exp_list[@class_level[@class_id]]
@class_level[@class_id] -= 1
end
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
# When changing classes, all skills are forgotten and relearned
def class_id=(class_id)
if $data_classes[class_id] != nil
@class_id = class_id
unless equippable?($data_weapons[@weapon_id])
equip(0, 0)
end
unless equippable?($data_armors[@armor1_id])
equip(1, 0)
end
unless equippable?($data_armors[@armor2_id])
equip(2, 0)
end
unless equippable?($data_armors[@armor3_id])
equip(3, 0)
end
unless equippable?($data_armors[@armor4_id])
equip(4, 0)
end
forget_all
for i in 1..@class_level[@class_id]
for j in $data_classes[@class_id].learnings
if j.level == i
learn_skill(j.skill_id)
end
end
end
end
end
end
# Small modification to the way EXP is given at the end of battle.
class Scene_Battle
alias cps_scene_battle_main main
def main
cps_scene_battle_main
if @level_window != nil
@level_window.dispose
end
end
def start_phase5
# Shift to phase 5
@phase = 5
# Play victory ME
$game_system.me_play($game_system.battle_end_me)
# Play map BGM
$game_system.bgm_play($game_temp.map_bgm)
# EXP
exp = 0
gold = 0
treasures = []
# ???
for enemy in $game_troop.enemies
# ??????????????
unless enemy.hidden
# ?? EXP????????
exp += enemy.exp
gold += enemy.gold
# ?????????
if rand(100) < enemy.treasure_prob
if enemy.item_id > 0
treasures.push($data_items[enemy.item_id])
end
if enemy.weapon_id > 0
treasures.push($data_weapons[enemy.weapon_id])
end
if enemy.armor_id > 0
treasures.push($data_armors[enemy.armor_id])
end
end
end
end
# ???????? 6 ??????
treasures = treasures[0..5]
# EXP ??
@level_window = Window_Level.new
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.cant_get_exp? == false
last_level = actor.level
last_class_level = actor.class_level[actor.class_id]
actor.add_exp(exp)
if actor.level > last_level
@level_window.level_up(i)
end
if actor.class_level[actor.class_id] > last_class_level
@level_window.class_up(i)
end
end
end
# ??????
$game_party.gain_gold(gold)
# ???????
for item in treasures
case item
when RPG::Item
$game_party.gain_item(item.id, 1)
when RPG::Weapon
$game_party.gain_weapon(item.id, 1)
when RPG::Armor
$game_party.gain_armor(item.id, 1)
end
end
# ???????????????
@result_window = Window_BattleResult.new(exp, gold, treasures)
# ???????????
@phase5_wait_count = 100
end
#--------------------------------------------------------------------------
# ? ?????? (???????????)
#--------------------------------------------------------------------------
def update_phase5
# ????????? 0 ???????
if @phase5_wait_count > 0
# ????????????
@phase5_wait_count -= 1
# ????????? 0 ??????
if @phase5_wait_count == 0
# ????????????
@result_window.visible = true
@level_window.visible = true
# ??????????????
$game_temp.battle_main_phase = false
# ?????????????????
@status_window.refresh
@level_window.refresh
end
return
end
# C ??????????
if Input.trigger?(Input::C)
# ????
battle_end(0)
end
end
end
# Window to display the names of all the classes.
class Window_Classes < Window_Selectable
def initialize
super(0, 0, 160, 480)
@column_max = 1
refresh
self.index = 0
end
def classdata
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# This for makes sure only to show the first four entries in $data_classes.
# If you make more than 4 classes, be sure to modify these numbers.
for i in 1..8
@data.push($data_classes[i])
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
item = @data[index]
x = 4
y = index * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(x, y, 128, 32, item.name, 0)
end
end
class Scene_ClassSelect
def initialize(actor_index = 0)
@actor_index = actor_index
end
def main
@actor = $game_party.actors[@actor_index]
@class_win = Window_Classes.new
@spriteset = Spriteset_Map.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@class_win.dispose
@spriteset.dispose
end
def update
@class_win.update
@spriteset.update
if @class_win.active
update_class
return
end
end
def update_class
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
#returns to the menu with the item selection highlighted. Change to Scene_Map if you want to change class via map event.
$scene = Scene_Menu.new(1)
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
# Updates character's profession based on the decision.
@actor.class_id = @class_win.classdata.id
# Return to Scene_Map, change it to Scene_Menu.new if you're using the script via menu.
$scene = Scene_Map.new
return
end
end
end
# Updated version of the default battle result made to show the gain
# in Class EXP (C-EXP)
class Window_BattleResult < Window_Base
def initialize(exp, gold, treasures)
@exp = exp
@gold = gold
@treasures = treasures
super(0, 0, 640, 192)
self.contents = Bitmap.new(width - 32, height - 32)
self.visible = false
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 128, 32, $data_system.words.gold)
self.contents.draw_text(4, 64, 128, 32, "EXP:")
self.contents.draw_text(4, 96, 128, 32, "C-EXP:")
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 128, 32, @gold.to_s, 2)
self.contents.draw_text(4, 64, 128, 32, @exp.to_s, 2)
self.contents.draw_text(4, 96, 128, 32, (@exp*0.75).floor.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(164, 0, 128, 32, "Items Found:")
y = 32
for item in @treasures
draw_item_name(item, 164, y)
y += 32
end
end
end
# Temporary mod of Window_Status to show Class/Profession and Level.
class Window_Status < Window_Base
def refresh
self.contents.clear
draw_actor_graphic(@actor, 40, 112)
draw_actor_name(@actor, 4, 0)
draw_actor_class(@actor, 4 + 144, 0)
draw_actor_level(@actor, 96, 32)
draw_actor_state(@actor, 96, 64)
draw_actor_hp(@actor, 96, 112, 172)
draw_actor_sp(@actor, 96, 144, 172)
draw_actor_parameter(@actor, 96, 192, 0)
draw_actor_parameter(@actor, 96, 224, 1)
draw_actor_parameter(@actor, 96, 256, 2)
draw_actor_parameter(@actor, 96, 304, 3)
draw_actor_parameter(@actor, 96, 336, 4)
draw_actor_parameter(@actor, 96, 368, 5)
draw_actor_parameter(@actor, 96, 400, 6)
self.contents.font.color = system_color
self.contents.draw_text(320, 48, 80, 32, "EXP")
self.contents.draw_text(320, 80, 80, 32, "NEXT")
self.contents.font.color = normal_color
self.contents.draw_text(320 + 80, 48, 84, 32, @actor.exp_s, 2)
self.contents.draw_text(320 + 80, 80, 84, 32, @actor.next_rest_exp_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(320, 160, 96, 32, "Equipment")
draw_item_name($data_weapons[@actor.weapon_id], 320 + 16, 208)
draw_item_name($data_armors[@actor.armor1_id], 320 + 16, 256)
draw_item_name($data_armors[@actor.armor2_id], 320 + 16, 304)
draw_item_name($data_armors[@actor.armor3_id], 320 + 16, 352)
draw_item_name($data_armors[@actor.armor4_id], 320 + 16, 400)
# Mod is here
self.contents.font.color = system_color
self.contents.draw_text(300, 0, 96, 32, "Lv")
self.contents.draw_text(320, 112, 80, 32, "C-EXP")
self.contents.font.color = normal_color
self.contents.draw_text(472, 112, 200, 32, @actor.show_class_exp.to_s)
self.contents.draw_text(300, 0, 72, 32, @actor.show_class_level.to_s, 2)
end
end
class Window_Level < Window_Base
def initialize
super(0, 192, 640, 128)
self.contents = Bitmap.new(width - 32, height - 32)
self.visible = false
@level_up_flags = [false, false, false, false]
@class_up_flags = [false, false, false, false]
refresh
end
def level_up(actor_index)
@level_up_flags[actor_index] = true
end
def class_up(actor_index)
@class_up_flags[actor_index] = true
end
def refresh
self.contents.clear
@item_max = $game_party.actors.size
for i in 0...$game_party.actors.size
@actor = $game_party.actors[i]
self.contents.font.color = normal_color
self.contents.font.size = 18
draw_actor_exp_bar(@actor, i * 160 + 4, 0, 120)
draw_actor_class_bar(@actor, i * 160 + 4, 32, 120)
self.contents.draw_text(i * 160 + 4, 0, 120, 32, "Level")
self.contents.draw_text(i * 160 + 4, 32, 120, 32, "C. Level")
if @level_up_flags[i]
self.contents.font.color = Color.new(0,255,0,255)
self.contents.font.size = 24
self.contents.draw_text(i * 160 + 4, 0, 120, 32, "LEVEL UP!", 2)
end
if @class_up_flags[i]
self.contents.font.color = Color.new(0,255,0,255)
self.contents.font.size = 24
self.contents.draw_text(i * 160 + 4, 32, 120, 32, "LEVEL UP!", 2)
end
end
end
end
# Gradient Bars
# [url=http://members.jcom.home.ne.jp/cogwheel/]http://members.jcom.home.ne.jp/cogwheel/[/url]
class Game_Actor < Game_Battler
def now_exp
return @exp - @exp_list[@level]
end
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
def now_class_exp
return @class_exp[@class_id] - @class_exp_list[@class_level[@class_id]]
end
def next_class_exp
return @class_exp_list[@class_level[@class_id]+1] > 0 ? @class_exp_list[@class_level[@class_id]+1] -
@class_exp_list[@class_level[@class_id]] : 0
end
end
class Window_Base < Window
def draw_actor_exp_bar(actor, x, y, width = 144)
if actor.next_exp != 0
rate = actor.now_exp.to_f / actor.next_exp
else
rate = 1
end
plus_x = 0
rate_x = 0
plus_y = 25
plus_width = 0
rate_width = 100
height = 10
align1 = 1
align2 = 2
align3 = 0
grade1 = 1
grade2 = 0
color1 = Color.new(0, 0, 0, 192)
color2 = Color.new(255, 255, 192, 192)
color3 = Color.new(0, 0, 0, 192)
color4 = Color.new(64, 0, 0, 192)
color5 = Color.new(80 * rate, 80 - 80 * rate ** 2, 80 - 80 * rate, 192)
color6 = Color.new(240 * rate, 240 - 240 * rate ** 2, 240 - 240 * rate, 192)
if actor.next_exp != 0
exp = (width + plus_width) * actor.now_exp * rate_width /
100 / actor.next_exp
else
exp = (width + plus_width) * rate_width / 100
end
gauge_rect(x + plus_x + width * rate_x / 100, y + plus_y,
width, plus_width + width * rate_width / 100,
height, exp, align1, align2, align3,
color1, color2, color3, color4, color5, color6, grade1, grade2)
end
def draw_actor_class_bar(actor, x, y, width = 144)
if actor.next_class_exp != 0
rate = actor.now_class_exp.to_f / actor.next_class_exp
else
rate = 1
end
plus_x = 0
rate_x = 0
plus_y = 25
plus_width = 0
rate_width = 100
height = 10
align1 = 1
align2 = 2
align3 = 0
grade1 = 1
grade2 = 0
color1 = Color.new(0, 0, 0, 192)
color2 = Color.new(255, 255, 192, 192)
color3 = Color.new(0, 0, 0, 192)
color4 = Color.new(64, 0, 0, 192)
color5 = Color.new(80 * rate, 80 - 80 * rate ** 2, 80 - 80 * rate, 192)
color6 = Color.new(240 * rate, 240 - 240 * rate ** 2, 240 - 240 * rate, 192)
if actor.next_class_exp != 0
exp = (width + plus_width) * actor.now_class_exp * rate_width /
100 / actor.next_class_exp
else
exp = (width + plus_width) * rate_width / 100
end
gauge_rect(x + plus_x + width * rate_x / 100, y + plus_y,
width, plus_width + width * rate_width / 100,
height, exp, align1, align2, align3,
color1, color2, color3, color4, color5, color6, grade1, grade2)
end
def gauge_rect(x, y, rect_width, width, height, gauge, align1, align2, align3,
color1, color2, color3, color4, color5, color6, grade1, grade2)
case align1
when 1
x += (rect_width - width) / 2
when 2
x += rect_width - width
end
case align2
when 1
y -= height / 2
when 2
y -= height
end
self.contents.fill_rect(x, y, width, height, color1)
self.contents.fill_rect(x + 1, y + 1, width - 2, height - 2, color2)
if align3 == 0
if grade1 == 2
grade1 = 3
end
if grade2 == 2
grade2 = 3
end
end
if (align3 == 1 and grade1 == 0) or grade1 > 0
color = color3
color3 = color4
color4 = color
end
if (align3 == 1 and grade2 == 0) or grade2 > 0
color = color5
color5 = color6
color6 = color
end
self.contents.gradation_rect(x + 2, y + 2, width - 4, height - 4,
color3, color4, grade1)
if align3 == 1
x += width - gauge
end
self.contents.gradation_rect(x + 2, y + 2, gauge - 4, height - 4,
color5, color6, grade2)
end
end
class Bitmap
def gradation_rect(x, y, width, height, color1, color2, align = 0)
if align == 0
for i in x...x + width
red = color1.red + (color2.red - color1.red) * (i - x) / (width - 1)
green = color1.green +
(color2.green - color1.green) * (i - x) / (width - 1)
blue = color1.blue +
(color2.blue - color1.blue) * (i - x) / (width - 1)
alpha = color1.alpha +
(color2.alpha - color1.alpha) * (i - x) / (width - 1)
color = Color.new(red, green, blue, alpha)
fill_rect(i, y, 1, height, color)
end
elsif align == 1
for i in y...y + height
red = color1.red +
(color2.red - color1.red) * (i - y) / (height - 1)
green = color1.green +
(color2.green - color1.green) * (i - y) / (height - 1)
blue = color1.blue +
(color2.blue - color1.blue) * (i - y) / (height - 1)
alpha = color1.alpha +
(color2.alpha - color1.alpha) * (i - y) / (height - 1)
color = Color.new(red, green, blue, alpha)
fill_rect(x, i, width, 1, color)
end
elsif align == 2
for i in x...x + width
for j in y...y + height
red = color1.red + (color2.red - color1.red) *
((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
green = color1.green + (color2.green - color1.green) *
((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
blue = color1.blue + (color2.blue - color1.blue) *
((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
alpha = color1.alpha + (color2.alpha - color1.alpha) *
((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
color = Color.new(red, green, blue, alpha)
set_pixel(i, j, color)
end
end
elsif align == 3
for i in x...x + width
for j in y...y + height
red = color1.red + (color2.red - color1.red) *
((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
green = color1.green + (color2.green - color1.green) *
((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
blue = color1.blue + (color2.blue - color1.blue) *
((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
alpha = color1.alpha + (color2.alpha - color1.alpha) *
((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
color = Color.new(red, green, blue, alpha)
set_pixel(i, j, color)
end
end
end
end
end
The battle result window works perfectly, but now I'm having problems with the class changing scene. I made it so that I can only change to a certain number of classes, rather than the entire list in the database. When I go to change a class that isn't the default class, I get the following error:
"line 169: ArgumentError occurred
bad value for range"
And I can't figure out what's wrong. It worked perfectly before, and now I can't get it to work. I need help with this as soon as possible, thanks.
Edit: Nevermind, I've solved it! I found out that the problem wasn't the actual line, but in line 39 which the class levels and experience points are defined in the for loop. I put in the attribute variable "@class_id" when I'm supposed to input the number of the last Class ID in the database. In example: for i in 1..11 when I have 11 classes in the database. And when you only want to change into some of the classes in the list, you go to line 305 and change the 1..8 to the number of changeable classes for your lead party member. Regardless, this topic is already resolved, and any moderators out there can go ahead and close it.
Thanks,
Eric&TheCheat :wink: