查看: 2286|回复: 4

[已经过期] 请教个人物跟随脚本的问题

[复制链接]
梦石
0
星屑
52
在线时间
586 小时
注册时间
2012-5-31
回帖
711
发表于 2012-12-22 13:07:43 | 显示全部楼层 |阅读模式

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

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

×
  1. # ————————————————————————————————————

  2. # ▼▲▼ XRXS13. パーティ列車移動 ver.1.02 ▼▲▼
  3. #
  4. # Train_Actor
  5. #
  6. #

  7. module Train_Actor




  8. #是否使用停止跟随的方法,也就是说,这里false改为true的时候,如果TRANSPARENT_SWITCHES_INDEX
  9. #开关打开,跟随的人物就消失了(其实只是变成透明而已)
  10. TRANSPARENT_SWITCH = false
  11. TRANSPARENT_SWITCHES_INDEX = 20
  12. #举例:第一个为true,第二个为20,则打开20号开关,后面的人都没了。





  13. #跟随人数的最大数目,可以更改为2、3什么的。
  14. TRAIN_ACTOR_SIZE_MAX = 5





  15. # 定数
  16. #Input::DOWN = 2
  17. #Input::LEFT = 4
  18. #Input::RIGHT = 6
  19. #Input::UP = 6
  20. DOWN_LEFT = 1
  21. DOWN_RIGHT = 3
  22. UP_LEFT = 7
  23. UP_RIGHT = 9
  24. JUMP = 5
  25. #==============================================================================
  26. # ■ Game_Party_Actor
  27. #------------------------------------------------------------------------------
  28. #  
  29. #==============================================================================
  30. class Game_Party_Actor < Game_Character
  31. attr :name
  32. def initialize
  33.   
  34. super()
  35. @x = $game_player.x
  36. @y = $game_player.y
  37. @through = true
  38. end
  39. def setup(actor)
  40. # キャラクターのファイル名と色相を設定
  41. if actor != nil
  42. if $game_player.moving?
  43. @character_name = actor.character_name
  44. else
  45. if actor.id < 30
  46. @character_name = actor.character_name + "_W1"
  47. else
  48. @character_name = actor.character_name
  49. end
  50. end
  51. @character_hue = actor.character_hue
  52. @tempneme = actor.name
  53. else
  54. @character_name = ""
  55. @character_hue = 0
  56. @tempneme = ""
  57. end
  58. # 不透明度と合成方法を初期化
  59. [url=home.php?mod=space&uid=316553]@opacity[/url] = 255
  60. @blend_type = 0
  61. end
  62. def screen_z(height = 0)
  63. if $game_player.x == @x and $game_player.y == @y
  64. return $game_player.screen_z(height) - 1
  65. end
  66. super(height)
  67. end
  68.     def name
  69.         return @tempneme
  70.       end
  71. #--------------------------------------------------------------------------
  72. # ● 下に移動
  73. # turn_enabled : その場での向き変更を許可するフラグ
  74. #--------------------------------------------------------------------------
  75. def move_down(turn_enabled = true)
  76.   # 下を向く
  77.   if turn_enabled
  78.     turn_down
  79.   end
  80.   # 通行可能な場合
  81.   if passable?(@x, @y, Input::DOWN)
  82.     # 下を向く
  83.     turn_down
  84.     # 座標を更新
  85.     @y += 1
  86.     increase_steps
  87.   end
  88. end
  89. #--------------------------------------------------------------------------
  90. # ● 左に移動
  91. # turn_enabled : その場での向き変更を許可するフラグ
  92. #--------------------------------------------------------------------------
  93. def move_left(turn_enabled = true)
  94.   # 左を向く
  95.   if turn_enabled
  96.     turn_left
  97.   end
  98.   # 通行可能な場合
  99.   if passable?(@x, @y, Input::LEFT)
  100.     # 左を向く
  101.     turn_left
  102.     # 座標を更新
  103.     @x -= 1
  104.     increase_steps
  105.   end
  106. end
  107. #--------------------------------------------------------------------------
  108. # ● 右に移動
  109. # turn_enabled : その場での向き変更を許可するフラグ
  110. #--------------------------------------------------------------------------
  111. def move_right(turn_enabled = true)
  112.   # 右を向く
  113.   if turn_enabled
  114.     turn_right
  115.   end
  116.   # 通行可能な場合
  117.   if passable?(@x, @y, Input::RIGHT)
  118.     # 右を向く
  119.     turn_right
  120.     # 座標を更新
  121.     @x += 1
  122.     increase_steps
  123.   end
  124. end
  125. #--------------------------------------------------------------------------
  126. # ● 上に移動
  127. # turn_enabled : その場での向き変更を許可するフラグ
  128. #--------------------------------------------------------------------------
  129. def move_up(turn_enabled = true)
  130.   # 上を向く
  131.   if turn_enabled
  132.     turn_up
  133.   end
  134.   # 通行可能な場合
  135.   if passable?(@x, @y, Input::UP)
  136.     # 上を向く
  137.     turn_up
  138.     # 座標を更新
  139.     @y -= 1
  140.     increase_steps
  141.   end
  142. end
  143. #--------------------------------------------------------------------------
  144. # ● 左下に移動
  145. #--------------------------------------------------------------------------
  146. def move_lower_left
  147.   # 向き固定でない場合
  148.   unless @direction_fix
  149.     # 右向きだった場合は左を、上向きだった場合は下を向く
  150.     @direction = 1
  151.   end
  152.   # 下→左、左→下 のどちらかのコースが通行可能な場合
  153.   if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  154.      (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  155.     # 座標を更新
  156.     @x -= 1
  157.     @y += 1
  158.     increase_steps
  159.   end
  160. end
  161. #--------------------------------------------------------------------------
  162. # ● 右下に移動
  163. #--------------------------------------------------------------------------
  164. def move_lower_right
  165.   # 向き固定でない場合
  166.   unless @direction_fix
  167.     # 左向きだった場合は右を、上向きだった場合は下を向く
  168.     @direction = 3
  169.   end
  170.   # 下→右、右→下 のどちらかのコースが通行可能な場合
  171.   if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  172.      (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  173.     # 座標を更新
  174.     @x += 1
  175.     @y += 1
  176.     increase_steps
  177.   end
  178. end
  179. #--------------------------------------------------------------------------
  180. # ● 左上に移動
  181. #--------------------------------------------------------------------------
  182. def move_upper_left
  183.   # 向き固定でない場合
  184.   unless @direction_fix
  185.     # 右向きだった場合は左を、下向きだった場合は上を向く
  186.     @direction = 7
  187.   end
  188.   # 上→左、左→上 のどちらかのコースが通行可能な場合
  189.   if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  190.      (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  191.     # 座標を更新
  192.     @x -= 1
  193.     @y -= 1
  194.     increase_steps
  195.   end
  196. end
  197. #--------------------------------------------------------------------------
  198. # ● 右上に移動
  199. #--------------------------------------------------------------------------
  200. def move_upper_right
  201.   # 向き固定でない場合
  202.   unless @direction_fix
  203.     # 左向きだった場合は右を、下向きだった場合は上を向く
  204.     @direction = 9
  205.   end
  206.   # 上→右、右→上 のどちらかのコースが通行可能な場合
  207.   if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  208.      (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  209.     # 座標を更新
  210.     @x += 1
  211.     @y -= 1
  212.     increase_steps
  213.   end
  214. end
  215. attr_writer :move_speed
  216. attr_writer :step_anime
  217. end
  218. #==============================================================================
  219. # ■ Spriteset_Map_Module
  220. #------------------------------------------------------------------------------
  221. #  
  222. #==============================================================================
  223. module Spriteset_Map_Module
  224. def setup_actor_character_sprites?
  225.   return @setup_actor_character_sprites_flag != nil
  226. end
  227. def setup_actor_character_sprites(characters)
  228.   if !setup_actor_character_sprites?
  229.     index_game_player = 0
  230.     @character_sprites.each_index do |i|
  231.       if @character_sprites[i].character.instance_of?(Game_Player)
  232.         index_game_player = i
  233.         break
  234.       end
  235.     end
  236.     for character in characters.reverse
  237.       @character_sprites.unshift(
  238.        Sprite_Character.new(@viewport1, character)
  239.        )
  240.     end
  241.     @setup_actor_character_sprites_flag = true
  242.   end
  243. end
  244. end
  245. #==============================================================================
  246. # ■ Scene_Map_Module
  247. #------------------------------------------------------------------------------
  248. #  
  249. #==============================================================================
  250. module Scene_Map_Module
  251. def setup_actor_character_sprites(characters)
  252.   @spriteset.setup_actor_character_sprites(characters)
  253. end
  254. end
  255. #==============================================================================
  256. # ■ Game_Party_Module
  257. #------------------------------------------------------------------------------
  258. #  
  259. #==============================================================================
  260. module Game_Party_Module
  261. def return_char(i)
  262. return @characters[i]
  263. end
  264. def set_transparent_actors(transparent)
  265.   @transparent = transparent
  266. end
  267. def setup_actor_character_sprites
  268.   if @characters == nil
  269.     @characters = []
  270.     for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  271.       @characters.push(Game_Party_Actor.new)
  272.     end
  273.   end
  274.   for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  275.     @characters[i - 1].setup(actors[i])
  276.   end
  277.   if $scene.class.method_defined?('setup_actor_character_sprites')
  278.     $scene.setup_actor_character_sprites(@characters)
  279.   end
  280. end
  281. def update_party_actors
  282.   setup_actor_character_sprites
  283.   transparent = $game_player.transparent
  284.   if transparent == false
  285.     if TRANSPARENT_SWITCH
  286.       transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX]
  287.     end
  288.   end
  289.   for character in @characters
  290.     character.transparent = transparent
  291.     character.move_speed = $game_player.move_speed
  292.       character.step_anime = $game_player.step_anime
  293.     character.update
  294.   end
  295. end
  296. def moveto_party_actors( x, y )
  297.   setup_actor_character_sprites
  298.   for character in @characters
  299.     character.moveto( x, y )
  300.   end
  301.   if @move_list == nil
  302.     @move_list = []
  303.   end
  304.   move_list_setup
  305. end
  306. def move_party_actors
  307.   if @move_list == nil
  308.     @move_list = []
  309.     move_list_setup
  310.   end
  311.   @move_list.each_index do |i|
  312.   if @characters[i] != nil
  313.     case @move_list[i].type
  314.     when Input::DOWN
  315.       @characters[i].move_down(@move_list[i].args[0])
  316.     when Input::LEFT
  317.       @characters[i].move_left(@move_list[i].args[0])
  318.     when Input::RIGHT
  319.       @characters[i].move_right(@move_list[i].args[0])
  320.     when Input::UP
  321.       @characters[i].move_up(@move_list[i].args[0])
  322.     when DOWN_LEFT
  323.       @characters[i].move_lower_left
  324.     when DOWN_RIGHT
  325.       @characters[i].move_lower_right
  326.     when UP_LEFT
  327.       @characters[i].move_upper_left
  328.     when UP_RIGHT
  329.       @characters[i].move_upper_right
  330.     when JUMP
  331.       @characters[i].jump(@move_list[i].args[0],@move_list[i].args[1])
  332.     end
  333.   end
  334. end
  335. end
  336. #==============================================================================
  337. # ■ Move_List_Element
  338. #------------------------------------------------------------------------------
  339. #  
  340. #==============================================================================
  341. class Move_List_Element
  342.   def initialize(type,args)
  343.     @type = type
  344.     @args = args
  345.   end
  346.   def type()
  347.     return @type
  348.   end
  349.   def args()
  350.     return @args
  351.   end
  352. end
  353. def move_list_setup
  354.   for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  355.     @move_list[i] = nil
  356.   end
  357. end
  358. def add_move_list(type,*args)
  359.   @move_list.unshift(Move_List_Element.new(type,args)).pop
  360. end
  361. def move_down_party_actors(turn_enabled = true)
  362.   move_party_actors
  363.   add_move_list(Input::DOWN,turn_enabled)
  364. end
  365. def move_left_party_actors(turn_enabled = true)
  366.   move_party_actors
  367.   add_move_list(Input::LEFT,turn_enabled)
  368. end
  369. def move_right_party_actors(turn_enabled = true)
  370.   move_party_actors
  371.   add_move_list(Input::RIGHT,turn_enabled)
  372. end
  373. def move_up_party_actors(turn_enabled = true)
  374.   move_party_actors
  375.   add_move_list(Input::UP,turn_enabled)
  376. end
  377. def move_lower_left_party_actors
  378.   move_party_actors
  379.   add_move_list(DOWN_LEFT)
  380. end
  381. def move_lower_right_party_actors
  382.   move_party_actors
  383.   add_move_list(DOWN_RIGHT)
  384. end
  385. def move_upper_left_party_actors
  386.   move_party_actors
  387.   add_move_list(UP_LEFT)
  388. end
  389. def move_upper_right_party_actors
  390.   move_party_actors
  391.   add_move_list(UP_RIGHT)
  392. end
  393. def jump_party_actors(x_plus, y_plus)
  394.   move_party_actors
  395.   add_move_list(JUMP,x_plus, y_plus)
  396. end
  397. end
  398. module Game_Player_Module
  399. def update
  400.   $game_party.update_party_actors
  401.   super
  402. end
  403. def moveto( x, y )
  404.   $game_party.moveto_party_actors( x, y )
  405.   super( x, y )
  406. end
  407. def move_down(turn_enabled = true)
  408.   if passable?(@x, @y, Input::DOWN)
  409.     $game_party.move_down_party_actors(turn_enabled)

  410.   end
  411.   super(turn_enabled)
  412. end
  413. def move_left(turn_enabled = true)
  414.   if passable?(@x, @y, Input::LEFT)
  415.     $game_party.move_left_party_actors(turn_enabled)
  416.   end
  417.   super(turn_enabled)
  418. end
  419. def move_right(turn_enabled = true)
  420.   if passable?(@x, @y, Input::RIGHT)
  421.     $game_party.move_right_party_actors(turn_enabled)
  422.   end
  423.   super(turn_enabled)
  424. end
  425. def move_up(turn_enabled = true)
  426.   if passable?(@x, @y, Input::UP)
  427.     $game_party.move_up_party_actors(turn_enabled)
  428.   end
  429.   super(turn_enabled)
  430. end
  431. def move_lower_left
  432.   # 下→左、左→下 のどちらかのコースが通行可能な場合
  433.   unless @direction_fix
  434.     @direction = 1
  435.   end
  436.   if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  437.      (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  438.     $game_party.move_lower_left_party_actors
  439.     increase_steps
  440.   end
  441.   super
  442. end
  443. def move_lower_right
  444.   # 下→右、右→下 のどちらかのコースが通行可能な場合
  445.   unless @direction_fix
  446.     @direction = 3
  447.   end
  448.   if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  449.      (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  450.     $game_party.move_lower_right_party_actors
  451.     increase_steps
  452.   end
  453.   super
  454. end
  455. def move_upper_left
  456.   # 上→左、左→上 のどちらかのコースが通行可能な場合
  457.   unless @direction_fix
  458.     @direction = 7
  459.   end
  460.   if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  461.      (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  462.     $game_party.move_upper_left_party_actors
  463.     increase_steps
  464.     end
  465.   super
  466. end
  467. def move_upper_right
  468.   # 上→右、右→上 のどちらかのコースが通行可能な場合
  469.   unless @direction_fix
  470.     @direction = 9
  471.   end
  472.   if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  473.      (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  474.     $game_party.move_upper_right_party_actors
  475.     increase_steps

  476.   end
  477.   super
  478. end
  479. def jump(x_plus, y_plus)
  480.   # 新しい座標を計算
  481.   new_x = @x + x_plus
  482.   new_y = @y + y_plus
  483.   # 加算値が (0,0) の場合か、ジャンプ先が通行可能な場合
  484.   if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  485.     $game_party.jump_party_actors(x_plus, y_plus)
  486.   end
  487.   super(x_plus, y_plus)
  488. end
  489. attr_reader :move_speed
  490. attr_reader :step_anime
  491. end
  492. end # module Train_Actor
  493. #==============================================================================
  494. # ■ Game_Party
  495. #------------------------------------------------------------------------------
  496. #  
  497. #==============================================================================
  498. class Game_Party
  499.   include Train_Actor::Game_Party_Module
  500. end
  501. #==============================================================================
  502. # ■ Game_Player
  503. #------------------------------------------------------------------------------
  504. #  
  505. #==============================================================================
  506. class Game_Player
  507.   include Train_Actor::Game_Player_Module
  508. end
  509. #==============================================================================
  510. # ■ Spriteset_Map
  511. #------------------------------------------------------------------------------
  512. #  
  513. #==============================================================================
  514. class Spriteset_Map
  515.   include Train_Actor::Spriteset_Map_Module
  516. end
  517. #==============================================================================
  518. # ■ Scene_Map
  519. #------------------------------------------------------------------------------
  520. #  
  521. #==============================================================================
  522. class Scene_Map
  523.   include Train_Actor::Scene_Map_Module
  524. end
复制代码


这是个人物跟随脚本,运行没问题,可是一点存档就出错,请教高手
2.jpg
报错好像是说方法“ setup_actor_character_sprites”不对。可是上面不是有“ setup_actor_character_sprites”定义了吗?

点评

看了一下,应该是Scene_Map_Module的内容没有完全复制进去,所以调用@spriteset.的时候就因为找不到变量而出错  发表于 2012-12-22 17:55

虱子

梦石
0
星屑
121
在线时间
1782 小时
注册时间
2010-6-19
回帖
3515
发表于 2012-12-22 15:18:36 | 显示全部楼层
试试使用新存档

点评

内容不全?这脚本我在站里下的呀?  发表于 2012-12-22 18:58
重玩也没问题,可是一存档就会出错  发表于 2012-12-22 17:42

http://rpg.blue/thread-175056-1-2.html
PVZ型塔防物一个
http://rpg.blue/thread-155199-1-2.html
RMXP技术讨论区手动认可帖,得到答案请认可
回复

使用道具 举报

梦石
0
星屑
52
在线时间
586 小时
注册时间
2012-5-31
回帖
711
 楼主| 发表于 2012-12-22 19:37:35 | 显示全部楼层
我又试了几次,还是存档 时出问题。
回复

使用道具 举报

故九江太守

梦石
0
星屑
334
在线时间
2159 小时
注册时间
2012-12-5
回帖
4323
发表于 2012-12-22 22:11:26 来自手机 | 显示全部楼层
下载下范例试试
回复

使用道具 举报

梦石
0
星屑
50
在线时间
3 小时
注册时间
2015-5-22
回帖
6
发表于 2015-5-22 09:58:44 | 显示全部楼层
你最珍贵 发表于 2012-12-22 22:11
下载下范例试试

珍贵啊  脚本老是出错怎么办呀TAT
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部