[XP] Skill Shop

Started by G_G, June 07, 2009, 06:32:20 am

Previous topic - Next topic

G_G

June 07, 2009, 06:32:20 am Last Edit: February 18, 2013, 01:49:30 pm by KK20
Skill Shop
Authors: game_guy
Version: 2.2
Type: Skill Buying Script
Key Term: Custom Shop System



Introduction

What this script does is act as a shop but sells skills instead that you can teach to your party members.


Features


  • Sells Skills to teach Actors
  • Make it any actor can learn any skill
  • Make skills class specific
  • Easy to configure then most skill shops I've seen
  • Now skills can be level specific
  • Sort skills in 6 different ways



Screenshots

Spoiler: ShowHide





Demo

MediaFire


Script


Spoiler: ShowHide

#===============================================================================
# Skill Shop
# Author: Game_guy
# Date: June 7th, 2009
# Version: 2.2
#===============================================================================
#
# Intro:
# What this script does is act as a shop but sells skills instead.
#
# Instructions:
# 1: First how do you want it setup? Theres two ways
#    1: -Any person can learn any skill
#    or
#    2: -Classes learn different skills then other classes
#
#    Go down to UseClasses and set it to false for 1: or true for 2:
#
# 2: Ok now that thats over lets move onto price. Go down to CONFIG PRICE and
#    follow the instructions there.
#  
# 3: Skip this step if you set UseClasses to false.
#    Go to CONFIG CLASS SKILLS and follow the instructions there.
#    
# 4: Ok so everythings setup now. Time to actually find out how to open the
#    skillshop right? You use this line
#    $scene = SkillShop.new([skill id's go here])
#    example
#    $scene = SkillShop.new([1, 2]) will make a shop with the skills
#    Heal and Great Heal
#
# 5: Ok the script now is able to make it where only skills are learnable at
#    certain levels. Go to CONFIG LEVEL and follow instructions there.
#
# 6: Ok so now there's a new option that sorts the skills in the following.
#    Alphabetical
#    Reverse Alphabetical
#    Numeric (Sorts it by Id)
#    Reverse Numberic
#    Price
#    Reverse price
#    At default its at numeric but to change it use this,
#    $game_system.ssort = 0,1,2, or 3.
#    0 = Numeric, 1 = Reverse Numeric, 2 = Alphabetical,
#    3 = Reverse Alphabetical, 4 = Price, 5 = Reverse Price.
#===============================================================================
module GameGuy
 #==========================
 # BEGIN CONFIG
 #==========================
 UseClasses = true # if false anyone can learn any skill
                    # if true only classes can learn the defined skills
end
module RPG
 class Skill
   def price
     case id
     #==========================
     # CONFIG PRICE
     #==========================
     # use
     # when skill_id then return price
     when 1 then return 50
     when 57 then return 75
     end
     return 10
   end
   def llevel
     case id
     #==========================
     # CONFIG LEVEL
     #==========================
     # use
     # when skill_id then return level
     when 57 then return 2
     end
     return 1
   end
 end
 class Class
   def learnskills
     case id
     #==========================
     # CONFIG CLASS SKILLS
     #==========================
     # use
     # when class_id then return [skill id's here]
     when 1 then return [57, 58, 59, 60]
     when 2 then return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 81]
     when 7 then return [69, 70, 71, 72, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80]
     when 8 then return [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56]
     end
     return []
   end
 #==========================
 # END CONFIG
 #==========================
 end
end
class Game_System
 attr_accessor :ssort
 alias sort_me_skillz initialize
 def initialize
   @ssort = 0
   sort_me_skillz
 end
