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

Project1

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

[已经解决] 变量小白问题,脚本赋值变量

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
跳转到指定楼层
1
 楼主| 发表于 2013-2-20 16:08:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 xixifilm 于 2013-2-22 15:42 编辑

一个令商品价格改变的脚本,加入事件里:
变量操作:[001]=$"价格变动脚本"     #“价格变动脚本”= "x" 是给予100~300不同比率令商店操作价格全部变动的脚本
变量操作:[001]=随机数(100..300)
商店处理:[恢复剂]
以上操作无效果,是否变量不能这样操作
而同样是事件操作:
脚本:$"价格变动脚本"  = 300
商店处理:[恢复剂]
这样就成功了令商品以%300价格买卖,为何之前错误?小白求点化

Lv3.寻梦者 (版主)

八宝粥的基叔

梦石
0
星屑
4677
在线时间
5233 小时
注册时间
2009-4-29
帖子
14320

贵宾

2
发表于 2013-2-20 16:22:15 | 只看该作者
错了错了,LZ你错了喵~
应该是这样:
[001]=随机数(100..300)
脚本:$"价格变动脚本"  = $game_variables[1]

点评

小白不明白,事件执行--》脚本$操作就直接起作用, 但代了变量就无效果,阁下的方法我看懂了,但是我这脚本出现错误:“undefined method > for Game_Varia...   发表于 2013-2-20 17:35

评分

参与人数 1梦石 +1 收起 理由
Mic_洛洛 + 1 认可答案

查看全部评分

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

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

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
3
 楼主| 发表于 2013-2-20 17:30:47 | 只看该作者
protosssonny 发表于 2013-2-20 16:22
错了错了,LZ你错了喵~
应该是这样:
[001]=随机数(100..300)

理解,谢谢

不过出错了, “$game_system.tax.percent ”这是我脚本, $game_system.tax.percent = 120 为 120%价格


