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

Project1

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

[已经解决] 使用雇佣脚本(人口贩卖)时出错

[复制链接]

Lv1.梦旅人

井蓝

梦石
0
星屑
58
在线时间
351 小时
注册时间
2011-1-14
帖子
277
跳转到指定楼层
1
发表于 2012-5-20 14:31:01 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 帕克 于 2012-5-20 17:39 编辑


出错显示为这个,我木有改过Game_Actors

这样调出的
a = [3]
$scene =\
Mercenaries::\
Scene_Mercenaries.new(a)

好吧,表示自行解决

脚本:

  1. module Mercenaries
  2.   class Window_Help < ::Window_Base
  3.     def initialize
  4.       super(0, 0, 196, 256)
  5.       self.contents = Bitmap.new(width - 32, height - 32)
  6.       self.contents.font.size = 18
  7.       @actor = nil
  8.       self.z += 10
  9.     end
  10.     def draw_actor(actor)
  11.       if @actor != actor
  12.         self.contents.clear
  13.         bitmap = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
  14.         bx = (self.width / 2) - bitmap.width / 2
  15.         by = (self.height / 2) - bitmap.height / 2
  16.         self.contents.blt(bx, by, bitmap, bitmap.rect, 196)
  17.         self.contents.draw_text(4, 4 + 0, 196, 18, "合约金:" + actor.price.to_s)
  18.         self.contents.draw_text(4, 4 + 20, 196, 18, "姓名:" + actor.name)
  19.         self.contents.draw_text(4, 4 + 40, 196, 18, "职业:" + actor.class_name)
  20. #~        self.contents.draw_text(4, 4 + 60, 196, 18, "武器:#{$data_weapons[actor.weapon_id].name}")
  21. #~        self.contents.draw_text(4, 4 + 80, 196, 18, "铠甲:#{$data_armors[actor.armor3_id].name}")
  22. #~        self.contents.draw_text(4, 4 + 100, 196, 18, "攻击力:#{actor.atk}")
  23. #~        self.contents.draw_text(4, 4 + 120, 196, 18, "防御力:#{actor.pdef}")
  24. #~        self.contents.draw_text(4, 4 + 140, 196, 18, "魔御力:#{actor.mdef}")
  25.         self.contents.draw_text(4, 4 + 60, 196, 18, "年薪:"+ actor.num.to_s)
  26.         self.contents.draw_text(4, 4 + 80, 196, 18, "硬件开发:#{actor.str}")
  27.         self.contents.draw_text(4, 4 + 100, 196, 18, "编程编程:#{actor.dex}")
  28.         self.contents.draw_text(4, 4 + 120, 196, 18, "外观设计:#{actor.agi}")
  29.         self.contents.draw_text(4, 4 + 140, 196, 18, "配件开发:#{actor.int}")
  30.         @actor = actor
  31.       end
  32.     end
  33.   end
  34.   class Window_ShopCommand < Window_Selectable
  35.     #--------------------------------------------------------------------------
  36.     # ● 初始化对像
  37.     #--------------------------------------------------------------------------
  38.     def initialize
  39.       super(80, 90 - 64, 480, 64)
  40.       self.contents = Bitmap.new(width - 32, height - 32)
  41.       @item_max = 3
  42.       @column_max = 3
  43.       @commands = ["雇佣", "解雇", "取消"]
  44.       refresh
  45.       self.index = 0
  46.     end
  47.     #--------------------------------------------------------------------------
  48.     # ● 刷新
  49.     #--------------------------------------------------------------------------
  50.     def refresh
  51.       self.contents.clear
  52.       for i in 0...@item_max
  53.         draw_item(i)
  54.       end
  55.     end
  56.     #--------------------------------------------------------------------------
  57.     # ● 描绘项目
  58.     #     index : 项目编号
  59.     #--------------------------------------------------------------------------
  60.     def draw_item(index)
  61.       x = 4 + index * 160
  62.       self.contents.draw_text(x, 0, 128, 32, @commands[index])
  63.     end
  64.   end
  65.   class Window_Mercenaries < ::Window_Selectable
  66.     attr_reader   :column_max
  67.     attr_reader   :item_max
  68.     attr_reader   :mercenaries
  69.     def initialize(mercenaries)
  70.       super(80, 90, 480, 320)
  71.       @mercenaries = mercenaries
  72.       @column_max = 7
  73.       refresh
  74.       self.index = 0
  75.     end
  76.     def set_mercenaries(mercenaries)
  77.       @mercenaries = mercenaries
  78.       refresh
  79.     end
  80.     def id
  81.       return @mercenaries[self.index]
  82.     end
  83.     def refresh
  84.       if self.contents != nil
  85.         self.contents.dispose
  86.         self.contents = nil
  87.       end
  88.       @item_max = @mercenaries.size
  89.       if @item_max > 0
  90.         self.contents = Bitmap.new(width - 32, row_max * 80)
  91.         for i in 0...@item_max
  92.           draw_actor(i)
  93.         end
  94.       end
  95.     end
  96.     def draw_actor(index)
  97.       x = 4 + (index % @column_max * 64)
  98.       y = 4 + (index / @column_max * 80)
  99.       actor = $game_actors[@mercenaries[index]]
  100.       bitmap = RPG::Cache.character(actor.character_name,actor.character_hue)
  101.       rect = bitmap.rect
  102.       rect.width /= 4
  103.       rect.height /= 4
  104.       self.contents.blt(x, y, bitmap, rect)
  105.       self.contents.font.size = 12
  106.       self.contents.draw_text(x, y + 64 - 8, 64, 16, actor.name)
  107.       self.contents.font.size = 9
  108.       self.contents.draw_text(x + 4, y + 64 - 16, 64, 9, "Lv."+sprintf("%02d", actor.level))
  109.     end
  110.     #--------------------------------------------------------------------------
  111.     # ● 更新光标举行
  112.     #--------------------------------------------------------------------------
  113.     def update_cursor_rect
  114.       # 光标位置不满 0 的情况下
  115.       if @index < 0
  116.         self.cursor_rect.empty
  117.         return
  118.       end
  119.       # 获取当前的行
  120.       row = @index / @column_max
  121.       # 当前行被显示开头行前面的情况下
  122.       if row < self.top_row
  123.         # 从当前行向开头行滚动
  124.         self.top_row = row
  125.       end
  126.       # 当前行被显示末尾行之后的情况下
  127.       if row > self.top_row + (self.page_row_max - 1)
  128.         # 从当前行向末尾滚动
  129.         self.top_row = row - (self.page_row_max - 1)
  130.       end
  131.       # 计算光标的宽
  132.       cursor_width = self.width / @column_max - 32
  133.       # 计算光标坐标
  134.       x = @index % @column_max * 64
  135.       y = @index / @column_max * 80 - self.oy
  136.       # 更新国标矩形
  137.       self.cursor_rect.set(x, y, 64, 80)
  138.     end
  139.   end
  140.   class Scene_Mercenaries
  141.     def initialize(mercenaries)
  142.       @mercenaries = mercenaries
  143.       for actor in $game_party.actors
  144.         if @mercenaries.include?(actor.id)
  145.           @mercenaries.delete(actor.id)
  146.         end
  147.       end
  148.       @windows = []
  149.       @temp = @mercenaries.dup
  150.       @type = -1
  151.     end
  152.     def main_start
  153.       make_window
  154.       @spriteset = Spriteset_Map.new
  155.     end
  156.     def main_loop
  157.       while $scene == self
  158.         rm_update
  159.         input_update
  160.         update_window
  161.       end
  162.     end
  163.     def main_end
  164.       dispose_window
  165.       @spriteset.dispose
  166.     end
  167.     def main
  168.       main_start
  169.       Graphics.transition
  170.       main_loop
  171.       Graphics.freeze
  172.       main_end
  173.     end
  174.     def make_window
  175.       @window_shopcommand = Window_ShopCommand.new
  176.       @window_help = Window_Help.new
  177.       @window_mercenaries = Window_Mercenaries.new(@mercenaries)
  178.       @window_mercenaries.active = false
  179.       @window_mercenaries.index = -1
  180.       wx = (@window_mercenaries.index % @window_mercenaries.column_max * 64)
  181.       wy = (@window_mercenaries.index / @window_mercenaries.column_max * 80)
  182.       @window_help.x = wx + @window_mercenaries.x + 64
  183.       @window_help.y = wy + @window_mercenaries.y + 80
  184.       @window_gold = Window_Gold.new
  185.       @window_gold.x = 640 - @window_gold.width - 32
  186.       @window_gold.y = 480 - @window_gold.height - 32
  187.       @windows << @window_gold << @window_shopcommand << @window_mercenaries << @window_help
  188.       @window_help.visible = false
  189.     end
  190.     def update_window
  191.       @windows.each{ |window|window.update }
  192.       help_update
  193.     end
  194.     def dispose_window
  195.       @windows.each{ |window|window.dispose }
  196.     end
  197.     def help_update
  198.       if @window_mercenaries.active
  199.         @window_help.visible = true
  200.         wx = (@window_mercenaries.index % @window_mercenaries.column_max * 64)
  201.         wy = (@window_mercenaries.index / @window_mercenaries.column_max * 80)
  202.         @window_help.x = wx + @window_mercenaries.x + 64
  203.         @window_help.y = wy + @window_mercenaries.y + 80
  204.         if @window_help.x + @window_help.width > 640
  205.           @window_help.x = 640 - @window_help.width
  206.         end
  207.         if @window_help.y + @window_help.height > 480
  208.           @window_help.y = 480 - @window_help.height
  209.         end
  210.         @window_help.draw_actor($game_actors[@window_mercenaries.id])
  211.       else
  212.         @window_help.visible = false
  213.       end
  214.     end
  215.     def input_update
  216.       if Input.trigger?(Input::B)
  217.         @type = -1
  218.         @window_shopcommand.active = true
  219.         @window_mercenaries.active = false
  220.         @window_mercenaries.index = -1
  221.         return
  222.       end
  223.       if Input.trigger?(Input::C)
  224.         if @window_shopcommand.active
  225.           case @window_shopcommand.index
  226.           when 0
  227.             @window_mercenaries.set_mercenaries(@temp)
  228.             @type = 0
  229.             @window_shopcommand.active = false
  230.             @window_mercenaries.active = true
  231.             @window_mercenaries.index = 0
  232.             return
  233.           when 1
  234.             actors = []
  235.             for actor in $game_party.actors
  236.               actors << actor.id
  237.             end
  238.             @window_mercenaries.set_mercenaries(actors)
  239.             @type = 1
  240.             @window_shopcommand.active = false
  241.             @window_mercenaries.active = true
  242.             @window_mercenaries.index = 0
  243.             return
  244.           when 2
  245.             $scene = Scene_Map.new
  246.             return
  247.           end
  248.         end
  249.         case @type
  250.         when 0
  251.           if $game_party.gold >= $game_actors[@window_mercenaries.id].price
  252.             if $game_party.actors.size < 4
  253.               $game_party.lose_gold($game_actors[@window_mercenaries.id].price)
  254.               $game_party.add_actor(@window_mercenaries.id)
  255.               @window_mercenaries.mercenaries.delete(@window_mercenaries.id)
  256.               @window_mercenaries.refresh
  257.               if @window_mercenaries.index > @window_mercenaries.mercenaries.size-1
  258.                 @window_mercenaries.index = @window_mercenaries.mercenaries.size-1
  259.               end
  260.             end
  261.           end
  262.         when 1
  263.           if @window_mercenaries.id != 1
  264.             $game_party.gain_gold($game_actors[@window_mercenaries.id].price / 2)
  265.             $game_party.remove_actor(@window_mercenaries.id)
  266.             @temp << @window_mercenaries.id
  267.             @window_mercenaries.mercenaries.delete(@window_mercenaries.id)
  268.             @window_mercenaries.refresh
  269.             if @window_mercenaries.index > @window_mercenaries.mercenaries.size-1
  270.               @window_mercenaries.index = @window_mercenaries.mercenaries.size-1
  271.             end
  272.           end
  273.         end
  274.         @window_gold.refresh
  275.       end
  276.     end
  277.     def rm_update
  278.       Graphics.update
  279.       Input.update
  280.     end
  281.   end
  282. end
  283. class Game_Actor
  284.   def price
  285.     price = @name.split(/,/)[1].nil? ? 0 : @name.split(/,/)[1].to_i
  286. #~    price2 = $game_variables[1]
  287.     return price * self.level
  288.   end
  289.   def num
  290.     num = @name.split(/,/)[2].nil? ? 0 : @name.split(/,/)[2].to_i
  291. #~    price2 = $game_variables[1]
  292.     return num * self.level
  293.   end
  294.   def name
  295.     return @name.split(/,/)[0]
  296.   end
  297. end
  298. class Game_System
  299.   attr_reader   :mercenaries
  300.   alias old_initialize initialize
  301.   def initialize
  302.     old_initialize
  303.     @mercenaries = {}
  304.   end
  305. end