end
class Window_SkillCommand < Window_Selectable
 def initialize
   super(0, 64, 480, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   @item_max = 2
   @column_max = 2
   @commands = ["Learn", "Exit"]
   refresh
   self.index = 0
 end
 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_SkillBuy < Window_Selectable
 def initialize(shop_goods)
   super(0, 128, 368, 352)
   @skill_shop_goods = shop_goods
   self.active = false
   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 = []
   for i in 0...@skill_shop_goods.size
     skill = $data_skills[@skill_shop_goods[i]]
     if skill != nil
       @data.push(skill)
     end
   end
   case $game_system.ssort
   when 0
     [@data].each {|ary| ary.sort! {|a, b| a.id <=> b.id}}
   when 1
     [@data].each {|ary| ary.sort! {|a, b| a.id <=> b.id}}
     [@data].each {|ary| ary.reverse!}
   when 2
     [@data].each {|ary| ary.sort! {|a, b| a.name <=> b.name}}
   when 3
     [@data].each {|ary| ary.sort! {|a, b| a.name <=> b.name}}
     [@data].each {|ary| ary.reverse!}
   when 4
     [@data].each {|ary| ary.sort! {|a, b| a.price <=> b.price}}
   when 5
     [@data].each {|ary| ary.sort! {|a, b| a.price <=> b.price}}
     [@data].each {|ary| ary.reverse!}
   else
     [@data].each {|ary| ary.sort! {|a, b| a.id <=> b.id}}
   end
   @item_max = @data.size
   if @item_max > 0
     self.contents = Bitmap.new(width - 32, row_max * 32)
     for i in 0...@item_max
       draw_item(i)
     end
   end
 end
 def draw_item(index)
   skill = @data[index]
   price = skill.price
   enabled = (price <= $game_party.gold)
   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_SkillStatus2 < Window_Selectable
 def initialize
   super(368, 128, 272, 352)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
   self.z = 200
   self.active = false
   self.index = -1
 end
 def refresh
   self.contents.clear
   @item_max = $game_party.actors.size
   for i in 0...$game_party.actors.size
     x = 64
     y = i * 80
     actor = $game_party.actors[i]
     classs = $data_classes[$game_actors[actor.id].class_id]
     draw_actor_graphic(actor, x - 40, y + 60)
     draw_actor_name(actor, x - 13, y + 10)
     if actor.skill_learn?($thing.id)
       self.contents.font.color = crisis_color
       $text = "Aquired"
     elsif GameGuy::UseClasses
       if classs.learnskills.include?($thing.id) && $thing.llevel <= actor.level
         self.contents.font.color = normal_color
         $text = "Can Learn"
       elsif classs.learnskills.include?($thing.id) && $thing.llevel > actor.level
         self.contents.font.color = disabled_color
         $text = "Can Learn At Level " + $thing.llevel.to_s
       else
         self.contents.font.color = disabled_color
         $text = "Can't Learn"
       end
     else
       if actor.level >= $thing.llevel
         self.contents.font.color = normal_color
         $text = "Can Learn"
       else
         self.contents.font.color = disabled_color
         $text = "Can Learn At Level " + $thing.llevel.to_s
       end
     end
     self.contents.draw_text(x - 13, y + 40, 200, 32, $text)
   end
 end
 def update_cursor_rect
   if @index < 0
     self.cursor_rect.empty
   else
     self.cursor_rect.set(0, @index * 80, self.width - 32, 80)
   end
 end
end

class SkillShop
 def initialize(skills)
   @skills = skills
 end
 def main
   @command = Window_SkillCommand.new
   @help_window = Window_Help.new
   @skillbuy = Window_SkillBuy.new(@skills)
   @skillbuy.active = false
   @skillbuy.help_window = @help_window
   $thing = @skillbuy.skill
   @status = Window_SkillStatus2.new
   #@status.visible = false
   @gold = Window_Gold.new
   @gold.x = 480
   @gold.y = 64
   
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @gold.dispose
   @skillbuy.dispose
   @help_window.dispose
   @command.dispose
   @status.dispose
 end
 def update
   @gold.update
   @status.update
   @gold.refresh
   @command.update
   @skillbuy.update
   @help_window.update
   $thing = @skillbuy.skill
   @status.refresh
   if @command.active
     update_command
     return
   end
   
   if @status.active
     update_status
     return
   end
   
   if @skillbuy.active
     update_buy
     return
   end
 end
 
 def update_buy
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     @skillbuy.active = false
     @skillbuy.index = -1
     @command.active = true
     @command.index = 0
     return
   end
   if Input.trigger?(Input::C)
     $game_system.se_play($data_system.decision_se)
     @skillbuy.active = false
     @status.active = true
     @status.visible = true
     @status.index = 0 if @status.index == -1
   end
 end
 
 def update_command
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Map.new
     return
   end
   if Input.trigger?(Input::C)
     $game_system.se_play($data_system.decision_se)
     case @command.index
     when 0
       @command.active = false
       @command.index = -1
       @skillbuy.active = true
       @skillbuy.index = 0
     when 1
       $game_system.se_play($data_system.cancel_se)
       $scene = Scene_Map.new
     end
     return
   end
 end
 
 def update_status
   if Input.trigger?(Input::B)
     @status.active = false
     @status.index = -1
     @skillbuy.active = true
     return
   end
   if Input.trigger?(Input::C)
     price = @skillbuy.skill.price
     @actort = $game_party.actors[@status.index]
     enabled = (price <= $game_party.gold)
     
     if enabled
       if @actort.skill_learn?(@skillbuy.skill.id)
         $game_system.se_play($data_system.buzzer_se)
         return
       end
       if GameGuy::UseClasses
         if $data_classes[@actort.class_id].learnskills.include?(@skillbuy.skill.id) && @actort.level >= @skillbuy.skill.llevel
           @actort.learn_skill(@skillbuy.skill.id)
           $game_party.lose_gold(@skillbuy.skill.price)
           $game_system.se_play($data_system.decision_se)
           @status.refresh
           @skillbuy.refresh
           return
         else
           $game_system.se_play($data_system.buzzer_se)
           return
         end
       else
         if @actort.level >= @skillbuy.skill.llevel
           @actort.learn_skill(@skillbuy.skill.id)
           $game_party.lose_gold(@skillbuy.skill.price)
           $game_system.se_play($data_system.decision_se)
           @status.refresh
           @skillbuy.refresh
         else
           $game_system.se_play($data_system.buzzer_se)
           return
         end
         return
       end
       
     else
       $game_system.se_play($data_system.buzzer_se)
       return
     end
   end
 end

end



Instructions

In the script


Compatibility

Not tested with SDK. Wont work with other skill shop scripts


Credits and Thanks


  • game_guy ~ For making it
  • Hellfire Dragon ~ Requesting a cool sorting feature
  • Blizzard ~ Stormtronics CMS's Item sorting option
  • dylanf3 ~ Requesting price sorting option



Author's Notes

Give credits and enjoy!

Sally

awsome!! this is very good,

G_G

Anyone else like this script?

Blizzard

Put up a screenshot. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Oh yea huh xD

Ok here's some I completely forgot about adding them...sorry guys :(
Spoiler: ShowHide



Holyrapid

Is there a way to show in the level that is required for the skill, in the shop window?
I mean like this:
Description of skill
Skill Name       Lvl needed     Price
or something like this anyway. Or does it allready display that?

winkio

An all around useful script :)