#============================================================================
# Shop Taxes V1.6 (VXA version)
# By Emerald
#----------------------------------------------------------------------------
# Originally made by Falcon for RMXP
# Edited by Emerald to fit the RMVX and now also RMVX Ace
# You're free to use the script for any game, as long as you give credits
#----------------------------------------------------------------------------
# Version History
# 0.5 -> Script ported to RMVX Ace with minor edits to avoid errors
# 1.0 -> Further edits due to problems with percentage taxes
#               Added possibility to easily configure x/y position of tax information
#               and a value to configure if it will even be shown at all.
# 1.5 -> Again, further edits due to slight problems. But aside from that,
#               you can use <tax key item> again. Also added possibility to create
#               items which alter taxes. DRASTICALLY changed Instructions, be sure to
#               read it thoroughly.
# 1.6 -> Added Sell taxes and item Sell Tax changes.
#----------------------------------------------------------------------------
# With this script, you can almost fully control prices for VX Ace. You can
# normally set prices and prices unique per shop, and this script adds the
# possibility to make taxes. With these taxes, you can easily change prices of
# all items in a shop, either higher or lower.
#
# Instructions:
#
# Just as always, put this script between ▼ Materials and ▼ Main. If the
# information about the taxes is not shown correctly in shops, you can change
# it below.
# 就像往常一样,把这个脚本▼材料和▼之间。如果信息无法正确显示在商店的税收,你可以改变它下面
#
# In order to add taxes, use the call script method within an event. Use
# the following codes codes:
#
# $game_system.tax.percent = x
# Where x > 100 results in a tax with x% the normal price
# 其中,x> 100结果在一个纳税X%的正常价格
# Where x < 100 results in a discount with x% the normal price
# 其中,x<100 X%的正常价格折扣
#
# $game_systeme.tax.direct = y
# Where y > 0 results in a tax which adds y to every price
# 其中y> 0,y为每一个价格在一个纳税
# Where y < 0 results in a discount which subtracts y to every price
# 式中,y<0的结果中减去y为每一个价格的折扣
#
# WARNING
# For n = the price of an item,
# If n - y equals 0, the item becomes free
# If n - y < 0, the item becomes free AND you GET money (why doesn't that happen
# in real life)
# If x = a negative value then you'll GET money (x% the normal price)
# 对于n =一个项目的价格,
#  如果n -  y等于0时,该项目成为自由
#  如果n -  Y <0时,该项目成为自由,你会得到钱(为什么不发生在现实生活中)
# 如果x =负值,那么你会得到钱(X%的正常价格)
#
#
# ALWAYS!!, unless you're SURE the player can't have any items which alter taxes,
# add $game_system.tax.perbon to percentage taxes and $game_system.tax.dirbon to
# direct taxes. Else, the changes of the items ARE NOT APLIED!!
# ALWAYS!,除非你确定玩家可以没有任何改变税收的项目,
# $ game_system.tax.perbon的百分比税和$ game_system.tax.dirbon到
# 直接税。否则,不APLIED项目的变化!
# END WARNING
#
# $game_system.selltax.percent = x
# $game_system.selltax.direct = y
# $game_system.selltax.perbon = x
# $game_system.selltax.dirbon = y
#
# Exact same story as above, only these are hidden and for items being sold.
# 精确上述同样的故事,这些都是隐藏的,正在出售的物品。
#
# <tax key item>
# Use the above tag if you don't want that the price of that item can be changed
# by taxes. Useful for items which the player may not buy/sell. 使用上面的标签,
# 如果你不希望这样的价格,该项目可以改变税收。有用的物品,玩家可以不买/卖。
#
#
# <tax +/-x>
# Use the above tag to make items which will alter direct taxes. Use + to make
# it higher, - to make it lower. Enter a value for x. 使用上面的标签,这将改变
# 直接税。高,使用+ - ,使其低。输入x的值。
#
# <tax +/-x%>
# Use the above tag to make items whcih will alter percentage taxes. Use + to
# make it higher, - to make it lower. WARNING!! The value you enter for x will
# be ADDED or SUBSTRACTED of the current tax.percent!! 使用上面的标记,让项目的
# 酦将改变比例税。高,使用+ - ,使其低。警告!您输入的x的值将被添加或中减去目前
# 的tax.percent!!
#
# Examples:
# $game_system.tax.percent = 150 & an item with <tax +20%> will result in a tax
# of 170%. “150”项目与<tax+20%>将导致在一个纳税170%。
#
# $game_system.tax.percent = 100 (/no value set) & an item with <tax -42%> will
# result in a tax of 58%.“100”(/没有价值的)一个项目,<tax-42%>导致58%的税。
#
# NOTE that if the player gets any items with these tags, the amount he/she has
# of the item determines how many times the taxes will be altered! Two of the
# same items in Example 1 will result in a tax of 190% instead of 170%.
# Also, if the player gets any items with these tags, the changes to taxes will
# be stored in $game_system.tax.perbon and $game_system.tax.dirbon for
# percentage and direct taxes respectively. Always add these variable to
# $game_system.tax.percent and $game_system.tax.direct respectively if changes
# to these two are made. Don't change perbon and dirbon as they only handle the
# changes made by items. 需要注意的是,如果玩家获得这些标签的任何项目,该项目确定
# 他/她有多少次税将改变!例1在同一项目中的两个将导致190%,而不是170%的税。
# 此外,如果玩家获得这些标签的任何项目的税收,将,在$ game_system.tax.perbon美元和
# 百分比game_system.tax.dirbon和直接税分别存放。一定要添加这些变量$ game_system.
# tax.percent的美元和game_system.tax.direct如果这两个分别。 ,不要改变perbon和dirbon,
# 因为他们处理的项目所做的更改。
#
# <selltax +/-x>
# Exact same effect as <tax...> but this one changes the prices of sold items.
# 精确相同的效果<tax...>但这个变化的价格出售项目。
#
# <selltax +/-x%>
# Same story as above.上同
#
# Use $game_system.selltax.perbon and $game_system.selltax.perbon for the above
# two tags.
#----------------------------------------------------------------------------
# Credits to:
# Falcon for the original script
# Blizard for the idea that triggered version 2.0 (Falcon's Credits)
# You, because you ate a cookie in your life =D (I hope... If not, I'll send
# Bennett to make you eat a cookie with his manliness...)
#----------------------------------------------------------------------------
# This script should be compatible with all shop systems. If not, alert me.
#============================================================================
#
# CONFIGURATIONS
#
#============================================================================
class Window_ShopStatus < Window_Base

  TAX                    = "Tax"   # Word which stands before percent tax IF the percent tax > 100代表%的税率征收前IF%的税> 100
  DISCOUNT              = "价格"   # Word which stands before percent tax IF the percent tax < 100字代表IF%的税率征收100%的税前
  TAX_DIRECT      = "Tax (A)"     # Word which stands before direct tax IF the direct tax > 0 里面站立在直接税,如果直接税>0
  DISCOUNT_DIRECT = "Discount (A)" # Word which stands before direct tax IF the direct tax < 0代表如果直接税直接税之前<0
  TAX_INFORMATION = true  # True = show information about taxes in shops, false = well... the opposite
  TAX_X            = 4    # x position of the information of the taxes. Usually, text has an x-value of 4 x位置的信息的税收。一般,文字有4的x值
  TAX_Y            = 216  # y position of the information. Default = 216. Not that text starts on y = 0 and every line has a height of y = 24 y位置的信息。默认值= 216。非该文本在y=0开始,每行有一个高度为y =24