复制代码

点评

LZ的文章分類設不試設錯了?應該是"有事請教"不是"已經解決"吧?  发表于 2012-5-21 19:51
貌似这脚本间接调用了Game_Player而module却是nil导致的  发表于 2012-5-20 17:07
我遇過同樣的問題...大概是LZ將可以雇用的人物全雇走了吧 似乎是雇用窗口裡的人物不能為空 為空會出錯 就像LZ的圖那樣...  发表于 2012-5-20 15:40

Lv1.梦旅人

梦·贤者

梦石
0
星屑
50
在线时间
1141 小时
注册时间
2007-12-15
帖子
4100
2
发表于 2012-5-20 15:10:22 | 只看该作者
光贴脚本,不说怎么操作的,是差不多哪里的问题的。
反正我测试是没问题。

点评

我就是这样做的,没发现问题。请上传有问题的工程。  发表于 2012-5-20 17:37
不可能没问题,我把脚本换到了新工程单独用都有问题  发表于 2012-5-20 17:35
http://rpg.blue/home.php?mod=space&uid=34951&do=blog&id=12799
回复

使用道具 举报

Lv1.梦旅人

井蓝

梦石
0
星屑
58
在线时间
351 小时
注册时间
2011-1-14
帖子
277
3
 楼主| 发表于 2012-5-20 17:25:15 | 只看该作者
果然是全部雇走了就有问题= =但怎么解决捏

点评

只剩最后一个人貌似不能雇佣吧  发表于 2012-5-20 17:32
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
49
在线时间
186 小时
注册时间
2012-5-8
帖子
987
4
发表于 2012-5-21 00:35:38 | 只看该作者
20行出错了吧--。
貌似是武器的问题..
看什么看,没看过大坑啊!
-------------------------炫翼-----------------------------
剧情:4%
地图:2%
系统:7%
优化:3%
脚本:25%
--------------------------炫翼----------------------------

      工作室


广告位招租....  
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-24 13:41

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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