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

Project1

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

[交流讨论] 请教ACE大佬帮我看下重装机兵里面的贩售机脚本哪里没好

[复制链接]

Lv2.观梦者

梦石
0
星屑
791
在线时间
71 小时
注册时间
2023-12-26
帖子
105
跳转到指定楼层
1
发表于 2024-2-15 13:09:38 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 djs789783 于 2024-2-15 21:53 编辑

请教ACE大佬帮我看下重装机兵里面的贩售机脚本哪里没好

附工程案例。
,帮我弄下,发给我哈,谢谢你,新年快乐。
重装机兵里面的贩售机就是,固定可以买几样东西,还带抽奖。。。请问有没有类似这样的就是固定买几个东西,还能带抽奖的脚本?然后脚本上可以随便自己添加物品。

大佬帮我工程弄下发给我吗谢谢,或者发其它类似这样的工程案例让我学习学习。

==========================


#设置[0,3,0,500][分类,id,价格,]
module SH
  GBSE   = "Cursor2" #光标转动时播放的SE
  WINME  = "Victory1"  #中奖时播放的ME
  GBZDSD = 10  #光标转动的速度/帧 2帧转动一次
  ZSZDQS = 2   #抽奖至少转动几圈
  WBHDD  = 60  #抽奖完毕后,等待多少帧光标归零
end




#主调用方法
def 售货机(goods,prize=nil)
  $prize = prize
  #goods代表物品   prize代表奖品
  SceneManager.call(Scene_Shop_A)
  SceneManager.scene.prepare(goods, false)
end


#encoding:utf-8
#==============================================================================
# ■ Window_ShopNumber
#------------------------------------------------------------------------------
#  商店画面中,输入“物品买入/卖出数量”的窗口。
#==============================================================================

class Window_ShopNumber_S < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :number                   # 数量
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  def initialize(x, y, height)
    super(x, y, window_width, height)
    @item = nil
    @Max = 1
    @price = 0
    @number = 1
    @currency_unit = Vocab::currency_unit
  end
  #--------------------------------------------------------------------------
  # ● 获取窗口的宽度
  #--------------------------------------------------------------------------
  def window_width
    return 440
  end
  #--------------------------------------------------------------------------
  # ● 设置物品、最大值、价格、货币单位
  #--------------------------------------------------------------------------
  def set(item, max, price, currency_unit = nil)
    @item = item
    @max = max
    @price = price
    @currency_unit = currency_unit if currency_unit
    @number = 1
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 设置货币单位
  #--------------------------------------------------------------------------
  def currency_unit=(currency_unit)
    @currency_unit = currency_unit
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_item_name(@item, 0, item_y)
    draw_number
    draw_total_price
  end
  #--------------------------------------------------------------------------
  # ● 绘制数量
  #--------------------------------------------------------------------------
  def draw_number
    change_color(normal_color)
    draw_text(cursor_x - 28, item_y, 22, line_height, "×")
    draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
  end
  #--------------------------------------------------------------------------
  # ● 绘制总价
  #--------------------------------------------------------------------------
  def draw_total_price
    width = contents_width - 8
    draw_currency_value(@price * @number, @currency_unit, 4, price_y, width)
  end
  #--------------------------------------------------------------------------
  # ● 显示物品名称行的 Y 坐标
  #--------------------------------------------------------------------------
  def item_y
    contents_height / 2 - line_height * 3 / 2
  end
  #--------------------------------------------------------------------------
  # ● 显示价格行的 Y 坐标
  #--------------------------------------------------------------------------
  def price_y
    contents_height / 2 + line_height / 2
  end
  #--------------------------------------------------------------------------
  # ● 获取光标的宽度
  #--------------------------------------------------------------------------
  def cursor_width
    figures * 10 + 12
  end
  #--------------------------------------------------------------------------
  # ● 获取光标的 X 坐标
  #--------------------------------------------------------------------------
  def cursor_x
    contents_width - cursor_width - 4
  end
  #--------------------------------------------------------------------------
  # ● 获取数量显示的最大列数
  #--------------------------------------------------------------------------
  def figures
    return 2
  end
  #--------------------------------------------------------------------------
  # ● 更新画面
  #--------------------------------------------------------------------------
  def update
    super
    if active
      last_number = @number
      update_number
      if @number != last_number
        Sound.play_cursor
        refresh
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新数量
  #--------------------------------------------------------------------------
  def update_number
    change_number(1)   if Input.repeat?(:RIGHT)
    change_number(-1)  if Input.repeat?(:LEFT)
    change_number(10)  if Input.repeat?(:UP)
    change_number(-10) if Input.repeat?(:DOWN)
  end
  #--------------------------------------------------------------------------
  # ● 更改数量
  #--------------------------------------------------------------------------
  def change_number(amount)
    @number = [[@number + amount, @max].min, 1].max
  end
  #--------------------------------------------------------------------------
  # ● 更新光标
  #--------------------------------------------------------------------------
  def update_cursor
    cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
  end
