Hello. I was wondering if an actor's level cap can be changed through a variable. Let's say you want your character to stop levelling at level 10 until he reaches another point in the game, where a switch can be triggered and the character's level cap will increase by changing a max level variable, as opposed to how the current database is set up where a character's level cap remains the way it is on the database. Thank you.
Sure, this is pretty easy. Assuming it's okay for the level cap to be consistent across all characters (like, as long as you don't want Aluxes' cap to be 10 and Basil's to be 15) and if it's okay that the characters don't gain XP and can "jump" to another level once the cap changes, you can just throw this somewhere below the default scripts:
class Game_Battler
#--------------------------------------------------------------------------
# * Determine [Can't Get EXP] States
#--------------------------------------------------------------------------
def cant_get_exp?
for i in @states
if $data_states[i].cant_get_exp
return true
end
end
if level >= $game_variables[REPLACE]
return true
end
return false
end
end
Make sure you replace "REPLACE" with the variable number you want to use as the cap. If one of my previous assumptions is incorrect let me know - I'll make it work however you'd like.
Thank you for the answer ^^ Hm, that is one way to do it, but it would be more interesting without depending on a state for not gaining experience. It is functionally the same I suppose. I was really looking for a way to change the "max level" value in the middle of the game for an actor individually, if possible.
No worries. It's technically not using a status effect/state to not gain experience, it's just using the code where that takes place. I was actually messing around with it and it's also not complete - if the characters gain a large sum of XP at once (enough for more than one level) it can bypass the soft cap (and actually, it would only effect manual level changes, not through gained XP). Of course since you want to change the max level for each character, that's a little different and you should disregard the above code altogether. What you should use is this:
class Game_Actor < Game_Battler
attr_reader :final_level # final level
alias old_setup_soft_cap setup
def setup(actor_id)
old_setup_soft_cap(actor_id)
actor = $data_actors[actor_id]
@final_level = actor.final_level
end
def final_level=(final)
@final_level = final
# automatically adjust level when cap is lifted
self.exp+=0
end
#--------------------------------------------------------------------------
# * Change Level
# level : new level
#--------------------------------------------------------------------------
def level=(level)
# Check up and down limits
level = [[level, @final_level].min, 1].max
# Change EXP
self.exp = @exp_list[level]
end
#--------------------------------------------------------------------------
# * Change EXP
# exp : new EXP
#--------------------------------------------------------------------------
def exp=(exp)
@exp = [[exp, 9999999].min, 0].max
# Level up
while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
break if @level >= @final_level
@level = [@level + 1, @final_level].min
# Learn skill
for j in $data_classes[@class_id].learnings
if j.level == @level
learn_skill(j.skill_id)
end
end
end
# Level down
while @exp < @exp_list[@level]
@level -= 1
end
# Correction if exceeding current max HP and max SP
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
end
You won't be able to use a variable but you can use a script call for $game_actors[ACTOR_ID].final_level = 10, or 20, or whichever. Set it individually for each character, and it defaults to whatever you have in the database. Do you want the characters to continue to gain XP when they're at their cap? Like, if Aluxes has enough XP for level 20, but his cap is 10, should he become level 20 when the cap is raised, or should he only have up to the XP of a level 10 as well?
Once again, thank you very much. I'll test this out and see how it works. What I wanted was, um, if they're at a cap of level 10 (for example), they stop gaining EXP altogether, but changing the cap will once again allow them to gain EXP until they reach the next level cap. Does that make sense? ^^;;;
Gotcha. In that case, this will be the version you'd want to use. Same instructions as the last one, just slightly changed so it won't keep excess EXP.
class Game_Actor < Game_Battler
attr_accessor :final_level # final level
alias old_setup_soft_cap setup
def setup(actor_id)
old_setup_soft_cap(actor_id)
actor = $data_actors[actor_id]
@final_level = actor.final_level
end
#--------------------------------------------------------------------------
# * Change Level
# level : new level
#--------------------------------------------------------------------------
def level=(level)
# Check up and down limits
level = [[level, @final_level].min, 1].max
# Change EXP
self.exp = @exp_list[level]
end
def final_level=(final)
@final_level = final
# automatically adjust level when cap is lifted
self.exp+=0
end
#--------------------------------------------------------------------------
# * Change EXP
# exp : new EXP
#--------------------------------------------------------------------------
def exp=(exp)
return if cant_get_exp?
@exp = [[exp, 9999999].min, 0].max
# Level up
while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
# make sure xp cap is successful
self.level = @final_level if @level >= @final_level
break if @level >= @final_level
@level = [@level + 1, @final_level].min
# Learn skill
for j in $data_classes[@class_id].learnings
if j.level == @level
learn_skill(j.skill_id)
end
end
end
# Level down
while @exp < @exp_list[@level]
@level -= 1
end
# Correction if exceeding current max HP and max SP
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
end
class Game_Battler
#--------------------------------------------------------------------------
# * Determine [Can't Get EXP] States
#--------------------------------------------------------------------------
def cant_get_exp?
for i in @states
if $data_states[i].cant_get_exp
return true
end
end
if level >= @final_level
return true
end
return false
end
end
I tested it out. It works very well thank you!
I did try the reverse by having the default cap at 30 and try to set it upwards to 50, but that didn't really work though. It only works if the cap is set lower than what the default database has, but regardless it is functioning.