Learn Skill - Caldaron - 10-09-2006
Learn Skill
by Caldaron
Version: 1.05
Oct 9 2006
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Introduction
This Script allows u to choose skills for actors to learn. It adds autmatically exp to the skill, so that u only have to choose and wait, until the skill is learned...
Features- Actors need learn points to learn skills (can be switched off)
- Popup message, when skill is learned
- Reset to last saved Learn-Skill and EXP without losses
- Set Learnpoints/EXP needed for every Skill
Script
Code: #==============================================================================
# Learn Skill Script v. 1.05
# by Caldaron (6.10.2006)
#==============================================================================
SDK.log('Learn Skill', 'Caldaron', 1.05, '2006-10-6')
if SDK.state('Learn Skill')
#==============================================================================
module Learn
#--------------------------------------------------------------
Points = true # disable learn_points
Learn_EXP = {1 => 100} # skill.id => skill.exp
Learn_Points = {1 => 10} # skill.id => skill.learn_points
#--------------------------------------------------------------
end
#==============================================================================
class Scene_Learn
#--------------------------------------------------------------
def initialize(actor_index = 0)
@actor_index = actor_index
end
#--------------------------------------------------------------
def main
@actor = $game_party.actors[@actor_index]
@actor_window = Window_Learn_Actor.new(@actor)
@actual_window = Window_Learn_Actual.new(@actor)
@list_window = Window_Learn_List.new(@actor)
@help_window = Window_Help.new
@list_window.help_window = @help_window
@warning_window = Window_Help.new
@warning_window.set_text("XP will be lost, learn anyhow?", 1)
@confirm_window = Window_Command.new(144,["Yes", "No"])
@exit_window = Window_Command.new(144,["Yes", "Cancel", "Reset"])
@actor_window.visible = true
@actual_window.visible = true
@list_window.visible = true
@list_window.help_window.visible = true
@warning_window.visible = false
@confirm_window.visible = false
@list_window.active = true
@confirm_window.active = false
@exit_window.visible = false
@exit_window.active = false
if @actor.learn_current != nil
@current = $data_skills[@actor.learn_current]
else
@current = nil
end
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.lp_consume == nil
actor.lp_consume = 0
end
end
@list_window.help_window.y = 416
@warning_window.y = 160
@warning_window.z = 200
@confirm_window.x = 248
@confirm_window.y = 224
@confirm_window.z = 200
@confirm_window.index = 1
@exit_window.x = 248
@exit_window.y = 224
@exit_window.z = 200
@exit_window.index = 1
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@actor_window.dispose
@actual_window.dispose
@list_window.dispose
@help_window.dispose
@warning_window.dispose
@confirm_window.dispose
@exit_window.dispose
end
#--------------------------------------------------------------
def update
@actor_window.update
@actual_window.update
@list_window.update
@help_window.update
@warning_window.update
@confirm_window.update
@exit_window.update
if @list_window.active
update_list
return
end
if @confirm_window.active
update_confirm
end
if @exit_window.active
update_exit
end
end
#--------------------------------------------------------------
def update_list
if Input.trigger?(Input::B)
@show_description = false
@a = Learn::Points ? @actor.learn_exp != 0 ? false : true : false
if (@actor.lp_consume != 0 and @actor.start != @actor.learn_current and @actor.start != nil and @a)
@list_window.active = false
@warning_window.set_text("Accept Changes?", 1)
@warning_window.visible = true
@exit_window.visible = true
@exit_window.active = true
else
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(4)
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.start != actor.learn_current
actor.learn_points -= actor.lp_consume
end
actor.lp_consume = 0
end
end
end
if Input.trigger?(Input::C)
@skill = @list_window.skill
if @skill != nil
if points(@skill) > @a = Learn::Points ? @actor.learn_points : points(@skill)
$game_system.se_play($data_system.buzzer_se)
return
else
$game_system.se_play($data_system.decision_se)
if @actor.learn_current != nil and @actor.learn_exp > 0 and @actor.lp_consume == 0
@list_window.active = false
@warning_window.visible = true
@confirm_window.visible = true
@confirm_window.active = true
return
else
if @current != nil
@actor.learn_list.push(@current.id)
end
@actor.learn_current = @skill.id
if @actor.learn_current == @actor.start
backup
else
@actor.learn_exp = 0
@actor.lp_consume = points(@skill)
end
$scene = Scene_Learn.new(@actor_index)
end
end
else
$game_system.se_play($data_system.buzzer_se)
return
end
end
if Input.trigger?(Input::R)
$game_system.se_play($data_system.cursor_se)
@actor_index += 1
@actor_index %= $game_party.actors.size
$scene = Scene_Learn.new(@actor_index)
return
end
if Input.trigger?(Input::L)
$game_system.se_play($data_system.cursor_se)
@actor_index += $game_party.actors.size - 1
@actor_index %= $game_party.actors.size
$scene = Scene_Learn.new(@actor_index)
return
end
end
#--------------------------------------------------------------
def update_confirm
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@warning_window.visible = false
@confirm_window.visible = false
@confirm_window.active = false
@list_window.active = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
case @confirm_window.index
when 0
if @current != nil
@actor.learn_list.push(@current.id)
end
@actor.learn_current = @skill.id
if @actor.learn_current == @actor.start
backup
else
@actor.learn_exp = 0
@actor.lp_consume = points(@skill)
end
$scene = Scene_Learn.new(@actor_index)
when 1
@warning_window.visible = false
@confirm_window.visible = false
@confirm_window.active = false
@list_window.active = true
return
end
end
end
#--------------------------------------------------------------
def update_exit
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@warning_window.visible = false
@exit_window.visible = false
@exit_window.active = false
@list_window.active = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
case @exit_window.index
when 0
$scene = Scene_Menu.new(4)
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.lp_consume == nil
actor.lp_consume = 0
end
actor.learn_points -= actor.lp_consume
actor.lp_consume = 0
end
when 1
@warning_window.set_text("XP will be lost, learn anyhow?", 1)
@warning_window.visible = false
@exit_window.visible = false
@exit_window.active = false
@list_window.active = true
return
when 2
backup
$scene = Scene_Learn.new(@actor_index)
end
end
end
#--------------------------------------------------------------
def backup
@actor.learn_points = @actor.start_points
@actor.learn_current = @actor.start
@actor.learn_list = @actor.start_list
@actor.learn_exp = @actor.start_exp
@actor.learn_exp_need = @actor.start_exp_need
@actor.learned_list = @actor.start_learned_list
@actor.lp_consume = 0
return
end
#--------------------------------------------------------------
def points(skill)
if Learn::Points
if Learn::Learn_Points.has_key?(skill.id)
return Learn::Learn_Points[skill.id]
else
return [[Integer(skill.sp_cost / 20), 0].max, 999].min
end
else
return exp(skill)
end
end
#--------------------------------------------------------------------------
def exp(skill)
if Learn::Learn_EXP.has_key?(skill.id)
return Learn::Learn_EXP[skill.id]
else
return [[Integer(skill.sp_cost / 3), 1].max, 999999].min
end
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Window_Learn < Window_Base
#--------------------------------------------------------------------------
attr_accessor :actor_id
attr_accessor :skill_id
#--------------------------------------------------------------------------
def initialize(actor_id, skill_id = 1)
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.back_opacity = 128
@actor_id = actor_id
@skill_id = skill_id
refresh
end
#--------------------------------------------------------------------------
def refresh
@actor = $game_party.actors[@actor_id]
@name = @actor.name
@skill = $data_skills[@skill_id]
@skill = @skill.name
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(0, 0, 608, 32, "#{@name.to_s} has learned #{@skill.to_s}!", 1)
end
#--------------------------------------------------------------------------
def update
super
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Window_Learn_Actor < Window_Base
#--------------------------------------------------------------------------
def initialize(actor)
super(0,0,640/3,96)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
@actor = actor
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_actor_name(@actor, 0, 0)
draw_actor_learn_level(@actor, 112, 0)
if Learn::Points
self.contents.draw_text(0, 32, 96, 32, "Learnpoints:")
self.contents.draw_text(108, 32, 72, 32, @actor.learn_points.to_s, 1)
end
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Window_Learn_Actual < Window_Base
#--------------------------------------------------------------------------
def initialize(actor)
super(640/3, 0, 640*2/3, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
@actor = actor
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.draw_text(0, 0, 640*2/3-32, 32, "Learns :",0)
if @actor.learn_current != nil
@current = $data_skills[@actor.learn_current]
if Learn::Learn_EXP.has_key?(@current.id)
@actor.learn_exp_need = Learn::Learn_EXP[@current.id]
else
@actor.learn_exp_need = [[Integer(@current.sp_cost / 3), 1].max, 999999].min
end
draw_actor_learn_current_bar(@actor, 0, 32, 640*2/3-32)
bitmap = RPG::Cache.icon(@current.icon_name)
self.contents.blt(132, 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(164, 0, 204, 32, @current.name, 0)
else
self.contents.draw_text(0, 32, 640*2/3-32, 32, "Nothing",1)
end
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Window_Learn_List < Window_Selectable
#--------------------------------------------------------------------------
def initialize(actor)
super(0, 96, 640, 320)
@actor = actor
@column_max = 2
refresh
self.index = 0
end
#--------------------------------------------------------------------------
def skill
return @data[self.index]
end
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
@actor.learn_list.sort!
if @actor.learn_current != nil
current = $data_skills[@actor.learn_current]
else
current = nil
end
for i in 0...@actor.learn_list.size
skill = $data_skills[@actor.learn_list[i]]
if skill != nil and not @data.include?(skill) and not @actor.learned_list.include?(skill.id)
@data.push(skill)
end
@data.delete(current)
end
for i in 0...@actor.skills.size
skill = $data_skills[@actor.skills[i]]
@data.delete(skill)
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
def draw_item(index)
skill = @data[index]
if Learn::Points
if Learn::Learn_Points.has_key?(skill.id)
@lp_cost = Learn::Learn_Points[skill.id]
else
@lp_cost = [[Integer(skill.sp_cost / 20), 0].max, 999].min
end
else
if Learn::Learn_EXP.has_key?(skill.id)
@lp_cost = Learn::Learn_EXP[skill.id]
else
@lp_cost = [[Integer(skill.sp_cost / 3), 1].max, 999999].min
end
end
self.contents.font.color = normal_color
if Learn::Points
if @lp_cost <= @actor.learn_points
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(skill.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
self.contents.draw_text(x + 232, y, 48, 32, @lp_cost.to_s, 2)
end
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.skill == nil ? "" : self.skill.description)
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Window_Base
def draw_actor_learn_level(actor, x, y)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 32, 32, "LV")
self.contents.font.color = normal_color
self.contents.draw_text(x + 32, y, 24, 32, actor.level.to_s, 1)
end
#--------------------------------------------------------------------------
def draw_actor_learn_current_bar(actor, x, y, width = 172)
if actor.learn_exp_need != 0
rate = actor.learn_exp.to_f / actor.learn_exp_need
else
rate = 1
end
plus_x = 0
rate_x = 0
plus_y = 25
plus_width = 0
rate_width = 100
height = 20
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.learn_exp_need != 0
exp = (width + plus_width) * actor.learn_exp * rate_width / 100 / actor.learn_exp_need
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)
aw = self.contents.text_size(actor.learn_exp.to_s).width
bw = self.contents.text_size(actor.learn_exp_need.to_s).width
self.contents.draw_text(width/2 - aw - 4, y, aw, 32, actor.learn_exp.to_s, 2)
self.contents.font.color = normal_color
self.contents.draw_text(width/2, y, 12, 32, "/", 1)
self.contents.draw_text(width/2 + 16, y, bw, 32, actor.learn_exp_need.to_s, 0)
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
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
attr_accessor :learn_points
attr_accessor :learn_current
attr_accessor :learn_list
attr_accessor :learn_exp
attr_accessor :learn_exp_need
attr_accessor :learned_list
attr_accessor :lp_consume
attr_accessor :start
attr_accessor :start_points
attr_accessor :start_list
attr_accessor :start_exp
attr_accessor :start_exp_need
attr_accessor :start_learned_list
#--------------------------------------------------------------------------
alias caldaron_learn_actor_init initialize
def initialize(actor_id)
@learn_points = 0
@learn_current = nil
@learn_list = []
@learn_exp = 0
@learn_exp_need = 0
@learned_list = []
@lp_consume = 0
@start = nil
@start_points = 0
@start_list = []
@start_exp = 0
@start_exp_need = 0
@start_learned_list = []
caldaron_learn_actor_init(actor_id)
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
alias caldaron_learn_map_main main
def main
@learn_window = []
for i in 0...$game_party.actors.size
@learn_window.push(Window_Learn.new(i))
@learn_window[i].visible = false
end
@wait = 0
caldaron_learn_map_main
for i in 0...$game_party.actors.size
@learn_window[i].dispose
end
end
#--------------------------------------------------------------------------
alias caldaron_learn_map_update update
def update
if @wait > 0
@wait -= 1
end
if @wait == 0
for i in 0...$game_party.actors.size
@learn_window[i].visible = false
end
end
@i = -1
for i in 0...$game_party.actors.size
@actor = $game_party.actors[i]
if @actor.learn_current != nil and @actor.learn_exp >= @actor.learn_exp_need
@learn_window[i].skill_id = @actor.learn_current
@learn_window[i].refresh
@learn_window[i].visible = true
@actor.learn_exp = 0
@actor.learn_skill(@actor.learn_current)
@actor.learned_list.push(@actor.learn_current)
@actor.learn_current = nil
@wait = 100
end
if @learn_window[i].visible
@i += 1
if @i > 0
@learn_window[i].y = 64 * @i
end
end
end
caldaron_learn_map_update
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
alias caldaron_learn_battle_start_phase5 start_phase5
def start_phase5
caldaron_learn_battle_start_phase5
exp = 0
for enemy in $game_troop.enemies
unless enemy.hidden
exp += enemy.exp
end
end
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.cant_get_exp? == false
actor.learn_exp += exp
end
end
end
#--------------------------------------------------------------------------
end
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
def call_learn
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
actor.start = actor.learn_current
actor.start_exp = actor.learn_exp
actor.start_exp_need = actor.learn_exp_need
actor.start_points = actor.learn_points
actor.start_list = actor.learn_list
actor.start_learned_list = actor.learned_list
actor.lp_consume = 0
end
$scene = Scene_Learn.new
end
#--------------------------------------------------------------------------
def command_315
value = operate_value(@parameters[1], @parameters[2], @parameters[3])
iterate_actor(@parameters[0]) do |actor|
actor.exp += value
actor.learn_exp += value
end
return true
end
#--------------------------------------------------------------------------
def add_learn_points(actor_id, n)
if actor_id.is_a?(Array)
for i in 0...actor_id.size
$game_party.actors[i].learn_points += n
end
else
$game_party.actors[actor_id].learn_points += n
end
end
#--------------------------------------------------------------------------
def add_learn_skill(actor_id, skill_id)
if actor_id.is_a?(Array)
for i in 0...actor_id.size
if skill_id.is_a?(Array)
for j in 0...skill_id.size
skill = $data_skills[skill_id[j]].id
$game_party.actors[i].learn_list.push(skill)
end
else
$game_party.actors[i].learn_list.push(skill_id)
end
end
else
if skill_id.is_a?(Array)
for j in 0...skill_id.size
skill = $data_skills[skill_id[j]].id
$game_party.actors[actor_id].learn_list.push(skill)
end
else
skill = $data_skills[skill_id]
$game_party.actors[actor_id].learn_list.push(skill_id)
end
end
end
#--------------------------------------------------------------------------
end
#==============================================================================
end
Instructions
Put the Script above Main
For non SDK-Users: Delete Line 5, 7, last line
to push a skill into the learn_list:
Code: add_learn_skill(actor_id, skill_id)
actor_id can be 1 or [1, 2, ...]
skill_id can be 1 or [1, 2, ...]
to add learn_points:
Code: add_learn_points(actor_id, points)
actor_id can be 1 or [1, 2, ...]
To view Scene_Learn, please use
otherwise there will be no backup created
FAQ
I guess there will be some questions...
Incompatibility
Not known...
Credits and Thanks
Credits to me...
Author's Notes
maybe i rewrite some lines of the script, to make it more clearly arranged
|