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

Project1

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

[有事请教] 请高手看下时间类和金钱类的整合简单yinhang脚本

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3925
在线时间
254 小时
注册时间
2013-10-13
帖子
790
跳转到指定楼层
1
发表于 2023-11-9 21:41:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
class Bank_Window < Window_Selectable
  def initialize
    @operate=["存钱","取钱","取消"]
    super(320-120,240,240,64+64)
    @[email protected]
    @column_max=3
    @index=0
    self.contents=Bitmap.new(self.width-32,self.height-32)
    refresh
  end
  def refresh
    for i in [email protected]
      self.contents.draw_text(i*64,0,64,32,@operate[i])
    end
#    self.contents.draw_text(300,0,64,32,$data_system.words.gold)
  end
  #--------------------------------------------------------------------------
  # ● 更新光标矩形
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # 光标位置不满 0 的情况下
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # 获取当前的行
    row = @index / @column_max
    # 当前行被显示开头行前面的情况下
    if row < self.top_row
      # 从当前行向开头行滚动
      self.top_row = row
    end
    # 当前行被显示末尾行之后的情况下
    if row > self.top_row + (self.page_row_max - 1)
      # 从当前行向末尾滚动
      self.top_row = row - (self.page_row_max - 1)
    end
    # 计算光标的宽度
    cursor_width = self.width / @column_max - 32
    # 计算光标坐标
    x = @index % @column_max * (cursor_width+16)
    y = @index / @column_max * 32 - self.oy
    # 更新光标矩形
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
end
class Window_Gold < Window_Base
  #--------------------------------------------------------------------------
  # ● 初始化窗口
  #--------------------------------------------------------------------------
  def initialize
    super(0, 120, 160, 128)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  alias old_refresh refresh
  def refresh
    self.contents.clear
    cx = contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
    self.contents.draw_text(4,32,160-32,32,"身上的钱的数目")
  end
end
class Window_Gold_1 < Window_Base #yinhang窗口
  #--------------------------------------------------------------------------
  # ● 初始化窗口
  #--------------------------------------------------------------------------
  def initialize
    super(0, 240, 160, 128)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    gold_1=$game_party.gold_1*(1+$game_map.date_minute*0.5)
    cx = contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120-cx-2, 32,
    gold_1.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(124-cx, 0, cx, 32,
    $data_system.words.gold, 2)
    self.contents.draw_text(4,32,160-32,32,"yinhang的钱的数目")
  end
end
class Game_Party
  attr_reader :gold_1 #yinhang的钱的数目
  alias old_initialize initialize
  def initialize
    old_initialize
    @gold_1=0
  end
  def gain_1_gold(n)
    @gold_1=gold_1+n
  end
  def lose_1_gold(n)
    @gold_1=gold_1-n
  end
end


module Date
  RATE = Graphics.frame_rate
#============================================================================
# ■ 2、时间系统的运作
#============================================================================
def Date.run_date_system
#Graphics.frame_count=80桢 折合成2秒/
#每40桢刷新一次,date_minute记数加1/游戏中1分=现实1秒
#Graphics.frame_count是画面更新次数的计数/1秒记数40次
#/记数1直到40,*40是计数一下子就40
#Graphics.frame_rate是1秒钟更新画面的次数
   if Graphics.frame_count%Date::RATE == 0  #1分所用时间
     $game_map.date_minute += 1   
   end
   if $game_map.date_minute >= 60  #1小时所用时间
     $game_map.date_minute = 0   
     $game_map.date_hour += 1
   end
   if $game_map.date_hour >= 24  
     $game_map.date_hour = 0
     $game_map.date_day += 1
     $game_map.date_week += 1
   end
   if $game_map.date_week >= 8
     $game_map.date_week = 1
   end
   if $game_map.date_day >= 30
     $game_map.date_day = 1
     $game_map.date_month += 1
   end
   if $game_map.date_day > 90
     $game_map.date_season += 1
   end
   if $game_map.date_season >= 5
     $game_map.date_season = 1
   end

   if $game_map.date_month>=12
     $game_map.date_month = 1
     $game_map.date_year += 1
   end
end
end
class Window_TimeDate < Window_Base
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 86)
    self.contents = Bitmap.new(width - 32, height - 32)