end

module EME
  module REGEXP
        module ITEM

          # Only edit things past here if you know what you're doing
          KEY_ITEM_TAG = /<tax[\s_]?key[\s_]?item>/i # <tax key item>
          ITEM_TAX_PER = /<tax[\s_]?[ ]*([\+\-]\d+)([%%])>/i # <tax +/-x%>
          ITEM_TAX_DIR = /<tax[\s_]?[ ]*([\+\-]\d+)>/i  # <tax +/-x>
          ITEM_SELLTAX_PER = /<selltax[\s_]?[ ]*([\+\-]\d+)([%%])>/i # <selltax +/-x%>
          ITEM_SELLTAX_DIR = /<selltax[\s_]?[ ]*([\+\-]\d+)>/i  # <selltax +/-x>

        end
  end
end

#============================================================================
#
# Game_System
# Defines all needed variables for taxes.定义所有需要的变量税。
#============================================================================

class Game_System::Tax
  attr_accessor :percent
  attr_accessor :perbon
  attr_accessor :direct
  attr_accessor :dirbon

  def initialize
        @percent = 100
        @perbon  = 0
        @direct  = 0
        @dirbon  = 0
  end

end

class Game_System::SellTax
  attr_accessor :percent
  attr_accessor :perbon
  attr_accessor :direct
  attr_accessor :dirbon

  def initialize
        @percent = 100
        @perbon  = 0
        @direct  = 0
        @dirbon  = 0
  end

end

class Game_System
  attr_reader :tax
  attr_reader :selltax

  alias eme_tax_initialize initialize
  def initialize
        eme_tax_initialize
        @tax = Tax.new
        @selltax = SellTax.new
  end

end

#============================================================================
#
# Window_ShopBuy
# Handles effects of taxes and <tax key item>.处理的税和<tax的关键项目>的影响。
#============================================================================

class Window_ShopBuy

  def price(item)
        @price[item]
        notetag_check(item)
        if @key_item
          @new_price = @price[item]
        elsif $game_system.tax.percent != 100 or $game_system.tax.direct != 0
          @new_price = @price[item] * $game_system.tax.percent / 100 + $game_system.tax.direct
        else
          @new_price = @price[item]
        end
  end

  def notetag_check(item)
        @key_item = false
        item.note.split(/[\r\n]+/).each { |line|
        case line
          when EME::REGEXP::ITEM::KEY_ITEM_TAG
                @key_item = true
          end
        }
  end

