01-09-2012, 04:21 AM
I came up with something different.
Like Zeriab said, Using a hash to map identifiers in the form of symbols to the various objects much nicer than using an array. But on top of that, you can use a hash array to store MULTIPLE items for reference, like having this:
The above example shows that one item (renamed) holds both a name and a skill cost. This way you can keep all your stats for one skill in just one line.
Be that as it may, I still used the hash idea in the code I'm supplying. If I'm right (usually am ^_- ), you wanted to keep track of spellpoints, spellbonuses and free points for each actor. I hope I'm right. If that's the case, you wouldn't be using a Game_SkillPoints class. There would be no need.
Had to pass the @actor around the script so it knew which actor's data is being used.
With this, you can add points to a single actor's bonus points by this:
As such, $game_actors[5].modpoint(2,4) would add 4 points to the 'Hacking' skill for actor #5 in your database. The same thing goes for the modboost method you created.
And to start it, you can use this:
Where the actor_index is the position your guy has in the menu. By default, it is set to 0 for the game player's lead position.
With this, it returns a @skill value matching the index of your SKILLNAME array so you know which one it's messing with.
Oh, I still don't program VX.
Like Zeriab said, Using a hash to map identifiers in the form of symbols to the various objects much nicer than using an array. But on top of that, you can use a hash array to store MULTIPLE items for reference, like having this:
Code:
SKILL_ITEM = {}
#SKILL_ITEM[id] = ["skill name", cost]
SKILL_ITEM[0] = ["Alchemy", 14]
SKILL_ITEM[1] = ["Thaumatology", 23]
The above example shows that one item (renamed) holds both a name and a skill cost. This way you can keep all your stats for one skill in just one line.
Be that as it may, I still used the hash idea in the code I'm supplying. If I'm right (usually am ^_- ), you wanted to keep track of spellpoints, spellbonuses and free points for each actor. I hope I'm right. If that's the case, you wouldn't be using a Game_SkillPoints class. There would be no need.
The Code
Code:
#===============================================================================
# ■ Character Skills
# Version 0.00
#-------------------------------------------------------------------------------
# Author: Tenseiten/Tensei/Kirotan/Tohsaka
# Last Updated: 2012/01/06 JST
#===============================================================================
module Tenseiten
#============================================================================
# * Interchange Module
#----------------------------------------------------------------------------
# Allows other scripts using the Tenseinten module to share components with
# this script. This script must be placed before other interchange compliant
# scripts bearing the Tenseinten module.
#============================================================================
module INTERCHANGE
USINGSKILLS = true
end
module SKILLS
# BEGIN CONFIG
LEVELGAIN = 5 # Base Value for Points per Level
TEST = "A test"
SKILLNAME = {}
SKILLNAME[0] = "Alchemy"
SKILLNAME[1] = "Thaumatology"
SKILLNAME[2] = "Hacking"
SKILLNAME[3] = "Yanderehood"
SKILLNAME[4] = "Art"
SKILLNAME[5] = "Scripting"
SKILLNAME[6] = "Cooking"
SKILLNAME[7] = "Trolling"
SKILLNAME[8] = "Testing"
SKILLNAME[9] = "Double Rainbow"
SKILLNAME[10] = "All the way"
SKILLNAME[11] = "Across the sun"
SKILLNAME[12] = "What does it mean?"
# END CONFIG
end # End Skills
end # End Tenseinten
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :skillpoint # for cursor memory: Skill
attr_accessor :skillboost # for cursor memory: Skill
attr_accessor :freepoints # for cursor memory: Skill
#--------------------------------------------------------------------------
# * Object Initialization
# actor_id : actor ID
#--------------------------------------------------------------------------
alias skillpoints_initialize initialize
def initialize(actor_id)
skillpoints_initialize(actor_id)
@skillpoint = {}
@skillboost = {}
@freepoints = 0
for iter in 0...Tenseiten::SKILLS::SKILLNAME.size
@skillpoint[iter] = 0
@skillboost[iter] = 0
end
end
#--------------------------------------------------------------------------
# * Modify Skill Point
# id : id of the Skill
# value : value of adjustment
#--------------------------------------------------------------------------
def modpoint(id, value)
@skillpoint[id] += value
end
#--------------------------------------------------------------------------
# * Modify Skill Boost
# id : id of the Skill
# value : value of adjustment
#--------------------------------------------------------------------------
def modboost(id, value)
@skillboost[id] += value
end
end
#==============================================================================
# ** Window_SkillComponents
#------------------------------------------------------------------------------
# Displays the header window
#==============================================================================
class Window_SkillComponents < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 397, 54)
end
#--------------------------------------------------------------------------
# * Set Text
# text : character string displayed in window
# align : alignment (0..flush left, 1..center, 2..flush right)
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(-1, -2, 144, 24, 'Skills')
end
end
#==============================================================================
# ** Window_SkillFree
#------------------------------------------------------------------------------
# Displays the header window
#==============================================================================
class Window_SkillFree < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize(actor)
super(397, 0, 148, 54)
@actor = actor
refresh
end
#--------------------------------------------------------------------------
# * Display the Free Skill Points
#--------------------------------------------------------------------------
def display_free_points
pointhack = @actor.freepoints
return "%03d" % pointhack
end
#--------------------------------------------------------------------------
# * Set Text
# text : character string displayed in window
# align : alignment (0..flush left, 1..center, 2..flush right)
#--------------------------------------------------------------------------
def refresh
self.contents.clear
fsize = self.contents.font.size
self.contents.font.size = 15
self.contents.draw_text(4, -5, 264, 24, 'Free Points')
self.contents.font.size = 20
self.contents.draw_text(80, 2, 264, 24, display_free_points)
self.contents.font.size = fsize
end
end
#==============================================================================
# ** Window_SkillSelections
#------------------------------------------------------------------------------
# Displays the main window
#==============================================================================
class Window_SkillSelections < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize(actor)
super(0, 55, 544, 362)
@actor = actor
refresh
end
#--------------------------------------------------------------------------
# * Get Skill
#--------------------------------------------------------------------------
def skill
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
@data = []
for item in 0...Tenseiten::SKILLS::SKILLNAME.size
@data.push(item)
end
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
# Format Rectangles
rect1 = item_rect(index)
rect2 = item_rect(index, 256, 80)
rect3 = item_rect(index, 336, 80)
rect4 = item_rect(index, 416, 90)
self.contents.clear_rect(rect1)
self.contents.clear_rect(rect2)
self.contents.clear_rect(rect3)
self.contents.clear_rect(rect4)
item = @data[index]
if item != nil
# Get the data
skill_name = Tenseiten::SKILLS::SKILLNAME[item]
skill_point = @actor.skillpoint[item]
skill_boost = @actor.skillboost[item]
skill_boost = 121 if item == 3
skill_total = skill_point + skill_boost
# Draw in rectangles
self.contents.draw_text(rect1, skill_name)
self.contents.draw_text(rect2, skill_point, 2)
self.contents.draw_text(rect3, skill_boost, 2)
self.contents.draw_text(rect4, skill_total, 2)
end
end
#--------------------------------------------------------------------------
# * Get rectangle for displaying items
# index : item number
#--------------------------------------------------------------------------
def item_rect(index, left=0, width=0)
rect = Rect.new(0, 0, 0, 0)
rect.width = (contents.width + @spacing) / @column_max - @spacing
rect.height = WLH
rect.x = index % @column_max * (rect.width + @spacing)
rect.x += left if left != 0
rect.width -= left if left != 0
rect.width = width if width != 0
rect.y = index / @column_max * WLH
return rect
end
end
#==============================================================================
# ** Scene_CharSkills
#------------------------------------------------------------------------------
# This class performs bonus skill screen processing.
#==============================================================================
class Scene_CharSkills < Scene_Base
#--------------------------------------------------------------------------
# * Object Initialization
# actor_index : actor index
#--------------------------------------------------------------------------
def initialize(actor_index = 0)
@actor_index = actor_index
end
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
super
create_menu_background
@actor = $game_party.members[@actor_index]
@viewport = Viewport.new(0, 0, 544, 416)
create_title_window(@viewport)
create_counter_window(@viewport)
create_skill_window(@viewport)
end
#--------------------------------------------------------------------------
# * Create the Title Window
# viewport : viewport
#--------------------------------------------------------------------------
def create_title_window(viewport)
@title_window = Window_SkillComponents.new
@title_window.viewport = @viewport
end
#--------------------------------------------------------------------------
# * Create the Counter Window
# viewport : viewport
#--------------------------------------------------------------------------
def create_counter_window(viewport)
@counter_window = Window_SkillFree.new(@actor)
@counter_window.viewport = @viewport
end
#--------------------------------------------------------------------------
# * Create the Skill Window
# viewport : viewport
#--------------------------------------------------------------------------
def create_skill_window(viewport)
@skill_window = Window_SkillSelections.new(@actor)
@skill_window.viewport = @viewport
@skill_window.index = 0
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@counter_window.dispose
@title_window.dispose
@skill_window.dispose
end
#--------------------------------------------------------------------------
# * Return to Original Screen
#--------------------------------------------------------------------------
def return_scene
# $scene = Scene_Menu.new(1)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
update_menu_background
@title_window.update
@counter_window.update
@skill_window.update
update_skill_selection
end
#--------------------------------------------------------------------------
# * Update Skill Selection
#--------------------------------------------------------------------------
def update_skill_selection
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
elsif Input.trigger?(Input::C)
@skill = @skill_window.skill
p @skill
end
end
end
Had to pass the @actor around the script so it knew which actor's data is being used.
With this, you can add points to a single actor's bonus points by this:
Code:
$game_actors[actor_id].modpoint( skill_id, value)
And to start it, you can use this:
Code:
$game_temp.next_scene = nil
$scene = Scene_CharSkills.new(actor_index)
With this, it returns a @skill value matching the index of your SKILLNAME array so you know which one it's messing with.
Oh, I still don't program VX.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Above are clickable links