#    self.opacity = 0
    refresh
  end
  def refresh
    self.contents.clear
    @fen_timedate = $game_map.date_minute  # 此变量用于刷新 画面
    # 描绘年
    self.contents.font.size = 22
    self.contents.font.color=text_color(2)
    self.contents.draw_text(0, 0, 52, 52, "年")
    self.contents.font.size = 22
    self.contents.font.color=normal_color
    self.contents.draw_text(32, 0, 52, 52, $game_map.date_year.to_s)
    # 描绘 季节
    if $game_map.date_season == 2
      seasoncolor = Color.new(250,80,5)
      wordj = "夏"
    elsif $game_map.date_season == 4
      seasoncolor = Color.new(150,170,250)
      wordj = "冬"
    elsif $game_map.date_season == 1
      seasoncolor = Color.new(5,255,50)
      wordj = "春"
    else
      seasoncolor = Color.new(228,208,38)
      wordj = "秋"
    end
   
    self.contents.font.size = 22
    self.contents.font.name = ["楷体_GB2312","黑体"]
    self.contents.font.color = seasoncolor
    self.contents.draw_text(64, 0, 52, 52, wordj)
    #描绘月
    self.contents.font.size = 22
    self.contents.font.color=text_color(2)
    self.contents.draw_text(96, 0, 52, 52, "月")
    self.contents.font.size = 22
    self.contents.font.color=text_color(2)
    self.contents.draw_text(128, 0, 52, 52, $game_map.date_month.to_s)
    # 描绘 号数
    self.contents.font.size = 22
    self.contents.font.color=text_color(2)
    self.contents.draw_text(160, 0, 52, 52, "天")
    self.contents.font.size = 22     
    self.contents.font.name = ["楷体_GB2312","黑体"]
    self.contents.draw_text(192, 0, 84, 42,$game_map.date_day.to_s)
    # 描绘 星期
    case $game_map.date_week
    when 1
      self.contents.font.color = Color.new(170,170,170,255)
      wordx = "月"
    when 2
      self.contents.font.color = Color.new(50,100,240,255)
      wordx = "火"
    when 3
      self.contents.font.color = Color.new(227,59,13,255)
      wordx = "水"
    when 4
      self.contents.font.color = Color.new(74,4,4,255)
      wordx = "木"
    when 5
      self.contents.font.color = Color.new(228,231,10,255)
      wordx = "金"
    when 6
      self.contents.font.color = Color.new(155,50,36,255)
      wordx = "土"
    when 7
      self.contents.font.color = Color.new(55,244,246,255)
      wordx = "日"
    end
    self.contents.font.size = 22
    self.contents.font.name = ["楷体_GB2312","黑体"]
    self.contents.draw_text(224, 22, 128, 32, wordx)
    self.contents.font.color = Color.new(0,0,0,255)
    self.contents.draw_text(224+24, 22, 128, 32, "曜日")
   
    self.contents.font.size = 22
    self.contents.font.color = Color.new(0,0,0,255)
    # 描绘 时间
    tt = sprintf("%2d点%2d分", $game_map.date_hour,$game_map.date_minute)
    self.contents.draw_text(224, 0, 128, 32, tt)
  end #end refresh
  def update
    super
    # 刷新窗口
    if @fen_timedate != $game_map.date_minute
      refresh
    end
  end
end

class Game_Map
attr_accessor :date_minute
attr_accessor :date_hour
attr_accessor :date_day
attr_accessor :date_week
attr_accessor :date_season
attr_accessor :date_month
attr_accessor :date_year
# attr_reader   :every_month_days
attr_accessor :date_system_window_on_or_off
attr_accessor :weather1
attr_accessor :weather2
attr_accessor :waittime
def initialize
   @date_minute = 50
   @date_hour = 7
   @date_day = 1
   @date_week = 5
   @date_season = 4
   @date_month = 1
#   @data_month = 0
   @date_year = 0
#   @data_year = 0
   @date_system_window_on_or_off = true
   @weather1 = [false,0,0]
   @weather2 = [false,0,0]
   @waittime = [0,0]
end
end

class Scene_Map
# 主处理
alias main_old main
def main
    @b_window=Bank_Window.new
#    @b_window.index=@bank_index

    @gold_1_window=Window_Gold_1.new #yinhang的钱的窗口
    # 生成活动块
    @spriteset = Spriteset_Map.new
    @gold_window=Window_Gold.new
    @confirm_window=Window_Base.new(120, 88, 400, 64)
    @confirm_window.visible=false
   
    @yes_no_window = Window_Command.new(100, ["确定", "放弃"])
    @yes_no_window.x=120
    @yes_no_window.y=88+64
    @yes_no_window.visible=false
    @yes_no_window.active=false

   @tt = Window_TimeDate.new
   if $game_map.date_system_window_on_or_off == false
     @tt.visible = false
   end
   main_old
    @b_window.dispose
    @gold_window.dispose
    @confirm_window.dispose
    @yes_no_window.dispose
    @spriteset.dispose
    @gold_1_window.dispose
   @tt.dispose
