设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1291|回复: 1
打印 上一主题 下一主题

[已经过期] 多货币脚本出错了。。求大神。。。

[复制链接]

Lv1.梦旅人

梦石
0
星屑
168
在线时间
45 小时
注册时间
2012-9-4
帖子
30
跳转到指定楼层
1
发表于 2012-9-22 14:43:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
module Currency
#==============================================================================
#   设定部分
#==============================================================================
# 货币名称 -- 在金钱窗口里使用
@name = ["金", "银", "币", "款", "汇"]

# 货币名称 -- 在商店里选择时使用
@iname =["金币", "银币", "铜币", "存款", "汇票"]

# 货币汇率 -- 计算价钱用
@rate = [ 1, 0.5, 0.25, 1, 1]
# 无法使用的货币
@cannot_use = [3, 4]
# 不在金钱窗口显示的货币
@do_not_show = [4]
# 货币文字 -- 商店画面选项理所显示的文字
def self.word
return "选择货币"
end
# 只能用特定货币购买时显示的文字
# %s代表该货币
One_Currency = "只能用%s来购买!"

# 金钱窗口设置:是否在菜单显示新的金钱窗口
SHOW_NEW_CURRENCY = true
#==============================================================================
#  设定部分结束
#==============================================================================
#==============================================================================
#   使用方法
#==============================================================================
=begin
在事件中使用脚本:
gain_currency(类型, 数量)增加该类型货币
lose_currency(类型, 数量)减少该类型货币
convert(类型, 变量ID) 将该变量内的数值转换为该类型并返回
currency_type(类型, 变量ID) 将该类型货币金额代入该变量
在物品(武器、防具亦可,技能尚未测试)的备注栏打上
[currency 类型]
则该物品只能使用该类型货币购买
在物品(武器、防具亦可,技能尚未测试)的备注栏打上
[n_currency 类型]
则该物品只能使用该类型以外的货币购买
两个同时定义时,会互相抵销
(例如:同一个物品同时定义了[currency 1] 和[n_currency 1]
也就是同时「只能使用1号货币」和「只能除用除1号以外的货币」
那麽就变成了全部都能使用)
类型为数字代号,就是在脚本中所设定好的顺序(从0开始算)
0为默认金钱(直接用事件命令就行了)
☆只能用特定货币购买的商店 设定方法
在召唤商店画面的NPC事件指令内容使用:
脚本:$special_currency = n # <== n 为货币类型
商店处理:商品列表
脚本:call_new_shop
设定後,该商店的「货币选择」选项无效
=end
#==============================================================================
#  使用方法结束
#==============================================================================
attr_accessor :name
attr_accessor :rate
def self.get_g_rate(i)
if $game_party.gold != 0
p = @rate * $game_party.gold
return p.to_i == 0? 1 : p.to_i
else
return 0
end
end
def self.get_n_rate(i, number)
if number != 0
p = @rate * number
return p.to_i == 0? 1 : p.to_i
else
return 0
end
end
def self.number
return @name.size
end
def self.name(i)
return @name
end
def self.id(i)
return @iname
end
def self.show?(id)
return !(@do_not_show.include?(id))
end
def self.can_use?(id, item=nil)
return false if @cannot_use.include?(id)
unless item == nil
if item.get_currency_use != nil
return true if item.get_currency_use.include?(id)
elsif item.get_currency_not_use != nil
return false if item.get_currency_not_use.include?(id)
else return true
end
else return true
end
end
end
class Game_Party < Game_Unit
attr_accessor :curr
alias c_ini initialize
def initialize
c_ini
@curr = []
for i in 0...Currency.number
if @curr == nil
@curr = 0
end
end
@curr[0] = @gold
end
# 获得和失去金钱
def gain_curr(type, amount)
@curr[type] = [[@curr[type] + amount, 0].max, 9999999].min
@gold = @curr[0]
end
def lose_curr(type, amount)
gain_curr(type, -amount)
end
def gain_gold(n)
gain_curr(0, n)
end
def curr(n)
return @curr[n] == nil ? 0 : @curr[n]
end
end
class Game_Interpreter
# 获取货币
def gain_currency(type, amount)
$game_party.gain_curr(type, amount)
end
# 失去货币
def lose_currency(type, amount)
$game_party.lose_curr(type, amount)
end
# 货币兑换
def convert(type, vid)
return Currency.get_n_rate(type, $game_variables[vid])
end
# 获取货币持有量
def currency_type(type, vid)
$game_variables[vid] = $game_party.curr(type)
end
# 召唤商店画面
alias old_command_302 command_302
def command_302
if $special_shop != -1
$game_temp.shop_goods = [@params]
$game_temp.shop_purchase_only = @params[2]
loop do
@index += 1
if @list[@index].code == 605
$game_temp.shop_goods.push(@list[@index].parameters)
else
return false
end
end
else
old_command_302
end
end
def call_new_shop
$scene = Scene_Shop.new($special_shop)
$special_shop = -1
end
end
class Scene_Menu < Scene_Base
alias c_menu_start start
def start
c_menu_start
if Currency::SHOW_NEW_CURRENCY
@gold_window.dispose
@gold_window = Window_SGold.new(0, 0)
@gold_window.y = 416-@gold_window.height
end
end
end
class RPG::BaseItem
def get_currency_use
e = []
self.note.split(/[\r\n]+/).each { |line|
if line =~ /\[currency \d+\]/
a = line.split(/ /)[1]
d = ""
while ((c = a.slice!(/./m)) != nil)
d += c if c != ">"
end
e.push(d.to_i)
end
}
return e==[] ? nil : e
end
def get_currency_not_use
e = []
self.note.split(/[\r\n]+/).each { |line|
if line =~ /\[ncurrency \d+\]/
a = line.split(/ /)[1]
d = ""
while ((c = a.slice!(/./m)) != nil)
d += c if c != ">"
end
e.push(d.to_i)
end
}
return e==[] ? nil : e
end
end
#==============================================================================
# ■ Window_SGold
#------------------------------------------------------------------------------
#  新的显示金钱窗口,可以显示多重货币。
#==============================================================================
class Window_SGold < Window_Base
def initialize(x, y, c=-1)
a = 1
@money = []
for i in 0...Currency::number
@money.push(i) if Currency.show?(i)
end
a = @money.size if c == -1
super(x, y, 160, a * WLH + 32)
@currency = c
refresh
end
def refresh
self.contents.clear
if @currency == -1
for i in @money
draw_scurrency_value(i, 4, i*WLH, 120)
end
else
draw_scurrency_value(@currency, 4, 0, 120)
end
end
def draw_scurrency_value(i, x, y, width)
cx = contents.text_size(Vocab::gold).width
self.contents.font.color = normal_color
self.contents.draw_text(x, y, width-cx-2, WLH, $game_party.curr(i), 2)
self.contents.font.color = system_color
self.contents.draw_text(x, y, width, WLH, Currency.name(i), 2)
end
end
#==============================================================================
# ■ Window_ShopBuy
#------------------------------------------------------------------------------
#  商店画面、浏览显示可以购买的商品的窗口。
#==============================================================================
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# x : 窗口 X 座标
# y : 窗口 Y 座标
# c : 货币类型
#--------------------------------------------------------------------------
def initialize(x, y, c=0)
super(x, y, 304, 304)
@shop_goods = $game_temp.shop_goods
@currency = c
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 绘制商品
# index : 商品索引
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
number = $game_party.item_number(item)
price = Currency.get_n_rate(@currency, item.price)
gold = Currency.get_g_rate(@currency)
enabled = Currency.can_use?(@currency, item)
enabled = ( price <= gold and number < 99) if enabled
rect = item_rect(index)
self.contents.clear_rect(rect)
draw_item_name(item, rect.x, rect.y, enabled)
rect.width -= 4
self.contents.draw_text(rect,price, 2)
end
end
class Window_ShopStatus < Window_Base
alias curr_refresh refresh
def refresh
curr_refresh
currency = []
money = ""
if @item != nil
for i in 0...Currency::number
currency.push(i) if Currency.can_use?(i, @item)
end
for i in currency
money += "、" if i>0 and i<=currency.size
money += Currency.name(i)
end
string = sprintf(Currency::One_Currency, money)
self.contents.draw_text(4, 24, 200, WLH, string,1)
end
end
end
#==============================================================================
# ■ Scene_Shop
#------------------------------------------------------------------------------
#  处理商店画面的类。
#==============================================================================
class Scene_Shop < Scene_Base
def initialize(c=nil)
if c==nil
@special_currency = false
@currency = 0
else
@special_currency = true
@currency = c
end
end
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
alias c_start start
def start
c_start
@command = []
for i in 0...Currency::number
if Currency.can_use?(i)
@command.push(Currency::id(i))
end
end
@currency_window = Window_Command.new(160, @command, 1, 3)
@currency_window.x = 384
@currency_window.y = 56
@currency_window.active = false
@currency_window.visible = false
@gold_window = Window_SGold.new(384, 56, @currency)
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
alias c_term terminate
def terminate
c_term
@currency_window.dispose
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
@help_window.update
@command_window.update
@gold_window.update
@dummy_window.update
@buy_window.update
@sell_window.update
@number_window.update
@status_window.update
@currency_window.update
if @command_window.active
update_command_selection
elsif @buy_window.active
update_buy_selection
elsif @sell_window.active
update_sell_selection
elsif @number_window.active
update_number_input
elsif @currency_window.active
update_currency_selection
end
end
#--------------------------------------------------------------------------
# ● 生成命令窗口
#--------------------------------------------------------------------------
def create_command_window
s1 = Vocab::ShopBuy
s2 = Vocab::ShopSell
s3 = Vocab::ShopCancel
s4 = Currency.word
@command_window = Window_Command.new(384, [s1, s2, s4, s3], 4)
@command_window.y = 56
@command_window.draw_item(2, false) if @special_currency
if $game_temp.shop_purchase_only
@command_window.draw_item(1, false)
end
end
#--------------------------------------------------------------------------
# ● 更新命令窗口
#--------------------------------------------------------------------------
def update_command_selection
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
case @command_window.index
when 0 # 买入
Sound.play_decision
@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 # 卖出
if $game_temp.shop_purchase_only
Sound.play_buzzer
else
Sound.play_decision
@command_window.active = false
@dummy_window.visible = false
@sell_window.active = true
@sell_window.visible = true
@sell_window.refresh
end
when 3 # 离开
Sound.play_decision
$scene = Scene_Map.new
when 2 # 货币
unless @special_currency
Sound.play_decision
@currency_window.active = true
@currency_window.visible = true
@command_window.active = false
@gold_window.visible = false
else
Sound.play_buzzer
end
end
end
end
#--------------------------------------------------------------------------
# ● 更新货币选择窗口
#--------------------------------------------------------------------------
def update_currency_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@currency_window.active = false
@currency_window.visible = false
@command_window.active = true
@gold_window.visible = true
elsif Input.trigger?(Input::C)
Sound.play_decision
@currency_window.active = false
@currency_window.visible = false
@command_window.active = true
@currency = @currency_window.index
@buy_window.dispose
@buy_window = Window_ShopBuy.new(0, 112, @currency)
@buy_window.active = false
@buy_window.visible = false
@gold_window.dispose
@gold_window = Window_SGold.new(384, 56, @currency)
end
end
#--------------------------------------------------------------------------
# ● 更新买入选择
#--------------------------------------------------------------------------
def update_buy_selection
@status_window.item = @buy_window.item
if Input.trigger?(Input::B)
Sound.play_cancel
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
@help_window.set_text("")
return
end
if Input.trigger?(Input::C)
@item = @buy_window.item
number = $game_party.item_number(@item)
price = Currency.get_n_rate(@currency, @item.price)
gold = Currency.get_g_rate(@currency)
enabled = Currency.can_use?(@currency, @item)
enabled = ( price <= gold and number < 99) if enabled
unless enabled
Sound.play_buzzer
else
Sound.play_decision
max = price == 0 ? 99 : gold / @item.price
max = [max, 99 - number].min
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@item, max, @item.price)
@number_window.active = true
@number_window.visible = true
end
end
end
#--------------------------------------------------------------------------
# ● 确认数值输入
#--------------------------------------------------------------------------
def decide_number_input
Sound.play_shop
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0 # 买入
gold = @number_window.number * @item.price
$game_party.lose_curr(@currency_window.index, gold)
$game_party.gain_item(@item, @number_window.number)
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
@buy_window.active = true
@buy_window.visible = true
when 1 # 卖出
gold = @number_window.number * (@item.price / 2)
$game_party.gain_curr(@currency_window.index, gold)
$game_party.lose_item(@item, @number_window.number)
@gold_window.refresh
@sell_window.refresh
@status_window.refresh
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
end
end



这个用了以后打开商店,一打开角色菜单栏也会出错。。各种不理解,求解答。

点评

用了其他脚本吧,不然怎么会出错。。。  发表于 2012-9-22 15:00

Lv3.寻梦者 (版主)

八宝粥的基叔

梦石
0
星屑
4644
在线时间
5238 小时
注册时间
2009-4-29
帖子
14318

贵宾

2
发表于 2012-9-22 16:17:17 | 只看该作者
出错截图也没有,工程也不上,就放一个没有任何错误的脚本,想帮你也帮不到。如果我们是神仙或许可以帮你。

评分

参与人数 1星屑 +10 收起 理由
八宝粥先生 + 10 P叔一直是神仙

查看全部评分

《逝去的回忆3:四叶草之梦》真情发布,欢迎点击图片下载试玩喵。

《逝去的回忆3》的讨论群:
一群:192885514
二群:200460747
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-28 04:23

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表