end


#encoding:utf-8
#==============================================================================
# ■ Window_name
#------------------------------------------------------------------------------
#  物品名称的窗口
#==============================================================================

class Window_Name < Window_Base
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, window_height)
  end
  #--------------------------------------------------------------------------
  # ● 设置内容
  #--------------------------------------------------------------------------
  def set_text(text)
    if text != @text
      @text = text
      refresh
    end
  end
  #--------------------------------------------------------------------------
  # ● 获取窗口的宽度
  #--------------------------------------------------------------------------
  def window_width
    return 440-200
  end
  #--------------------------------------------------------------------------
  # ● 获取窗口的高度
  #--------------------------------------------------------------------------
  def window_height
    return 248
  end
  #--------------------------------------------------------------------------
  # ● 清除
  #--------------------------------------------------------------------------
  def clear
    set_text("")
  end
  #--------------------------------------------------------------------------
  # ● 设置物品
  #     item : 技能、物品等
  #--------------------------------------------------------------------------
  def set_item(item)
    set_text(item ? item.name : "")
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text_ex(4, 0, @text)
  end
end




###############################################################################


###############################################################################



#encoding:utf-8
#==============================================================================
# ■ Window_ShopBuy_A
#------------------------------------------------------------------------------
#  商店画面中,买入时显示所有商品的窗口。
#==============================================================================

class Window_ShopBuy_A < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :status_window            # 状态窗口
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  def initialize(x, y, height, shop_goods)
    super(100, 0, window_width, height)
    @shop_goods = shop_goods
    @money = 0
    refresh
    select(0)
  end
  
  #--------------------------------------------------------------------------
  # ● 获取窗口的宽度
  #--------------------------------------------------------------------------
  def window_width
    return (Graphics.width-200)
  end
  #--------------------------------------------------------------------------
  # ● 获取窗口的列数
  #--------------------------------------------------------------------------
  def col_max
    return 4
  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 && price(item) <= @money && !$game_party.item_max?(item)
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    make_item_list
    create_contents
    draw_all_items
  end
  #--------------------------------------------------------------------------
  # ● 生成商品列表
  #--------------------------------------------------------------------------
  def make_item_list
    @data = []
    @price = {}
    @shop_goods.each do |goods|
      case goods[0]
      when 0;  item = $data_items[goods[1]]
      when 1;  item = $data_weapons[goods[1]]
      when 2;  item = $data_armors[goods[1]]
      end
      if item
        @data.push(item)
        @price[item] = goods[2] == 0 ? item.price : goods[3]
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 绘制项目
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    rect = item_rect(index)
    draw_icon(item.icon_index, rect.x+35, rect.y-60, enable?(item))
    rect.width -= 4
    #rect.y += 130
    draw_text(rect, price(item), 1)
  end
  #--------------------------------------------------------------------------
  # ● 获取项目的绘制矩形
  #--------------------------------------------------------------------------
  def item_rect(index)
    rect = Rect.new
    rect.width = item_width
    rect.height = item_height
    rect.x = index % col_max * (item_width + spacing)
    rect.y = index / col_max * item_height +  130
    rect
  end
  #--------------------------------------------------------------------------
  # ● 更新帮助内容
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_item(item) if @help_window
  end
end




################################################################################





#encoding:utf-8
#==============================================================================
# ■ Scene_Shop_A
#------------------------------------------------------------------------------
#  商店画面
#==============================================================================

