查看: 2923|回复: 2

[已经解决] 关于掉宝

[复制链接]
梦石
0
星屑
17566
在线时间
4250 小时
注册时间
2013-7-18
回帖
2491
发表于 2017-2-8 10:47:21 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 y967 于 2017-2-8 11:26 编辑

如何实现一个怪物掉多个道具,这个已经有多格掉宝脚本了,问题是如何实现一个道具掉多个数量。

  1. class Scene_Battle
  2.   #--------------------------------------------------------------------------
  3.   # ● 开始结束战斗回合
  4.   #--------------------------------------------------------------------------
  5.   def start_phase5
  6.     # 转移到回合 5
  7.     @phase = 5
  8.     # 演奏战斗结束 ME
  9.     $game_system.me_play($game_system.battle_end_me)
  10.     # 还原为战斗开始前的 BGM
  11.     $game_system.bgm_play($game_temp.map_bgm)
  12.     # 初始化 EXP、金钱、宝物
  13.     exp = 0
  14.     gold = 0
  15.     treasures = []
  16.    
  17.     for enemy in $game_troop.enemies
  18.       unless enemy.hidden
  19.         
  20.         exp += $game_variables[13] * enemy.exp
  21.         gold += $game_variables[14] *enemy.gold
  22.         
  23.         if rand(100) < enemy.treasure_prob
  24.           if enemy.item_id > 0
  25.             treasures.push($data_items[enemy.item_id])
  26.           end
  27.           if enemy.weapon_id > 0
  28.             treasures.push($data_weapons[enemy.weapon_id])
  29.           end
  30.           if enemy.armor_id > 0
  31.             treasures.push($data_armors[enemy.armor_id])
  32.           end
  33.         end
  34.       end
  35.     end
  36.    
  37.     多格掉宝 = {} # 初始化
  38.    
  39.     # ---------------------------
  40.     # 多格掉宝 设置
  41.     # ---------------------------
  42.    
  43.     # 多格掉宝[敌人id] = [掉宝类型,id以及概率的数组]
  44.    
  45.     # 掉宝类型,id以及概率的数组 说明:
  46.     # 索引为 0 的值
  47.     # 0 是 物品 1 是武器 2 是防具
  48.     # 索引为 1 的值
  49.     # 物品 武器 防具 的 id
  50.     # 索引为 2 的值
  51.     # 概率
  52.    
  53.     # 设置范例
  54.    
  55.     多格掉宝[1] = [[0, 1, 18], [0, 2, 18]]
  56.     多格掉宝[2] = [[0, 27, 25]]
  57.    
  58.     多格掉宝[3] = [[0, 1, 18], [0, 2, 18]]
  59.     多格掉宝[4] = [[0, 27, 30]]
  60.     多格掉宝[5] = [[0, 35, 18]]
  61.     多格掉宝[6] = [[0, 35, 18]]
  62.     多格掉宝[7] = [[0, 35, 18]]
  63.     多格掉宝[8] = [[0, 35, 18]]
  64.     多格掉宝[9] = [[0, 35, 18],[0, 27, 18]]
  65.     多格掉宝[10] = [[0, 35, 18],[0, 27, 18]]
  66.    
  67.     多格掉宝[12] = [[0, 35, 18]]
  68.     多格掉宝[13] = [[0, 35, 18]]
  69.     多格掉宝[14] = [[0, 35, 18],[0, 27, 18]]
  70.     多格掉宝[15] = [[0, 35, 18]]
  71.     多格掉宝[16] = [[0, 35, 18]]
  72.     多格掉宝[19] = [[0, 35, 18],[0, 27, 16]]
  73.     多格掉宝[20] = [[0, 35, 18],[0, 27, 16]]
  74.     多格掉宝[21] = [[0, 35, 18],[0, 27, 16]]
  75.     多格掉宝[22] = [[0, 35, 18],[0, 27, 16]]
  76.     多格掉宝[23] = [[0, 35, 18],[0, 27, 16]]
  77.     多格掉宝[24] = [[0, 27, 42],[1, 23, 36],[0, 35, 18],[2, 40, 30]]
  78.   
  79.     多格掉宝[26] = [[0, 35, 18],[0, 27, 16]]
  80.     多格掉宝[27] = [[0, 35, 18],[0, 27, 16]]
  81.     多格掉宝[28] = [[0, 35, 18],[0, 27, 16]]
  82.     多格掉宝[29] = [[0, 35, 18],[0, 27, 16]]
  83.     多格掉宝[30] = [[0, 35, 18],[0, 27, 16]]
  84.     多格掉宝[31] = [[0, 35, 18],[0, 27, 16]]
  85.     多格掉宝[32] = [[0, 35, 18],[0, 27, 16]]
  86.    
  87.     多格掉宝[36] = [[0, 35, 18],[0, 27, 16]]
  88.     多格掉宝[37] = [[0, 35, 18],[0, 27, 16]]
  89.     多格掉宝[38] = [[0, 35, 18],[0, 27, 16]]
  90.     多格掉宝[39] = [[0, 35, 18],[0, 27, 16]]
  91.     多格掉宝[40] = [[0, 35, 18],[0, 27, 16]]
  92.     多格掉宝[41] = [[0, 35, 18],[0, 27, 16]]
  93.     多格掉宝[42] = [[0, 35, 18],[0, 27, 16]]
  94.     多格掉宝[43] = [[0, 35, 18],[0, 27, 16]]
  95.     多格掉宝[45] = [[0, 35, 18],[0, 27, 16]]
  96.     多格掉宝[46] = [[0, 35, 18],[0, 27, 16]]
  97.    
  98.    
  99.      case  $game_variables[4]
  100.    
  101.    when 0
  102.    
  103.    
  104.     多格掉宝[17] = [[0, 35, 18],[0, 27, 18],[0, 46, 33]]
  105.    
  106.    
  107.     多格掉宝[33] = [[1, 40, 40],[0, 52, 26],[2, 59, 40],[2, 62, 40],[0, 79, 26],[0, 80, 26],[0, 48, 20]]
  108.     多格掉宝[34] = [[1, 43, 40],[0, 53, 26],[2, 65, 40],[0, 81, 26],[0, 75, 26]]
  109.    
  110.     多格掉宝[47] = [[1, 49, 40],[0, 77, 26],[2, 68, 40],[0, 82, 26]]
  111.     多格掉宝[48] = [[1, 46, 40],[0, 76, 26],[0, 111, 50]]
  112.    
  113.     when 4
  114.       
  115.    
  116.     多格掉宝[17] = [[0, 35, 18],[0, 27, 18],[0, 47, 33]]
  117.     多格掉宝[33] = [[1, 40, 40],[0, 52, 26],[2, 59, 40],[2, 62, 40],[0, 79, 26],[0, 80, 26],[0, 113, 26],[0, 48, 20]]
  118.     多格掉宝[34] = [[1, 43, 40],[0, 53, 26],[2, 65, 40],[0, 81, 26],[0, 110, 26]]
  119.     多格掉宝[47] = [[1, 49, 40],[0, 77, 26],[2, 68, 40],[0, 82, 26],[0, 90, 20]]
  120.     多格掉宝[48] = [[1, 46, 40],[0, 76, 26],[0, 112, 50]]
  121.    
  122.   end
  123.   
  124.   
  125.     # ----------------------------------------
  126.     for enemy in $game_troop.enemies
  127.     unless enemy.hidden
  128.     if 多格掉宝[enemy.id] != nil
  129.        for i in 多格掉宝[enemy.id]
  130.           概率 = i[2]
  131.           case i[0]
  132.           when 0 # 物品
  133.             if rand(100) < 概率
  134.               if $data_items[i[1]] != nil
  135.                 treasures.push($data_items[i[1]])
  136.               end
  137.             end
  138.           when 1 # 武器
  139.             if rand(100) < 概率
  140.               if $data_weapons[i[1]] != nil
  141.                 treasures.push($data_weapons[i[1]])
  142.               end
  143.             end
  144.           when 2 # 防具
  145.             if rand(100) < 概率
  146.               if $data_armors[i[1]] != nil
  147.                 treasures.push($data_armors[i[1]])
  148.               end
  149.             end
  150.           end
  151.        end
  152.     end
  153.     end
  154.     end
  155.     # ----------------------------------------
  156.     for i in 0...$game_party.actors.size
  157.       actor = $game_party.actors[i]
  158.       if actor.cant_get_exp? == false
  159.         last_level = actor.level
  160.         actor.exp +=  exp
  161.         if actor.level > last_level
  162.           @status_window.level_up(i)
  163.         end
  164.       end
  165.     end
  166.     # 获得金钱
  167.     $game_party.gain_gold(gold)
  168.     # 获得宝物
  169.     for item in treasures
  170.       case item
  171.       when RPG::Item
  172.         $game_party.gain_item(item.id, 1)
  173.       when RPG::Weapon
  174.         $game_party.gain_weapon(item.id, 1)
  175.       when RPG::Armor
  176.         $game_party.gain_armor(item.id, 1)
  177.       end
  178.     end
  179.     # 生成战斗结果窗口
  180.     @result_window = Window_BattleResult.new(exp, gold, treasures)
  181.     # 设置等待计数
  182.     @phase5_wait_count = 0
  183.   end
  184. end