end
# 更新
alias update_old update
def update
   if $game_map.date_system_window_on_or_off == false
     @tt.visible = false
   else
     @tt.visible = true
   end
   #----------------------
#   Date.change_screen_tone
   Date.run_date_system
#   Date.rand_weather_type
   #----------------------
   @tt.update
   update_old
    @gold_1_window.refresh
    @b_window.update
    if @b_window.active
      b_update
      return
    end
    if @yes_no_window.active
      confirm_update
      return
    end
   
end
  def b_update
    if Input.trigger?(Input::B)
      $scene=Scene_Map.new
    end
    if Input.trigger?(Input::C)
      if @b_window.index==0 #存钱
        @b_window.active=false
        @yes_no_window.active=true
      elsif @b_window.index==1#取钱
        @b_window.active=false
        @yes_no_window.active=true
      elsif @b_window.index==2#取消
        $scene=Scene_Map.new
      end
    end
  end
  def confirm_update
    @bank_index=@b_window.index
    @yes_no_window.active=true
    @yes_no_window.visible=true
    @yes_no_window.update
    @confirm_window.visible=true
    @confirm_window.contents=Bitmap.new(@confirm_window.width-32,
                                        @confirm_window.height-32)
    if @b_window.index==0
      @confirm_window.contents.draw_text(0,0,300,32,"想存钱?")
    elsif @b_window.index==1
      @confirm_window.contents.draw_text(0,0,300,32,"想取钱?")
    end
    if Input.trigger?(Input::B)
      $scene=Scene_Map.new
    end
    if Input.trigger?(Input::C)
      case @b_window.index
      when 0#存钱
        if @yes_no_window.index==0 #确定
          if $game_party.gold>10000
            $game_party.lose_gold(10000)
            @gold_window.refresh
            $game_party.gain_1_gold(10000)
            @gold_1_window.refresh
            $scene=Bank_Scene.new(@b_window.index)
          end
        else #放弃
          $scene=Bank_Scene.new(@b_window.index)
        end
      when 1#取钱
        if @yes_no_window.index==0 #确定
          if $game_party.gold_1>0
            $game_party.lose_1_gold(10000)
            @gold_1_window.refresh
            $game_party.gain_gold(10000)
            @gold_window.refresh
            $scene=Bank_Scene.new(@b_window.index)
          end
        else
          $scene=Bank_Scene.new(@b_window.index)
        end
      when 2#取消
        $scene=Bank_Scene.new(@b_window.index)
      end
    end
  end
end
上面的脚本本意是建立一个yinhang系统,yinhang的存钱随时间的变化而增加。我在地图上放了加钱的事件。我有几个问题:
1,上面的脚本身上的钱不增加了,为什么?
2,要达到随时间加钱,脚本应该怎么改?
3,一按B键就暴错,为什么?

Lv4.逐梦者

梦石
0
星屑
5680
在线时间
782 小时
注册时间
2019-1-20
帖子
191
2
发表于 2023-11-15 23:29:08 | 只看该作者
只给点建议什么的,不打算写,脑壳子痛... ...

1,上面的脚本身上的钱不增加了,为什么?
p一下就知道钱是有增加的,是漏了一个窗口的刷新
#----------------------
#   Date.change_screen_tone
   Date.run_date_system
#   Date.rand_weather_type
#----------------------
@tt.update
   update_old
    @gold_window.refresh #<--
    @gold_1_window.refresh
    @b_window.update

2,要达到随时间加钱,脚本应该怎么改?
你想想yh利息是怎么计算的就知道了,注意正确的起始与结束时间
yh钱虽然有显示增加,但是它是临时变量且没有地方调用,
公式也有点问题,超过一定量会归零

3,一按B键就暴错,为什么?
不要在地图里面搞yh呀,操作yh界面时人物能到处跑不奇怪吗?
单独做成Scene_yh吧

有调用Bank_Scene.new没有写Bank_Scene,是忘了贴还是没写?


点评

https://rpg.blue/forum.php?mod=viewthread&tid=494814&page=1#pid2983831 我还是看不懂,能帮我看下然后解释下吗?  发表于 2023-11-16 21:25
谢谢  发表于 2023-11-16 21:22

提高解答机会的方法:
看一下对应版本的帮助文件 看天气预报说今天不下雨
改变问题为更有可能的或常见的 如:天气自动变化下雨→天气系统 果然不准呀~
使用论坛的搜索功能查找相关问题 好丧啊... ...想看女装
清楚说明实际上你想解决的问题  想看坛友的女装  
脚本自己有改过的地方要标明  不要遮脸的
脚本有问题但不是默认的要全部贴出来 大胆点,尽情发
三包原则:包有BUG,包甩锅,包咕咕
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-30 10:00

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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