class Scene_Shop_A < Scene_MenuBase
  #--------------------------------------------------------------------------
  # ● 准备
  #--------------------------------------------------------------------------
  def prepare(goods, purchase_only)
    @goods = goods
    @purchase_only = purchase_only
  end
  #--------------------------------------------------------------------------
  # ● 开始处理
  #--------------------------------------------------------------------------
  def start
    super
    create_backgrond
    create_dummy_window
    create_number_window
    create_name_window
    create_buy_window
    create_gold_window
    command_buy
  end
  #--------------------------------------------------------------------------
  # ● 生成背景图
  #--------------------------------------------------------------------------
  def create_backgrond
    @backgrond = Sprite.new
    @backgrond.bitmap = Bitmap.new("Graphics/Pictures/贩卖机")
    @backgrond.x = 0
    @gb = Sprite.new
    @gb.bitmap = Bitmap.new("Graphics/Pictures/光标")
    @gb.ox = @gb.width / 2
    @gb.oy = +82
    @gb.x = 317
    @gb.y = [email protected]
  end
  #--------------------------------------------------------------------------
  # ● 生成金钱窗口
  #--------------------------------------------------------------------------
  def create_gold_window
    @gold_window = Window_Gold.new
    @gold_window.viewport = @viewport
    @gold_window.x = @buy_window.x + @buy_window.width - @gold_window.width
    @gold_window.y = @buy_window.y + @buy_window.height
    @gold_window.opacity = 0
  end
  #--------------------------------------------------------------------------
  # ● 生成名称窗口
  #--------------------------------------------------------------------------
  def create_name_window
    @name_window = Window_Name.new
    @name_window.x = 100
    @name_window.y = 200
    @name_window.opacity = 0
  end
  #--------------------------------------------------------------------------
  # ● 生成填充窗口
  #--------------------------------------------------------------------------
  def create_dummy_window
    wy = 120
    wh = Graphics.height - wy
    @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
    @dummy_window.viewport = @viewport
  end
  #--------------------------------------------------------------------------
  # ● 生成数值输入窗口
  #--------------------------------------------------------------------------
  def create_number_window
    wy = 0
    wh = 200
    @number_window = Window_ShopNumber_S.new(100, wy, wh)
    @number_window.viewport = @viewport
    @number_window.hide
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  #--------------------------------------------------------------------------
  # ● 生成买入窗口
  #--------------------------------------------------------------------------
  def create_buy_window
    wy = 0
    wh = 200
    @buy_window = Window_ShopBuy_A.new(0, wy, wh, @goods)
    @buy_window.viewport = @viewport
    @buy_window.help_window = @name_window
    @buy_window.set_handler(:ok,     method(:on_buy_ok))
    @buy_window.set_handler(:cancel, method(:on_buy_cancel))
    @buy_window.opacity = 0
  end
  #--------------------------------------------------------------------------
  # ● 启用买入窗口
  #--------------------------------------------------------------------------
  def activate_buy_window
    @buy_window.money = money
    @buy_window.show.activate
  end
  #--------------------------------------------------------------------------
  # ● 指令“买入”
  #--------------------------------------------------------------------------
  def command_buy
    @dummy_window.hide
    activate_buy_window
  end
  #--------------------------------------------------------------------------
  # ● 买入“确定”
  #--------------------------------------------------------------------------
  def on_buy_ok
    @item = @buy_window.item
    @buy_window.hide
    @number_window.set(@item, max_buy, buying_price, currency_unit)
    @number_window.show.activate
  end
  #--------------------------------------------------------------------------
  # ● 买入“取消”
  #--------------------------------------------------------------------------
  def on_buy_cancel
    return_scene
    #@backgrond.dispose
    #@backgrond.bitmap.dispose
  end

  #--------------------------------------------------------------------------
  # ● 数值输入“确定”
  #--------------------------------------------------------------------------
  def on_number_ok
    Sound.play_shop
    do_buy(@number_window.number)
    end_number_input
    @gold_window.refresh
  end
  #--------------------------------------------------------------------------
  # ● 数值输入“取消”
  #--------------------------------------------------------------------------
  def on_number_cancel
    Sound.play_cancel
    end_number_input
  end
  #--------------------------------------------------------------------------
  # ● 执行买入
  #--------------------------------------------------------------------------
  def do_buy(number)
    $game_party.lose_gold(number * buying_price)
    $game_party.gain_item(@item, number)
    ###抽奖系统放在这里
    抽奖
    ##################
  end
  #--------------------------------------------------------------------------
  # ● 买入后执行抽奖
  #--------------------------------------------------------------------------
  def 抽奖
    a =    SH::ZSZDQS * 8 + rand(17)
    a.times do
      Audio.se_play("Audio/SE/#{SH::GBSE}", 100, 100)
      @gb.angle -= 45
      Graphics.update
      Graphics.wait(SH::GBZDSD)
    end
    if a % 8 == 0
      Audio.me_play("Audio/ME/#{SH::WINME}", 100, 100)
      Graphics.wait(120)
      case $prize[0]
      when 1
        $game_party.gain_item($data_items[$prize[1]], $prize[2])
      when 2
        $game_party.gain_item($data_weapons[$prize[1]], $prize[2],true)
      when 3
        $game_party.gain_item($data_armors[$prize[1]], $prize[2],true)
      end
    else
    end
    Graphics.wait(SH::WBHDD)
    @gb.angle = 0
  end
  #--------------------------------------------------------------------------
  # ● 结束数值输入
  #--------------------------------------------------------------------------
  def end_number_input
    @number_window.hide
    activate_buy_window
  end
  #--------------------------------------------------------------------------
  # ● 获取可以买入的最大值
  #--------------------------------------------------------------------------
  def max_buy
    max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
    buying_price == 0 ? max : [max, money / buying_price].min
  end
  #--------------------------------------------------------------------------
  # ● 获取持有金钱
  #--------------------------------------------------------------------------
  def money
    @gold_window.value
  end
  #--------------------------------------------------------------------------
  # ● 获取货币单位
  #--------------------------------------------------------------------------
  def currency_unit
    @gold_window.currency_unit
  end
  #--------------------------------------------------------------------------
  # ● 获取买入价格
  #--------------------------------------------------------------------------
  def buying_price
    return 150 unless RPGBOY.check_item(@item)
    @buy_window.price(@item)
  end
