查看: 2527|回复: 4

[已经解决] 技能商店問題

[复制链接]
梦石
0
星屑
354
在线时间
127 小时
注册时间
2016-10-8
回帖
54
发表于 2017-3-31 11:36:13 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 elemmy72 于 2017-3-31 11:36 编辑

之前找的白の魔的技能商店,礙於不會改選擇角色換頁
因此又找了另一個技能商店腳本,
可是卻在 item && item.skill_price <= @money 這行出錯了
有大大能幫忙找找原因嗎?

点击展开/收起=begin
CSCA技能商店
版本: 1.0 (发行时间: 2012年5月24日)
作者:Casper Gaming( http://www.caspergaming.com/ )
汉化:by 子弹君

重要提示:所有CSCA脚本应该是相互兼容的,除非另有说明。

该脚本可以让您轻松地创建一个卖技能的商店。

================================说明===================================

创建一个技能商店的事件:
要创建一个技能商店,你需要在事件处做一些脚本调用。

在脚本窗口中,你需要输入3行脚本:
goods= [1,2,3,4 ]
SceneManager.call(CSCA_Scene_Skill_Shop)
SceneManager.scene.prepare(goods)
第一行可以更改ID。该数字对应技能的ID 。
在这个例子中,#1,# 2,#3 ,#4将被出售。
最后两个脚本代码不需要变动

如何设置技能价格
技能的价格通过技能备注设置。在技能备注框中,输入此
备注 :
<cscaprice: X>
其中,x是技能的价格。例如,
<cscaprice: 100>
技能将花费100金。

如何设定哪些技能有的角色无法学习
默认情况下,角色可以不通过商店学习任何技能。这就需要在
角色的备注栏设置。
这样:
<csca_ss_skills: X>
其中,x将是技能的ID角色可以学习。您可以输入多个技能的ID
通过使用逗号分离。
例如:
<csca_ss_skills: x,y,z>
其中,x将是一个技能的ID ,Y将是另一个技能的ID ,Z将是另一个技能的
ID等。例如,
<csca_ss_skills: 1,2,3>
让角色来学习技能#1,#2,#3 。
============================= 结束=================================
=end

$imported = {} if $imported.nil?
$imported["CSCA-SkillShop"] = true
class CSCA_Scene_Skill_Shop < Scene_MenuBase

  def prepare(goods)
    @goods = goods
  end

  def start
    super
    create_help_window
    create_gold_window
    create_command_window
    create_dummy_window
    create_status_window
    create_buy_window
  end

  def create_gold_window
    @gold_window = Window_Gold.new
    @gold_window.viewport = @viewport
    @gold_window.x = Graphics.width - @gold_window.width
    @gold_window.y = @help_window.height
  end

  def create_command_window
    @command_window = CSCA_Window_SkillShopCommand.new(@gold_window.x)
    @command_window.viewport = @viewport
    @command_window.y = @help_window.height
    @command_window.set_handler(:buy,    method(:command_buy))
    @command_window.set_handler(:cancel, method(:return_scene))
  end

  def create_dummy_window
    wy = @command_window.y + @command_window.height
    wh = Graphics.height - wy
    @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
    @dummy_window.viewport = @viewport
  end

  def create_buy_window
    wy = @dummy_window.y
    wh = @dummy_window.height
    @buy_window = CSCA_Window_SkillShopBuy.new(0, wy, wh, @goods)
    @buy_window.viewport = @viewport
    @buy_window.help_window = @help_window
    @buy_window.status_window = @status_window
    @buy_window.hide
    @buy_window.set_handler(:ok,     method(:on_buy_ok))
    @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  end
  
  def create_status_window
    wx = 304
    wy = @dummy_window.y
    ww = Graphics.width - wx
    wh = @dummy_window.height
    @status_window = CSCA_Window_SkillShopStatus.new(wx, wy, ww, wh)
    @status_window.viewport = @viewport
    @status_window.hide
    @status_window.set_handler(:ok,     method(:on_number_ok))
    @status_window.set_handler(:cancel, method(:on_number_cancel))
  end

  def activate_buy_window
    @buy_window.money = money
    @buy_window.show.activate
    @status_window.show.unselect
  end

  def command_buy
    @dummy_window.hide
    activate_buy_window
  end

  def on_buy_ok
    @item = @buy_window.item
    @buy_window.deactivate
    @status_window.set(@item, buying_price)
    @status_window.show.activate.select(0)
  end

  def on_buy_cancel
    @command_window.activate
    @dummy_window.show
    @buy_window.hide
    @status_window.hide
    @help_window.clear
  end

  def on_number_ok
    Sound.play_shop
    do_buy(@status_window.item,@buy_window.item)
    end_input
    @gold_window.refresh
    @status_window.refresh
  end

  def on_number_cancel
    Sound.play_cancel
    end_input
  end

  def do_buy(actor, skill)
    $game_party.lose_gold(buying_price)
    $game_actors[actor.id].learn_skill(skill.id)
  end

  def end_input
    @status_window.unselect
    activate_buy_window
  end

  def money
    @gold_window.value
  end

  def currency_unit
    @gold_window.currency_unit
  end

  def buying_price
    @buy_window.price(@item)
  end
end
class CSCA_Window_SkillShopCommand < Window_HorzCommand

  def initialize(window_width)
    @window_width = window_width
    super(0, 0)
  end

  def window_width
    @window_width
  end

  def col_max
    return 2
  end

  def make_command_list
    add_command(Vocab::ShopBuy,    :buy)
    add_command(Vocab::ShopCancel, :cancel)
  end
end
class CSCA_Window_SkillShopBuy < Window_Selectable

  attr_reader   :status_window

  def initialize(x, y, height, shop_goods)
    super(x, y, window_width, height)
    @shop_goods = shop_goods
    @Money = 0
    refresh
    select(0)
  end

  def window_width
    return 304
  end

  def item_max
    @data ? @data.size : 1
  end

  def item
    @data[index]
  end

  def money=(money)
    @Money = money
    refresh
  end

  def current_item_enabled?
    enable?(@data[index])
  end

  def price(item)
    @price[item]
  end

  def enable?(item)
    item && item.skill_price <= @money
  end

  def refresh
    make_item_list
    create_contents
    draw_all_items
  end

  def make_item_list
    @data = []
    @price = {}
    for i in 0...@shop_goods.size
      item = $data_skills[@shop_goods]
      if item
        @data.push(item)
        @price[item] = item.skill_price
      end
    end
  end

  def draw_item(index)
    item = @data[index]
    rect = item_rect(index)
    draw_item_name(item, rect.x, rect.y, enable?(item))
    rect.width -= 4
    draw_text(rect, price(item), 2)
  end

  def status_window=(status_window)
    @status_window = status_window
    call_update_help
  end

  def update_help
    @help_window.set_item(item) if @help_window
    @status_window.item = item if @status_window
  end
end
class CSCA_Window_SkillShopStatus < Window_Selectable
  
  def set(skill, price)
    @skill = skill
    @price = price
    refresh
  end

  def initialize(x, y, width, height)
    super(x, y, width, height)
    @skill = nil
    @page_index = 0
    refresh
    select(0)
  end
  
  def item_max
    @data ? @data.size : 1
  end
  
  def item
    @data[index]
  end
  
  def item=(item)
    @skill = item
    refresh
  end

  def current_item_enabled?
    enable?(@data[index])
  end

  def enable?(actor)
    for i in 0...actor.skills.size
      if actor.skills == @skill
        return false
      end
    end
    for i in 0...actor.csca_learnable_skills.size
      unless @skill.nil?
        if actor.csca_learnable_skills == @skill.id
          return true
        end
      end
    end
    return false
  end

  def refresh
    make_item_list
    create_contents
    draw_all_items
  end

  def make_item_list
    @data = []
    $game_party.members.each do |actor|
      item = actor
      if !item.nil?
        @data.push(item)
      end
    end
  end

  def draw_item(index)
    item = @data[index]
    rect = item_rect(index)
    change_color(normal_color, enable?(item))
    draw_text(rect.x, rect.y, contents.width, line_height, item.name)
    change_color(normal_color)
  end
end
class RPG::Skill < RPG::UsableItem
  def skill_price
    if @note =~ /<G:(.*)>/i
      return $1.to_i
    else
      return 0
    end
  end
end
class RPG::Actor < RPG::BaseItem
  def learnable_skills
    if @note =~ /<csca_ss_skills:(.*)>/i
      ints = []
      for x in $1.split(",")
        ints.push(x.to_i)
      end
      return ints
    else
      return []
    end
  end
end
class Game_Actor < Game_Battler
  def csca_learnable_skills
    actor.learnable_skills
  end
end
(´_ゝ`)...仍未命名的遊戲製作進度:0%

老鹰

梦石
40
星屑
37812
在线时间
7091 小时
注册时间
2012-5-26
回帖
3297

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2017-3-31 12:33:07 | 显示全部楼层
本帖最后由 百里_飞柳 于 2017-3-31 12:36 编辑

代码要用代码框,就是 <> 这个符号的按钮

确定在数据库-技能页面中设置了技能的价格?

等等,代码有错误……
[pre lang="ruby"]class RPG::Skill < RPG::UsableItem
  def skill_price
    if @note =~ /<G:(.*)>/i
      return $1.to_i
    else
      return 0
    end
  end
end[/pre]
或者可以看做是注释有错误,实际应该是注释 <G:价格> 来设置技能的价格才对
你再试试

点评

啊啊啊啊,我找到他的網站了,結果就OK了冏冏冏冏冏…還是非常感謝祢的回答!謝謝~~~  发表于 2017-3-31 14:06
你先把主楼的代码框修改了……再截图为什么报错。确定不是因为论坛脚本复制粘贴后出的错?  发表于 2017-3-31 13:19
改了,還是不行QQ,一樣在231行錯誤…技能註釋我打<G:1000> 這樣應該沒錯吧?  发表于 2017-3-31 12:44

评分

参与人数 1星屑 +250 收起 理由
RaidenInfinity + 250 认可答案

查看全部评分

回复 1 0

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部