Manual Experience Table Enumeration
by RPG Advocate
saved from Phylomortis.Com
Introduction
This script allows you to define a character's experience requirements for each level manually. To use the manul experience table setup, create a filec called actor[number]exp.rxdata, where [number] is the actor ID of the character whose experience table is being created. For example, for actor #1, the file would be called actor1exp.rxdata.
You can put any comments you like on seperate lines. The only lines that will be read are those lines that contain only numbers and spaces. On lines with multiple numbers, the last number is the one that will be used.
NOTE: The experience tables, though they have .rxdata extensions, are still .txt files. They will not be encrypted with the rest of your game if you choose to encrypt your demo. You'll have to supply the files seperately.
# Manual Experience Table Enumeration
# by RPG Advocate
# Displays error messages
# if set to true
METE_ERROR_SHOW = true
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles the actor. It's used within the Game_Actors class
# ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Calculate EXP
#--------------------------------------------------------------------------
alias mete_make_exp_list make_exp_list
def make_exp_list
# The original call
mete_make_exp_list
# Obtain actor and read outside experience chart if available
actor = $data_actors[@actor_id]
fname = "Data\\actor" + actor.id.to_s + "exp.rxdata"
if FileTest.exist?(fname)
get_exp_list_from_file(fname)
if @exp_file_error
@exp_list = Array.new(101)
else
return
end
end
end
#--------------------------------------------------------------------------
# * Obtain experience table from file
#--------------------------------------------------------------------------
def get_exp_list_from_file(filename)
begin
if @exp_file_error
return
end
f = File.open(filename)
list = f.readlines
list = correct_malformed_input(list)
if @exp_file_error
return
end
for i in 0..list.size - 1
list[i] = list[i].to_i
end
list = correct_erroneous_data(list)
for i in list.size..100
list[i] = 0
end
list.unshift(0)
@exp_list = list
rescue StandardError
s1 = "Unrecoverable error while reading " + @name + "'s EXP list.\n"
s2 = "Experience curve declared in the database will be used instead."
print(s1 + s2) if METE_ERROR_SHOW
@exp_file_error = true
retry
ensure
if f != nil
f.close
end
end
end
#--------------------------------------------------------------------------
# * Delete and repair experience table
#--------------------------------------------------------------------------
def correct_malformed_input(list)
lines_to_delete = []
if list.size == 0
s1 = "Warning: " + @name + "'s experience requirement file is empty. "
s2 = "Experience curve declared in the database will be used instead."
print(s1 + s2) if METE_ERROR_SHOW
@exp_file_error = true
return
end
for i in 0..list.size - 1
delflag = false
for j in 0..list[i].size - 1
if list[i][j] != 10 && list[i][j] != 32 &&
!(list[i][j] >= 48 && list[i][j] <= 57)
delflag = true
end
end
if list[i].size == 1 && list[i][0] == 10
delflag = true
end
if delflag
lines_to_delete.push(list[i])
end
end
if lines_to_delete != []
for i in 0..lines_to_delete.size - 1
list.delete(lines_to_delete[i])
end
end
for i in 0..list.size - 1
while list[i].include?(32)
list[i].slice!(0)
end
end
return list
end
#--------------------------------------------------------------------------
# * Correct the new experience table
#--------------------------------------------------------------------------
def correct_erroneous_data(list)
warnings = ""
wrong_exp = false
if list[0] != 0
list[0] = 0
s1 = "Warning: " + @name + "'s experience requirement for level 1 "
s2 = "must be zero. Automatically correcting error.\n"
warnings += s1 + s2
end
if list.size < $data_actors[@actor_id].final_level
if list.size >= 2
value = list[list.size - 1] - list[list.size - 2]
for i in list.size..$data_actors[@actor_id].final_level - 1
list[i] = list[i-1] + value
end
else
list = []
for i in 0..$data_actors[@actor_id].final_level - 1
list[i] = i
end
end
s1 = "Warning: Fewer levels than " + @name + "'s maximum level have "
s2 = "been declared. Creating temporary substitute values.\n"
warnings += s1 + s2
end
if list.size > $data_actors[@actor_id].final_level
new_list = []
for i in 0..$data_actors[@actor_id].final_level - 1
new_list[i] = list[i]
end
list = new_list
s1 = "Warning: More levels than " + @name + "'s maximum level have "
s2 = "been declared. Ignoring excess declarations.\n"
warnings += s1 + s2
end
for i in 1..list.size - 1
if list[i] <= list[i-1]
if i == list.size - 1 && list.size != 2
diff = list[i-1] - list[i-2]
list[i] = list[i-1] + diff
elsif i == list.size - 1 && list.size == 2
list[i] = 10
else
if list[i+1] > list[i-1]
diff = list[i+1] - list[i-1]
list[i] = list[i-1] + diff / 2
else
list[i] = list[i-1] + 10
end
end
wrong_exp = true
end
end
if wrong_exp
s1 = "Warning: One or more experience requirements for " + @name + " "
s2 = "is less than or equal to the previous level's requirement. "
s3 = "Creating temporary substitute values."
warnings += s1 + s2 + s3
end
if warnings != ""
print(warnings) if METE_ERROR_SHOW
end
return list
end
end
Sample data table
This code is for a character that only has 6 levels. Level 1 starts at 0, Level 6 starts at 23493 and ends at 500000