Jackolas

July 11, 2009, 01:43:07 pm #7 Last Edit: July 11, 2009, 01:46:03 pm by Jackolas
Great script... only found 1 (i think really big) problem

when you bought a skill for a character you will see 3 selectable windows (the white boxes) at the same time
its really hard to see what 1 you are controlling

for example:
which 1 am I controlling atm:
Spoiler: ShowHide

awnser:
Spoiler: ShowHide
Its the top 1...


the way to do it is:
show 1 cursor in total when your in the top menu
show only 2 cursors when your in the skill select menu
and only show 3 cursors when your controlling the window what char should learn a skill

G_G

see the one you're controlling is blinking if you want I'll set it so the windows that arent active the index will be -1

Jackolas

i know the 1 blinking is the 1 your controlling.. but I'm afraid a lot of peep will get confused. (even I got confused)
this problem is the only reason why i'm not switching to this skill shop

G_G

there updated see if thats how you want it?

Jackolas

there is a bug
when you learned a skill to character and press esc and select learn again the cursor is gone and you can't select anything anymore

but nvm my request.. I don't want to waist your time for little things like this. I will stick with my own script I have.

G_G

check to see if its fixed now

dylanf3

I have some skills, i dont want to be bought, how can i do that?

G_G

dont include the skills when you call the skillshop you call it this way

SkillShop.new([skills])

example
SkillShop.new([1, 2, 3, 4])
would sell skills 1-4

Jackolas

the bug is fixed...

but think u misunderstand me :S

the top window was not really of my consurn
it the most right window where u select the actor after you bought the skill.
if you buy a skill and selected the actor who learns it i would love to see the actor select window cursor been hidden until u buy the next skill

dylanf3

But if i do that, i cant get to skill no. 57.....
Isnt there a way to sell all excluding no. 58 and 59?

G_G

@dylan you do this

SkillShop.new([1, 2, 3, 4, 57, 89])

Just put any skill id's in there or do these


Hellfire Dragon

Hey G_G, is there a way to make a shop sell all skills without having to list every skill ID?

TheBlob

Okay so I decided to try this out and ran into a strange problem that is almost certainly my doing.

First, I used the script and set up 9 skills just to test them out. Then, I called the script to run the item shop and discovered there was no text. No skills names, no "Learn" and "Exit", and no character names. I figured I did something wrong in my configuring, so I made a new game which just called the script without any editing whatsoever, and got the same result:



Any advice or help to fix it?

Hellfire Dragon

I think it's most likely that's it's because your using a cracked version of rmxp :P Are you?

winkio

It seems to me that you are using Postality Knights Edition of RMXP, by the blue icon in the upper left instead of an orange one.  Lots of scripts aren't compatible with it.  It shouldn't been too hard to edit them though.