end

==============================================================================


==================================

贩卖机.png (271.84 KB, 下载次数: 14)

贩卖机.png

冰箱.png (118.02 KB, 下载次数: 17)

冰箱.png

光标.png (2.97 KB, 下载次数: 17)

光标.png

脚本.zip

21.33 KB, 下载次数: 1

Lv3.寻梦者

梦石
0
星屑
3487
在线时间
885 小时
注册时间
2017-1-19
帖子
269
2
发表于 2024-2-17 15:10:38 | 只看该作者
这个固定买几个东西,还能带抽奖的脚本,这个脚本难道不可以吗?你说不会用就行了!!

事件脚本:
售货机([[0,1,1,1125],[0,2,1,35],[0,3,1,35],[0,31,1,35]],[1,7,1])

出售分类,ID,是否自定义,自定义价格

[出售分类]  0=物品,1=武器,2=防具

[ID]  就是物品,武器,防具的编号    0,1是指1号物品

[是否自定义] 0=原价 0=自定义价格

[自定义价格]    这个不用说了


0,1,1,1125指一号商品,商品是1号物品自定义价格1125

1,7,1是指中奖的奖品    分别代表 奖品分类,ID, 数量



               
回复 支持 1 反对 0

使用道具 举报

Lv2.观梦者

梦石
0
星屑
791
在线时间
71 小时
注册时间
2023-12-26
帖子
105
3
 楼主| 发表于 2024-2-17 15:18:27 | 只看该作者
shengfeng 发表于 2024-2-17 15:10
这个固定买几个东西,还能带抽奖的脚本,这个脚本难道不可以吗?你说不会用就行了!!

事件脚本:

谢谢,这个贴子好了,要怎么点已ok
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3487
在线时间
885 小时
注册时间
2017-1-19
帖子
269
4
发表于 2024-2-17 15:28:17 | 只看该作者
djs789783 发表于 2024-2-17 15:18
谢谢,这个贴子好了,要怎么点已ok

写错了

[是否自定义] 0=原价 1=自定义价格
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
791
在线时间
71 小时
注册时间
2023-12-26
帖子
105
5
 楼主| 发表于 2024-2-17 18:08:33 | 只看该作者
shengfeng 发表于 2024-2-17 15:28
写错了

[是否自定义] 0=原价 1=自定义价格

0是分类
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 07:12

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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