09-17-2009, 09:09 AM
Quick And Easy Skill Shop Version: 1.0
By: LegacyX
By: LegacyX
Introduction
This script enables you to have a shop you can buy/learn skills from.
Features
- Learn Skills
- Individual Hero Skills
- Learn Skills On Level
Screenshots
none yet sorry.
Script
Skill Shop Script (RMXP)
Code:
#==============================================================================
# ** Quick and Easy Skill Shop
#------------------------------------------------------------------------------
# Author: LegacyX
# Version: 1.0
# Build Date: 26.02.09
#------------------------------------------------------------------------------
=begin
=============================
* Info:
=============================
After seeing Sephirothspawn's Skill Shop script i decided to make my own....so here it is,
i will try to comment this script alot for Newbs but it isn't hard to figure out what goes where.
==============================
* How to Use:
==============================
You will need to call "$skill_shop =[i]" i = ID of skill...you must call the code for it to work!.
You will also need to call "$scene = Scene_Skill_Shop.new" to open up the Skill shop main window.
===============================
* Example:
===============================
$skill_shop = [1,2,3,6,7]
$scene = Scene_Skill_Shop.new
To set the text that appears in the Skill shop main windows Find "# Skill Shop Config
You can set Skill Price under "# Price Data".
You can allow skills to be learnt by individual heros by finding "# Skill data".
This is the layout:
[ID of skill, Level requirement for learn]
==============================
* Special Thanks & Credits:
==============================
Sephirothspawn: For all the coding help and the Skill Shop script which inspired me
to make my own.
=end
#===================================================
# ^ Module SkillShop_Config Begins
#===================================================
module Skill_Shop
# Skill Shop Config
#Edit here
Shop_Message = "Welcome how can i help?"
How_Learn = "Who would you like to teach?" #Text shown above Characters in shop window
Can_Learn = "Learn!" #Text shown when a hearo can learn the skill
Can_Learn_Lv = "Learn on Lv" #text shown when a hero CAN learn the skill
Cant_Learn = "Unable to learn" #Text shown if a hero is unable to learn that perticular skill
Learnt = "Learned!" #text shown when a hero has learnt a skill
Teach = "Teach!" #Command (Buy in normal shops)
Cancel = "Exit" #Command (Cancel in normal shops)
# Add Prices Here
PRICE = {
0 => 100, #Defualt price for skills with no price set
1 => 150, #Price for Skill ID 1
2 => 550,
3 => 450,
}
# Skill Data
# add the skills that each individual hero can learn.
#Layout is mentioned above.
SKILL_BUY = {
1 => [
[1,4],[2,3],[3,1],[7,1],
],
2 => [
[1,4],[2,3],[3,1],[7,5],
],
3 => [
[1,4],[2,3],[3,1],[7,5],
],
}
# Add Price
def self.skill_price(id)
if PRICE.include?(id)
return PRICE[id]
else
return PRICE[0]
end
end
# Add Hero id
def self.skill_buy(id)
if SKILL_BUY.include?(id)
return SKILL_BUY[id]
else
return []
end
end
end
#==============================================================================
# ** Class Game_Actor
#------------------------------------------------------------------------------
# This class handles the actor array. Refer to "$game_actors" for each
# instance of this class.
#==============================================================================
class Game_Actor < Game_Battler
def learn?(skill)
learn = skill_learn?(skill.id)
if learn
return false
else
return true
end
end
end
#==============================================================================
#class Window_Skill_ShopCommand
#==============================================================================
class Window_Skill_ShopCommand < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 64, 480, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Tahoma"
self.contents.font.size = 21
@item_max = 2
@column_max = 2
#Commands Setup... if you wish to add more commands edit here.
s1 = Skill_Shop::Teach
s2 = Skill_Shop::Cancel
@commands = [s1, s2]
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
def draw_item(index)
x = 4 + index * 240
self.contents.draw_text(x, 0, 128, 32, @commands[index])
end
end
#==============================================================================
#class Window_Skill_ShopBuy
#==============================================================================
class Window_Skill_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(shop_goods)
super(0, 128, 368, 352)
@skill_shop_goods = $skill_shop
refresh
self.index = 0
end
#--------------------------------------------------------------------------
def skill
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 0...@skill_shop_goods.size
skill = $data_skills[@skill_shop_goods[i]]
if skill != nil
@data.push(skill)
end
end
# If the number of items is not 0, it draws up bit map, drawing all item
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.name = "Tahoma"
self.contents.font.size = 21
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
def draw_item(index)
skill = @data[index]
# Acquiring the frequency of possession of the item
price = Skill_Shop.skill_price(skill.id)
enabled = (price <= $game_party.gold)
#Price colour handling
if enabled
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 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, 212, 32, skill.name, 0)
self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
end
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(skill == nil ? "" : skill.description)
end
end
#==============================================================================
#class Window_Skill_ShopStatus
#==============================================================================
class Window_Skill_ShopStatus < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(368, 128, 272, 352)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Tahoma"
self.contents.font.size = 21
@item = nil
refresh
self.active = false
self.index = -1
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@item_max = $game_party.actors.size
if @item == nil
return
end
self.contents.font.color = system_color
self.contents.draw_text(4, 0, self.width - 32, 32, Skill_Shop::How_Learn)
self.contents.font.color = normal_color
# Equipment supplementary information
for i in 0...$game_party.actors.size
# Acquiring the actor
can = false
lv = false
ac_lv = 0
actor = $game_party.actors[i]
can_learn = Skill_Shop.skill_buy(actor.id)
id = @item.id
for e in 0...can_learn.size
if can_learn[e][0] == id
can = true
if can_learn[e][1] <= actor.level
lv = true
else
lv = false
ac_lv = can_learn[e][1]
end
break
else
can = false
end
end
enabled = (can and lv and actor.learn?(@item))
# If equipment possibility if usually in letter color, else it sets to invalid letter color
if enabled
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
#Draw Character Pic
bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
cw = bitmap.rect.width / 4
ch = bitmap.rect.height / 4
src_rect = Rect.new(0, 0, cw, ch)
cx = contents.text_size(actor.name).width
self.contents.blt(cx, 64 + 64 * i, bitmap, src_rect)
# Drawing the name of the actor
self.contents.draw_text(4, 64 + 64 * i, 120, 32, actor.name)
# Check Skill
if can == false
text = Skill_Shop::Cant_Learn
elsif can == true and lv == false
ac = ac_lv.to_s
text = Skill_Shop::Can_Learn_Lv + " " + ac + "+"
elsif actor.learn?(@item) == false
text = Skill_Shop::Learnt
else
text = Skill_Shop::Can_Learn
end
# Drawing the item
self.contents.draw_text(124, 64 + 64 * i, 112, 32, text, 2)
end
end
#--------------------------------------------------------------------------
def item=(item)
if @item != item
@item = item
refresh
end
end
#--------------------------------------------------------------------------
def update_cursor_rect
# Cursor position as for -1 all selection, -2 below independence selection (user himself)
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(0, 62 + @index * 64, self.width - 32, 50)
end
end
end
#==============================================================================
#class Scene_Skill_Shop
#==============================================================================
#
#
#-----I advise you not to touch anything past here unless you know what you are doing.-------
#
#
class Scene_Skill_Shop
#--------------------------------------------------------------------------
def main
# Drawing up the help window
@help_window = Window_Help.new
# Drawing up the command window
@command_window = Window_Skill_ShopCommand.new
# Drawing up the Goldwyn dough
@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 64
# Drawing up the dummy window
@dummy_window = Window_Base.new(0, 128, 640, 352)
# Drawing up the purchase window
@buy_window = Window_Skill_ShopBuy.new($game_temp.shop_goods)
@buy_window.active = false
@buy_window.visible = false
@buy_window.help_window = @help_window
# Drawing up the status window
@status_window = Window_Skill_ShopStatus.new
@status_window.visible = false
@status_window.active
# Transition execution
Graphics.transition
# Main loop
loop do
# Renewing the game picture
Graphics.update
# Updating the information of input
Input.update
# Frame renewal
update
# When the picture changes, discontinuing the loop
if $scene != self
break
end
end
# Transition preparation
Graphics.freeze
# Releasing the window
@help_window.dispose
@command_window.dispose
@gold_window.dispose
@dummy_window.dispose
@buy_window.dispose
@status_window.dispose
end
#--------------------------------------------------------------------------
def update
# Renewing the window
@help_window.update
@command_window.update
@gold_window.update
@dummy_window.update
@buy_window.update
@status_window.update
# When the command window is active,: Update_command is called
if @command_window.active
update_command
return
end
# When the purchase window is active,: Update_buy is called
if @buy_window.active
update_buy
return
end
# When the target window is active,: Update_target is called
if @status_window.active
update_target
return
end
end
#--------------------------------------------------------------------------
def update_command
# The B when button is pushed
if Input.trigger?(Input::B)
# Performing cancellation SE
$game_system.se_play($data_system.cancel_se)
# Change to map picture
$scene = Scene_Map.new
return
end
# When C button is pushed
if Input.trigger?(Input::C)
# Eliminating the help text
@help_window.set_text("")
# It diverges at cursor position of the command window
case @command_window.index
when 0 # It purchases
# Performing decision SE
$game_system.se_play($data_system.decision_se)
# State of window to purchase mode
@command_window.active = false
@dummy_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@buy_window.refresh
@status_window.visible = true
when 1 # It stops
# Performing decision SE
$game_system.se_play($data_system.decision_se)
# Change to map picture
$scene = Scene_Map.new
end
return
end
end
#--------------------------------------------------------------------------
def update_buy
# Setting the item of the status window
@status_window.item = @buy_window.skill
# The B when button is pushed
if Input.trigger?(Input::B)
# Performing cancellation SE
$game_system.se_play($data_system.cancel_se)
# State of window to early mode
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
# Eliminating the help text
@help_window.set_text("")
return
end
# When C button is pushed
if Input.trigger?(Input::C)
# Acquiring the item
@item = @buy_window.skill
@price = Skill_Shop.skill_price(@item.id)
enabled = (@price <= $game_party.gold)
# When the item is invalid, or when price it is on from the money in hand
unless enabled
# Performing buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Performing decision SE
$game_system.se_play($data_system.decision_se)
@buy_window.active = false
@status_window.active = true
@status_window.index = 0
end
end
#--------------------------------------------------------------------------
def update_target
# The B when button is pushed
if Input.trigger?(Input::B)
# Performing cancellation SE
$game_system.se_play($data_system.cancel_se)
# Eliminating the target window
@buy_window.active = true
@status_window.index =- 1
@status_window.active = false
return
end
# When C button is pushed
if Input.trigger?(Input::C)
@actor = $game_party.actors[@status_window.index]
can = false
lv = false
can_learn = Skill_Shop.skill_buy(@actor.id)
id = @item.id
for i in 0...can_learn.size
if can_learn[i][0] == id
can = true
if can_learn[i][1] <= @actor.level
lv = true
else
lv = false
end
break
else
can = false
end
end
enabled = (can and lv and @actor.learn?(@item))
# When with SP and so on is cut off and it becomes not be able to use
unless enabled
# Performing buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Performing shop SE
$game_system.se_play($data_system.shop_se)
@actor.learn_skill(@item.id)
$game_party.lose_gold(@price)
@buy_window.refresh
@gold_window.refresh
@status_window.refresh
@buy_window.active = true
@status_window.index =- 1
@status_window.active = false
end
end
end
Instructions
Place above MAin and Below Scene_Debug, futher intructions in code.
Use $scene = Scene_Skill_Shop.new to call Skill Shop window
(if there any problems Just ask.)
Compatibility
Cannot be used with RMVX yet.
Credits and Thanks
Sephirothspawn: For all the coding help you have given me. And for your Skill Shop script which has inspired me
to make my own.
Author's Notes
I will be making the script compatible with the SDK soon.. that will be version 1.1
and i will be also trying to make it compatible with RMVX.
Terms and Conditions
No limits....but i would like some credit if you use this script in your game.