G_G

Quote from: Hellfire Dragon on July 25, 2009, 11:17:23 am
Hey G_G, is there a way to make a shop sell all skills without having to list every skill ID?

use this in a script call

skills = []
for i in 1...$data_skills.size
  skill.push(i)
end
$scene = SkillShop.new(skills)

Hellfire Dragon

Quote
NameError occurred while running script.

undefined local variable or method 'skill' for #<Interpreter:0x4042ad8>


:(

Ryex

skills = []
for i in 1...$data_skills.size
  skills.push(i)
end
$scene = SkillShop.new(skills)

try that^^
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G


Hellfire Dragon

July 25, 2009, 01:32:01 pm #26 Last Edit: July 25, 2009, 01:41:50 pm by Hellfire Dragon
Silly G_G, oh well, small mistake :haha: Thanks ;)

EDIT: Just a suggestions, it'd be cool if we could have the skills sorted in different ways other than by the ID number, looks kinda random :P Like alphabetical would be cool :)

G_G

Ok I'll see if I can do that.

Blizzard

Get Tons of Add-ons and turn on Ultimate Font Override.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Hellfire Dragon

What? Posted in the wrong thread Blizzy?

Blizzard

Have I? O_o

Quote from: TheBlob on July 25, 2009, 11:31:43 am
Okay so I decided to try this out and ran into a strange problem that is almost certainly my doing.

First, I used the script and set up 9 skills just to test them out. Then, I called the script to run the item shop and discovered there was no text. No skills names, no "Learn" and "Exit", and no character names. I figured I did something wrong in my configuring, so I made a new game which just called the script without any editing whatsoever, and got the same result:



Any advice or help to fix it?

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Hellfire Dragon

:o You should've quoted or used @USER or something in your post :xD:

Blizzard

Yes, I should have. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Hellfire Dragon


G_G

I'll start on it in about 30 minutes I forgot about it sorry ^_^

G_G

Updates* Okay HD I added 4 different sorting options just for you :)

Hellfire Dragon

Awesome :D
You think you could add the sorting option to the version you made me? If you don't have it I can send it to you ;)

G_G

Yea send me your version and I'll add it to it :)

dylanf3

Is it possible to add a Sort By Price? It would help more then names

Blizzard

Bug: When you buy a skill and you don't have enough money to buy another, the other skills don't get grayed out. You can fix it by adding a refresh call after buying a skill.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

@dylanf3: I'll add it
@Blizzard: I'll fix it

G_G

*updates*
Fixed the bug blizz posted, and added sorting by pricing

ojp2010

Doesn't really work well with Mouse controller any way to edit it or fix?

ForeverZer0

Very nice. I can't believe nobody has done this yet. Lvl ++
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Holyrapid

Why was this excelnt script forgotten for so long? This is a great system.

ojp2010

Is there a way to make it so the shop will only show you skills that your class can use, instead of listing them all and saying which ones you can't learn.

zottel89

October 15, 2012, 11:41:50 am #46 Last Edit: October 15, 2012, 11:44:27 am by zottel89
I'm sorry for necroposting,
but I have a question regarding this script (and I think it's awesome by the way^^) !

The thing is:

I can buy the same skill over and over again with the same character !
I guess it's because I'm using a Skill Equipping system (by game_guy) ?!

Is there a way to only be able to learn a skill ONCE per character,
even though I'm using the skill equipping script (which means they don't appear directly in the skill menu) ?!

KK20

Try this.
class Game_Actor < Game_Battler
  def skill_learn?(skill_id)
    return @skills.include?(skill_id) or @eskills.include?(skill_id)
  end
end

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

G_G

Oh wow, I hadn't realized the two scripts would even conflict. >.< Thanks again KK20 for fixing my scripts again. *levels up*

zottel89

Quote from: Ezel Berbier on October 15, 2012, 01:36:38 pm
Try this.
class Game_Actor < Game_Battler
  def skill_learn?(skill_id)
    return @skills.include?(skill_id) or @eskills.include?(skill_id)
  end
end



Uuuhm sry for the dumb question,
but where do I have to input this?

G_G

@KK20: That snippet you provided has a syntax error. I dunno why but it errors out with "or" but when you use "||" instead, it works just fine.

@zottel: Just use my updated Skills Equipment Script and you'll be fine.

KK20

herp

Didn't know about that. I didn't test it (if that was any indication), it just looked logical to me. Probably would work if you use parenthesis around the statement.
return (@skills.include?(skill_id) or @eskills.include?(skill_id))
Glad to have pointed that out for you! All scripts must be perfect!
Big IMG: ShowHide

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!