end

class Scene_Shop

  def selling_price
        the_selling_price = @item.price / 2
        notetag_check(@item)
        unless @key_item = true
          if $game_system.selltax.percent != 100
                the_selling_price *= $game_system.selltax.percent / 100
          end
          if $game_system.selltax.direct != 0
                the_selling_price += $game_system.selltax.direct
          end
        end
        return the_selling_price
  end

  def notetag_check(item)
        @key_item = false
        item.note.split(/[\r\n]+/).each { |line|
        case line
          when EME::REGEXP::ITEM::KEY_ITEM_TAG
                @key_item = true
          end
        }
  end

end

#============================================================================
#
# Game_Party
# Handles items which alter taxes.处理改变税的项目。
#============================================================================

class Game_Party

  alias eme_tax_gain_item gain_item
  def gain_item(item, amount, include_equip = false)
        eme_tax_gain_item(item, amount, include_equip = false)
        if amount > 0 and item != nil
          item.note.split(/[\r\n]+/).each { |line|
          case line
                when EME::REGEXP::ITEM::ITEM_TAX_PER
                  $game_system.tax.percent += $1.to_i * amount
                  $game_system.tax.perbon += $1.to_i * amount
                when EME::REGEXP::ITEM::ITEM_TAX_DIR
                  $game_system.tax.direct += $1.to_i * amount
                  $game_system.tax.dirbon += $1.to_i * amount
                when EME::REGEXP::ITEM::ITEM_SELLTAX_PER
                  $game_system.selltax.percent += $1.to_i * amount
                  $game_system.selltax.perbon += $1.to_i * amount
                when EME::REGEXP::ITEM::ITEM_SELLTAX_PER
                  $game_system.selltax.percent += $1.to_i * amount
                  $game_system.selltax.perbon += $1.to_i * amount
                end
          }
        elsif item != nil
          item.note.split(/[\r\n]+/).each { |line|
          case line
                when EME::REGEXP::ITEM::ITEM_TAX_PER
                  $game_system.tax.percent -= $1.to_i * amount
                  $game_system.tax.perbon -= $1.to_i * amount
                when EME::REGEXP::ITEM::ITEM_TAX_DIR
                  $game_system.tax.direct -= $1.to_i * amount
                  $game_system.tax.dirbon -= $1.to_i * amount
                when EME::REGEXP::ITEM::ITEM_SELLTAX_PER
                  $game_system.selltax.percent -= $1.to_i * amount
                  $game_system.selltax.perbon -= $1.to_i * amount
                when EME::REGEXP::ITEM::ITEM_SELLTAX_PER
                  $game_system.selltax.percent -= $1.to_i * amount
                  $game_system.selltax.perbon -= $1.to_i * amount
                end
          }
        end
  end

end

#============================================================================
#
# Window_ShopStatus
# Handles information of taxes shown in shops.在商店的税收处理信息。
#============================================================================
class Window_ShopStatus < Window_Base

  alias eme_tax_refresh refresh
  def refresh
        eme_tax_refresh
        if TAX_INFORMATION
          draw_taxes(TAX_X, TAX_Y)
        end
  end

  def draw_taxes(x, y)
        if $game_system.tax.percent != 100
          rect = Rect.new(x, y, contents.width - 4 - x, line_height)
          change_color(system_color)
          if $game_system.tax.percent > 100
                draw_text(rect, TAX + ":")
          else
                draw_text(rect, DISCOUNT + ":")
          end
          change_color(normal_color)
          draw_text(rect, $game_system.tax.percent.to_s + "%", 2)
        end
        if $game_system.tax.direct != 0
          rect = Rect.new(x, y + 24, contents.width - 4 - x, line_height)
          change_color(system_color)
          if $game_system.tax.direct > 0
                draw_text(rect, TAX_DIRECT + ":")
          else
                draw_text(rect, DISCOUNT_DIRECT + ":")
          end
          change_color(normal_color)
          draw_text(rect, $game_system.tax.direct.to_s, 2)
        end
  end