复制代码
退隐....
梦石
0
星屑
1788
在线时间
1313 小时
注册时间
2012-8-4
回帖
724
发表于 2017-2-8 13:04:06 | 显示全部楼层
本帖最后由 夜狠简单 于 2017-2-8 20:37 编辑

没有测试,有问题点评提醒我
  1. class Scene_Battle
  2.   #--------------------------------------------------------------------------
  3.   # ● 开始结束战斗回合
  4.   #--------------------------------------------------------------------------
  5.   def start_phase5
  6.     # 转移到回合 5
  7.     @phase = 5
  8.     # 演奏战斗结束 ME
  9.     $game_system.me_play($game_system.battle_end_me)
  10.     # 还原为战斗开始前的 BGM
  11.     $game_system.bgm_play($game_temp.map_bgm)
  12.     # 初始化 EXP、金钱、宝物
  13.     exp = 0
  14.     gold = 0
  15.     treasures = []

  16.     for enemy in $game_troop.enemies
  17.       unless enemy.hidden

  18.         exp += $game_variables[13] * enemy.exp
  19.         gold += $game_variables[14] *enemy.gold

  20.         if rand(100) < enemy.treasure_prob
  21.           if enemy.item_id > 0
  22.             treasures.push($data_items[enemy.item_id])
  23.           end
  24.           if enemy.weapon_id > 0
  25.             treasures.push($data_weapons[enemy.weapon_id])
  26.           end
  27.           if enemy.armor_id > 0
  28.             treasures.push($data_armors[enemy.armor_id])
  29.           end
  30.         end
  31.       end
  32.     end
  33.   for item in treasures
  34.       case item
  35.       when RPG::Item
  36.         $game_party.gain_item(item.id, 1)
  37.       when RPG::Weapon
  38.         $game_party.gain_weapon(item.id, 1)
  39.       when RPG::Armor
  40.         $game_party.gain_armor(item.id, 1)
  41.       end
  42.     end
  43.     多格掉宝 = {} # 初始化

  44.     # ---------------------------
  45.     # 多格掉宝 设置
  46.     # ---------------------------

  47.     # 多格掉宝[敌人id] = [掉宝类型,id以及概率的数组]

  48.     # 掉宝类型,id以及概率的数组 说明:
  49.     # 索引为 0 的值
  50.     # 0 是 物品 1 是武器 2 是防具
  51.     # 索引为 1 的值
  52.     # 物品 武器 防具 的 id
  53.     # 索引为 2 的值
  54.     # 概率

  55.     # 设置范例

  56.     多格掉宝[1] = [[0, 1, 100,10], [0, 2, 100]] #物品1每次掉落10个,物品2掉1个
  57.     多格掉宝[2] = [[0, 27, 100,rand(3)+1]]#物品27随机掉1~3个

  58.     多格掉宝[3] = [[0, 1, 18], [0, 2, 18]]
  59.     多格掉宝[4] = [[0, 27, 30]]
  60.     多格掉宝[5] = [[0, 35, 18]]
  61.     多格掉宝[6] = [[0, 35, 18]]
  62.     多格掉宝[7] = [[0, 35, 18]]
  63.     多格掉宝[8] = [[0, 35, 18]]
  64.     多格掉宝[9] = [[0, 35, 18],[0, 27, 18]]
  65.     多格掉宝[10] = [[0, 35, 18],[0, 27, 18]]

  66.     多格掉宝[12] = [[0, 35, 18]]
  67.     多格掉宝[13] = [[0, 35, 18]]
  68.     多格掉宝[14] = [[0, 35, 18],[0, 27, 18]]
  69.     多格掉宝[15] = [[0, 35, 18]]
  70.     多格掉宝[16] = [[0, 35, 18]]
  71.     多格掉宝[19] = [[0, 35, 18],[0, 27, 16]]
  72.     多格掉宝[20] = [[0, 35, 18],[0, 27, 16]]
  73.     多格掉宝[21] = [[0, 35, 18],[0, 27, 16]]
  74.     多格掉宝[22] = [[0, 35, 18],[0, 27, 16]]
  75.     多格掉宝[23] = [[0, 35, 18],[0, 27, 16]]
  76.     多格掉宝[24] = [[0, 27, 42],[1, 23, 36],[0, 35, 18],[2, 40, 30]]

  77.     多格掉宝[26] = [[0, 35, 18],[0, 27, 16]]
  78.     多格掉宝[27] = [[0, 35, 18],[0, 27, 16]]
  79.     多格掉宝[28] = [[0, 35, 18],[0, 27, 16]]
  80.     多格掉宝[29] = [[0, 35, 18],[0, 27, 16]]
  81.     多格掉宝[30] = [[0, 35, 18],[0, 27, 16]]
  82.     多格掉宝[31] = [[0, 35, 18],[0, 27, 16]]
  83.     多格掉宝[32] = [[0, 35, 18],[0, 27, 16]]

  84.     多格掉宝[36] = [[0, 35, 18],[0, 27, 16]]
  85.     多格掉宝[37] = [[0, 35, 18],[0, 27, 16]]
  86.     多格掉宝[38] = [[0, 35, 18],[0, 27, 16]]
  87.     多格掉宝[39] = [[0, 35, 18],[0, 27, 16]]
  88.     多格掉宝[40] = [[0, 35, 18],[0, 27, 16]]
  89.     多格掉宝[41] = [[0, 35, 18],[0, 27, 16]]
  90.     多格掉宝[42] = [[0, 35, 18],[0, 27, 16]]
  91.     多格掉宝[43] = [[0, 35, 18],[0, 27, 16]]
  92.     多格掉宝[45] = [[0, 35, 18],[0, 27, 16]]
  93.     多格掉宝[46] = [[0, 35, 18],[0, 27, 16]]


  94.      case  $game_variables[4]

  95.    when 0


  96.     多格掉宝[17] = [[0, 35, 18],[0, 27, 18],[0, 46, 33]]


  97.     多格掉宝[33] = [[1, 40, 40],[0, 52, 26],[2, 59, 40],[2, 62, 40],[0, 79, 26],[0, 80, 26],[0, 48, 20]]
  98.     多格掉宝[34] = [[1, 43, 40],[0, 53, 26],[2, 65, 40],[0, 81, 26],[0, 75, 26]]

  99.     多格掉宝[47] = [[1, 49, 40],[0, 77, 26],[2, 68, 40],[0, 82, 26]]
  100.     多格掉宝[48] = [[1, 46, 40],[0, 76, 26],[0, 111, 50]]

  101.     when 4


  102.     多格掉宝[17] = [[0, 35, 18],[0, 27, 18],[0, 47, 33]]
  103.     多格掉宝[33] = [[1, 40, 40],[0, 52, 26],[2, 59, 40],[2, 62, 40],[0, 79, 26],[0, 80, 26],[0, 113, 26],[0, 48, 20]]
  104.     多格掉宝[34] = [[1, 43, 40],[0, 53, 26],[2, 65, 40],[0, 81, 26],[0, 110, 26]]
  105.     多格掉宝[47] = [[1, 49, 40],[0, 77, 26],[2, 68, 40],[0, 82, 26],[0, 90, 20]]
  106.     多格掉宝[48] = [[1, 46, 40],[0, 76, 26],[0, 112, 50]]

  107.   end


  108.     # ----------------------------------------
  109.     for enemy in $game_troop.enemies
  110.     unless enemy.hidden
  111.     if 多格掉宝[enemy.id]
  112.        for i in 多格掉宝[enemy.id]
  113.           概率 = i[2]
  114.           case i[0]
  115.           when 0 # 物品
  116.             if rand(100) < 概率
  117.               if $data_items[i[1]] != nil
  118.                 treasures.push($data_items[i[1]])
  119.                 i[3]?$game_party.gain_item(i[1], i[3]):
  120.                 $game_party.gain_item(i[1], 1)
  121.               end
  122.             end
  123.           when 1 # 武器
  124.             if rand(100) < 概率
  125.               if $data_weapons[i[1]] != nil
  126.                 treasures.push($data_weapons[i[1]])
  127.                 i[3]?$game_party.gain_weapon(i[1], i[3]):
  128.                 $game_party.gain_weapon(i[1], 1)
  129.               end
  130.             end
  131.           when 2 # 防具
  132.             if rand(100) < 概率
  133.               if $data_armors[i[1]] != nil
  134.                 treasures.push($data_armors[i[1]])
  135.                 i[3]?$game_party.gain_armor(i[1], i[3]):
  136.                 $game_party.gain_armor(i[1], 1)
  137.               end
  138.             end
  139.           end
  140.        end
  141.     end
  142.     end
  143.     end
  144.     # ----------------------------------------
  145.     for i in 0...$game_party.actors.size
  146.       actor = $game_party.actors[i]
  147.       if actor.cant_get_exp? == false
  148.         last_level = actor.level
  149.         actor.exp +=  exp
  150.         if actor.level > last_level
  151.           @status_window.level_up(i)
  152.         end
  153.       end
  154.     end
  155.     # 获得金钱
  156.     $game_party.gain_gold(gold)
  157.     # 生成战斗结果窗口
  158.     @result_window = Window_BattleResult.new(exp, gold, treasures)
  159.     # 设置等待计数
  160.     @phase5_wait_count = 0
  161.   end
  162. end
复制代码

点评

解决了,大榭  发表于 2017-2-8 14:19

评分

参与人数 2星屑 +45 梦石 +1 收起 理由
RyanBern + 1 认可答案
y967 + 45 认可答案

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部