end

点评

第几行出错的没说清楚。  发表于 2013-2-20 17:40
那这出错就是另一个问题了,至于是怎么出错的,应另说明喵。  发表于 2013-2-20 17:34
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
4
 楼主| 发表于 2013-2-20 18:44:44 | 只看该作者
protosssonny 发表于 2013-2-20 16:22
错了错了,LZ你错了喵~
应该是这样:
[001]=随机数(100..300)

谢谢你的帮忙,

我的事件写法是:
变量操作:[0001:某某] = 随机数( 50..120 )
脚本:$game_system.tax.percent = $game_variables[1]
商店处理:某某......

而后当主角与事件角色一对话就出错
342行:NoMethodError
undefined method `>' for #<Game_Variables:0x76e004 @data=[nil,nil,105]

当前出错在此脚本“ if $game_system.tax.percent > 100 ”
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
5
 楼主| 发表于 2013-2-20 18:47:06 | 只看该作者
xixifilm 发表于 2013-2-20 17:30
理解,谢谢

不过出错了, “$game_system.tax.percent ”这是我脚本, $game_system.tax.percent = 120  ...

是我脚本内

#============================================================================
#
# Window_ShopStatus
# Handles information of taxes shown in shops.在商店的税收处理信息。
#============================================================================

以下
“ if $game_system.tax.percent > 100 ” 出错

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
6
 楼主| 发表于 2013-2-20 20:12:11 | 只看该作者
那个看似只是显示问题,
我取消了信息显示
# CONFIGURATIONS下
class Window_ShopStatus < Window_Base
  TAX_INFORMATION = false 取消显示
就会发生:
227行 :发生 TypeError
Game_Variables can't be coerced into Fixnum

点评

灰常不好意思,我这里没有任何错误。  发表于 2013-2-20 20:46
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
7
 楼主| 发表于 2013-2-20 20:59:14 | 只看该作者
protosssonny 发表于 2013-2-20 16:22
错了错了,LZ你错了喵~
应该是这样:
[001]=随机数(100..300)

不好意思,请问你用的什么版本的VA,
我用的是66里面的简体中文1.0版
或者可以给个链接我下载吗
回复 支持 反对

使用道具 举报

Lv3.寻梦者 (版主)

八宝粥的基叔

梦石
0
星屑
4677
在线时间
5233 小时
注册时间
2009-4-29
帖子
14320

贵宾

8
发表于 2013-2-20 21:03:01 | 只看该作者
xixifilm 发表于 2013-2-20 20:59
不好意思,请问你用的什么版本的VA,
我用的是66里面的简体中文1.0版
或者可以给个链接我下载吗 ...

Project2.rar (304.4 KB, 下载次数: 75)
《逝去的回忆3:四叶草之梦》真情发布,欢迎点击图片下载试玩喵。

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

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
9
 楼主| 发表于 2013-2-20 22:51:08 | 只看该作者
protosssonny 发表于 2013-2-20 21:03

感谢~!

我找到我自己的一个问题 ,不知道是否bug:

不是我的游戏版本问题,你的脚本也无错,我也照你的脚本写了,
问题是执行脚本事件时,由于$某某某=某某某[x] 这行太长了,超出了执行脚本的填写框,导致换行了,所以脚本出错

真是太感谢了,我现在商店终于可以随机价格

点评

换行使用符号\即可。  发表于 2013-2-20 22:53
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
60 小时
注册时间
2013-1-21
帖子
53
10
 楼主| 发表于 2013-2-21 21:12:44 | 只看该作者
protosssonny 发表于 2013-2-20 21:03

对了,有没有留意,比率并没有把卖出价格计算在内,请问能帮手看看脚本,是另外有指令,或者要怎么写?
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-7-21 15:23

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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