查看: 2161|回复: 2

[已经解决] 请问怎么样用开关控制脚本是否启用?

[复制链接]
梦石
0
星屑
1724
在线时间
542 小时
注册时间
2014-9-28
回帖
38

开拓者

发表于 2017-9-2 20:47:02 | 显示全部楼层 |阅读模式

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

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

×
是这样的,为了能够实现附带横版小游戏的多帧效果,我用了@rmav 的多帧脚本。可是,假如我用在正常的游戏流程(非附带的横版的小游戏)里,却发现会有很多奇奇怪怪的bug……所以,我希望能用开关控制这个脚本的开启/关闭!之前曾经试过直接在开头加 lf game_switches[250] = =true,然后在下面直接放上脚本……但果然还是不行。
所以,我就来这儿请教一下各位大神该怎么办……如有疏忽请见谅!
现附上脚本原文,恳请各位大神帮帮我!

  1. #encoding:utf-8
  2. #==============================================================================
  3. #   ■ 多帧4_8方图,4_8向行走
  4. #
  5. #   支持4方图:兼容rmVA原格式图片,4向8向行走
  6. #   支持8方图:从上到下方向为:正、左、右、背、左下、右下、左上、右上
  7. #             对应小键盘:24681379
  8. #   支持开火车,有一定范围的拥挤处理。支持4、8方混合开
  9. #   按住方向键时,碰到障碍物会踏步(可选)
  10. #   可选4、8向行走,在代码开头设置,默认为8向行走
  11. #------------------------------------------------------------------------------
  12. #使用说明:(在编辑器中设置行走图时,有个白框必须放在左上角)
  13. #         对原rmVA不支持的格式,需要对文件名实行命名规则
  14. #         1.png图片,须仅包含一个人物的全套行走
  15. #         2.图片内容,从左到右,小于99帧;
  16. #                    从上到下8个方向:正、左、右、背、左下、右下、左上、右上
  17. #         3.文件命名
  18. #           文件名:角色名+格式串+.png
  19. #                  name@D#DD%DD.png   其中%DD可选
  20. #          @D表示png文件中, 每一列有多少个图。以一位数表示,如8,即8个方向
  21. #          #DD表示png文件中,每一行有多少个图。以两位数表示,如06或6,即6帧
  22. #          %DD,可选,调整角色在游戏画面中的高度,单位像素。如20,即调低20像素
  23. #          说明:因为如果是精美8方图的话,一般有带阴影,而阴影会比脚低
  24. #                这时可通过%DD来调整人物在画面中的高低
  25. #                有些图片空白过多,也可用此来调整,不用弄PS。
  26. #
  27. #小技巧:★可新建一个工程,以RMVA默认的角色领队开火车,可看出是否对齐
  28. #        ★若人物在开火车中挤紧在一起,把其每帧的图片加宽,如>=68像素即可。
  29. #        ★把文件命名为name@1#DD%DD.png,可作为单行图移动或放事件中播放动画
  30. #注意:  ☆rmVA原格式行走图,停下来会停在第2帧(这是rmVA的默认方法)
  31. #        ☆自定义格式行走图,停下来会停在第1帧
  32. #        ☆格式串前的name必须在characters文件夹下的所有png文件中唯一
  33. #        ☆行走图的每一帧之间必须高度相等、宽度相等
  34. #      ☆☆没用到的功能关闭掉,以降低冲突及避免无谓的效率影响
  35. #------------------------------------------------------------------------------
  36. #  by rmav (有任何问题请毫无顾忌滴提出)
  37. #
  38. #   v1.09 配合跑步插件更新
  39. #==============================================================================
  40. $imported ||= {}
  41. $imported[:rmav_walk] = 20140204.1
  42. module Rmav
  43.   #---------行走选项设置---------#
  44. Opt_walk={
  45.       dir8_on:     false,     #false则4向行走,本插件系列其他功能仍可以用
  46.       step_ext_on: false,     #按着方向键碰到障碍物踏步,若为false则静止(rmVA默认是静止的)
  47.       
  48.       draw_character: true,  #可在窗口中绘制自定义行走图,若窗口太小会按比例缩小,
  49.                              ##如默认读档界面
  50.                            
  51.       encryption: false,     #打包游戏时,是否选择了加密
  52.                              ##若准备加密,那么在打包前,打开此开关并启动一次游戏
  53.                              ##再打包即可
  54.                              ##若没有启用替换图片功能或待机或跑步功能,可不用管
  55.                            
  56.       wait_run_enable: true  #是否使用了待机跑步子插件
  57.       }

  58.   
  59.   INPUT_HV=[[0,0],[4,2],[0,2],[6,2],[4,0],[0,0],[6,0],[4,8],[0,8],[6,8]]
  60.   Dirs=[1,2,3,4,6,7,8,9]


  61.   #--------------------------------------------------------------------------
  62.   # ● 缓存文件夹中所有png文件名
  63.   #--------------------------------------------------------------------------
  64.   def self.loadFolder(folderName,custom=true)
  65.     @cache_folder||={}
  66.     folderName.gsub!(/\\/,'/')
  67.     folderName+='/' if folderName[-1]!='/'
  68.     folderName.downcase!
  69.     unless @cache_folder.include?(folderName)
  70.       @cache_folder[folderName]=[]
  71.       Dir.glob(folderName+"*.png"){|f|
  72.         file_name=f.split('/')[-1].chomp!('.png')
  73.         if custom
  74.           if file_name.match(/\@\d{1,2}\#\d{1,2}/)
  75.             @cache_folder[folderName]<<file_name
  76.           end
  77.         else
  78.           @cache_folder[folderName]<<file_name
  79.         end
  80.       }
  81.     end
  82.     @cache_folder[folderName]   
  83.   end
  84.   #--------------------------------------------------------------------------
  85.   # ● 分类存储待机图、跑步图
  86.   #--------------------------------------------------------------------------
  87.   CharNames||={wait: {}, run: {}}
  88.   def self.charFolder_map
  89.     self.loadFolder("Graphics/Characters/").each{|f|
  90.         f=~%r{(.+)_([wr])\@\d{1,2}\#\d{1,2}(\%\d{1,2})?}
  91.         if $1&&$2
  92.           case $2
  93.             when "w";CharNames[:wait][$1]=f
  94.             when "r";CharNames[:run][$1]=f
  95.           end
  96.         end
  97.     }
  98.    
  99.   end

  100. end

  101. class Sprite_Character  
  102.   #--------------------------------------------------------------------------
  103.   # ● 设置角色的位图(n方向,n帧)
  104.   #--------------------------------------------------------------------------
  105.   alias_method :set_character_bitmap_org_rmav, :set_character_bitmap
  106.   def set_character_bitmap
  107.     self.bitmap = Cache.character(@character_name)
  108.     @fmt_sign = @character_name[/\@(\d{1,2})\#(\d{1,2})(?:\%(\d{1,2}))?/]      
  109.     if @fmt_sign
  110.       @fmt_sign=[$1.to_i,$2.to_i,$3.to_i]

  111.       @cw = bitmap.width / @fmt_sign[1]   
  112.       @ch = bitmap.height / @fmt_sign[0]  
  113.       self.ox = @cw / 2
  114.       self.oy = @ch-@fmt_sign[2]  
  115.     else
  116.       set_character_bitmap_org_rmav
  117.     end

  118.     if @character
  119.       @character.cw=@cw
  120.       @character.ch=@ch
  121.       @character.fmt_sign=@fmt_sign
  122.       @character.original_pattern=0 if @fmt_sign
  123.     end
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # ● 更新源矩形
  127.   #--------------------------------------------------------------------------
  128.   def update_src_rect
  129.     if @tile_id == 0
  130.       index = @character.character_index
  131.       pattern = @character.pattern < (@fmt_sign?@fmt_sign[1]:3) \
  132.                 ? @character.pattern : 1
  133.       sx = (index % 4 * 3 + pattern) * @cw
  134.       sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  135.       
  136.       case @character.direction
  137.         when 1; sy=@fmt_sign?(@fmt_sign[0]==4?0:4)*@ch:(index / 4 * 4 ) * @ch
  138.         when 3; sy=@fmt_sign?(@fmt_sign[0]==4?0:5)*@ch:(index / 4 * 4 ) * @ch
  139.         when 7; sy=@fmt_sign?(@fmt_sign[0]==4?3:6)*@ch:(index / 4 * 4+3 ) * @ch
  140.         when 9; sy=@fmt_sign?(@fmt_sign[0]==4?3:7)*@ch:(index / 4 * 4+3 ) * @ch
  141.       end
  142.       sy=0 if @fmt_sign&&@fmt_sign[0]==1  
  143.       self.src_rect.set(sx, sy, @cw, @ch)
  144.     end
  145.   end
  146.   
  147. end




  148. class Game_Player
  149. if Rmav::Opt_walk[:dir8_on]
  150.   #--------------------------------------------------------------------------
  151.   # ● 由方向键移动,8方向
  152.   #--------------------------------------------------------------------------
  153.   def move_by_input
  154.     return if !movable? || $game_map.interpreter.running?
  155.     input=Input.dir8
  156.     move_diagonal(*Rmav::INPUT_HV[input]) if input > 0
  157.   end
  158. end

  159.   #--------------------------------------------------------------------------
  160.   # ● 更新步行/踏步动画
  161.   #--------------------------------------------------------------------------
  162.   #alias_method :update_animation_org_rmav,:update_animation
  163.   def update_animation
  164.     if stopping? && @stop_count<1 && Rmav::Opt_walk[:step_ext_on]
  165.       @step_ext_anime=true
  166.     else
  167.       @step_ext_anime=false
  168.     end
  169.     super
  170.   end
  171. end



  172. class Game_CharacterBase
  173.   attr_accessor :cw,:ch,:fmt_sign,:original_pattern,:step_ext_anime
  174.   alias_method :characterBase_init_org_rmav, :initialize
  175.   def initialize
  176.     characterBase_init_org_rmav
  177.     @cw=@ch=0
  178.     @fmt_sign=nil
  179.     @step_ext_anime=false
  180.   end
  181.   
  182.   #--------------------------------------------------------------------------
  183.   # ● 斜向移动
  184.   #     horz : 横向(4 or 6)
  185.   #     vert : 纵向(2 or 8)
  186.   #--------------------------------------------------------------------------
  187.   alias_method :move_diagonal_org_charBase_rmav, :move_diagonal
  188.   def move_diagonal(horz, vert, turn_ok = true)

  189.     @move_succeed = diagonal_passable?(x, y, horz, vert)
  190.     if @move_succeed
  191.       set_direction(Rmav::INPUT_HV.index([horz, vert]))
  192.       @x = $game_map.round_x_with_direction(@x, horz)
  193.       @y = $game_map.round_y_with_direction(@y, vert)
  194.       @real_x = $game_map.x_with_direction(@x, reverse_dir(horz))
  195.       @real_y = $game_map.y_with_direction(@y, reverse_dir(vert))
  196.       increase_steps
  197.     elsif turn_ok
  198.       set_direction(Rmav::INPUT_HV.index([horz, vert]))
  199.       check_event_trigger_touch_front
  200.     end

  201.   end
  202.   

  203.   #--------------------------------------------------------------------------
  204.   # ● 更新动画图案
  205.   #--------------------------------------------------------------------------
  206.   def update_anime_pattern
  207.     if (!@step_anime && @stop_count > 0) ||
  208.       (!@step_anime && stopping? && !@step_ext_anime)
  209.       @pattern = @original_pattern
  210.     else
  211.       @pattern = (@pattern + 1) % (@fmt_sign?@fmt_sign[1]:4)
  212.     end
  213.   end
  214.   
  215.   #--------------------------------------------------------------------------
  216.   # ● 更新动画计数
  217.   #--------------------------------------------------------------------------
  218.   alias_method :update_anime_count_org_rmav,:update_anime_count
  219.   def update_anime_count
  220.     if Rmav::Opt_walk[:step_ext_on] && !(moving? && @walk_anime) && @step_ext_anime
  221.       @anime_count += 1      
  222.     else
  223.       update_anime_count_org_rmav
  224.     end
  225.   end


  226. end



  227. class Game_Follower
  228.   attr_accessor :gathering
  229.   alias_method :follower_initialize_org_rmav, :initialize
  230.   def initialize(member_index, preceding_character)
  231.     follower_initialize_org_rmav(member_index, preceding_character)
  232.     @gathering=false
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # ● 追随带队角色
  236.   #--------------------------------------------------------------------------
  237. def chase_preceding_character
  238.     unless moving?
  239.       sx = distance_x_from(@preceding_character.x)
  240.       sy = distance_y_from(@preceding_character.y)

  241.       dx_pix=[(@preceding_character.cw+@cw)/2, 79].min

  242.       if !@gathering && dx_pix > sx.abs*32+16
  243.         if sy>0
  244.           return  if (@ch>32+16&&sy<2)
  245.         elsif sy<0
  246.           return if (@preceding_character.ch>32+16&&sy.abs<2)
  247.         else
  248.           return
  249.         end        
  250.       end
  251.       
  252.       if sx != 0 && sy != 0
  253.         move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)
  254.       elsif sx != 0
  255.         move_straight(sx > 0 ? 4 : 6)
  256.       elsif sy != 0
  257.         move_straight(sy > 0 ? 8 : 2)
  258.       end
  259.     end
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # ● 更新画面
  263.   #--------------------------------------------------------------------------
  264.   alias_method :update_org_rmav,:update
  265.   def update
  266.     @step_ext_anime = $game_player.step_ext_anime
  267.     @stop_count=0  if @step_ext_anime
  268.     update_org_rmav
  269.   end
  270. end


  271. class Game_Followers
  272.   #--------------------------------------------------------------------------
  273.   # ● 集合
  274.   #--------------------------------------------------------------------------
  275.   alias_method :gather_org_rmav,:gather
  276.   def gather
  277.     gather_org_rmav
  278.     visible_folloers.each {|follower| follower.gathering=true }
  279.   end

  280.   #--------------------------------------------------------------------------
  281.   # ● 判定是否集合完毕
  282.   #--------------------------------------------------------------------------
  283.   alias_method :gather_org_rmav?,:gather?
  284.   def gather?
  285.     ok = gather_org_rmav?
  286.     if ok
  287.       visible_folloers.each {|follower| follower.gathering=false }
  288.     end
  289.     ok
  290.   end
  291. end

  292. if Rmav::Opt_walk[:draw_character]
  293. class Window_Base
  294.   #--------------------------------------------------------------------------
  295.   # ● 绘制人物行走图
  296.   #--------------------------------------------------------------------------
  297.   alias_method :draw_character_org_rmav,:draw_character
  298.   def draw_character(character_name, character_index, x, y,align=true)
  299.                                                           #align是否依据%DD调整
  300.     return unless character_name   
  301.     bitmap = Cache.character(character_name)
  302.     fmt_sign = character_name[/\@(\d{1,2})\#(\d{1,2})(\%(\d{1,2}))?/]      
  303.     if fmt_sign
  304.       fmt_sign=[$1.to_i,$2.to_i,$4.to_i]

  305.       cw = bitmap.width / fmt_sign[1]   
  306.       ch = bitmap.height / fmt_sign[0]  
  307.       ch1=(align)?(ch-fmt_sign[2]):(ch)

  308.       ch2=(ch1>=contents_height)?(contents_height):(ch1)
  309.       cw2=(cw>=contents_width)?(contents_width):(cw)

  310.       dh=ch2.fdiv ch1
  311.       dw=cw2.fdiv cw
  312.       
  313.       if dh<dw        
  314.        cw2=cw*ch2/ch1
  315.       elsif dh>dw
  316.        ch2=ch1*cw2/cw
  317.       end
  318.       y1=(align)?(fmt_sign[2]*[dh,dw].min):0
  319.       src_rect = Rect.new(0, 0, cw, ch)
  320.       dst_rect = Rect.new(x - cw2 / 2, y - ch2,cw2,ch2+y1)
  321.       contents.stretch_blt(dst_rect, bitmap, src_rect)
  322.     else
  323.       draw_character_org_rmav(character_name, character_index, x, y)
  324.     end

  325.   end
  326.   
  327. end
  328. end

  329. if Rmav::Opt_walk[:encryption]
  330.     if Dir.glob("*.rgss3a").size<1
  331.       files_tmp=Rmav.loadFolder("Graphics/Characters/")
  332.       File.open("Graphics/Characters/characters.rmav","wb"){|f|
  333.         Marshal.dump(files_tmp,f)
  334.       }
  335.     end
  336.     def Rmav.loadFolder(folderName)
  337.       @cache_folder||={}
  338.       folderName.gsub!(/\\/,'/')
  339.       folderName+='/' if folderName[-1]!='/'
  340.       folderName.downcase!
  341.       unless @cache_folder.include?(folderName)        
  342.         if folderName[/characters\//]
  343.           @cache_folder[folderName]=load_data(\
  344.           "Graphics/Characters/characters.rmav")
  345.         else
  346.           @cache_folder[folderName]=[]
  347.         end
  348.       end
  349.       @cache_folder[folderName]
  350.   
  351.    end
  352. end

  353. class Game_Character
  354. if Rmav::Opt_walk[:dir8_on]
  355.   #--------------------------------------------------------------------------
  356.   # ● 随机移动
  357.   #--------------------------------------------------------------------------
  358.   def move_random
  359.     direction=Rmav::Dirs[rand(8)]
  360.     move_diagonal(*Rmav::INPUT_HV[direction],false)
  361.   end
  362.   #--------------------------------------------------------------------------
  363.   # ● 接近人物
  364.   #--------------------------------------------------------------------------
  365.   def move_toward_character(character)
  366.     sx = distance_x_from(character.x)
  367.     sy = distance_y_from(character.y)
  368.      o=5
  369.      o-=1 if sx>0
  370.      o+=1 if sx<0
  371.      o-=3 if sy<0
  372.      o+=3 if sy>0
  373.      
  374.     move_diagonal(*Rmav::INPUT_HV[o]) if sx!=0 && sy!=0
  375.     if !@move_succeed && o!=5
  376.       if sx.abs > sy.abs
  377.         move_straight(sx > 0 ? 4 : 6)
  378.         move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
  379.       elsif sy != 0
  380.         move_straight(sy > 0 ? 8 : 2)
  381.         move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
  382.       end
  383.     end
  384.   end
  385.   #--------------------------------------------------------------------------
  386.   # ● 远离人物
  387.   #--------------------------------------------------------------------------
  388.   def move_away_from_character(character)
  389.     sx = distance_x_from(character.x)
  390.     sy = distance_y_from(character.y)
  391.     if sx.abs > sy.abs
  392.       move_straight(sx > 0 ? 6 : 4)
  393.       move_straight(sy > 0 ? 2 : 8) if !@move_succeed && sy != 0
  394.     elsif sy != 0
  395.       move_straight(sy > 0 ? 2 : 8)
  396.       move_straight(sx > 0 ? 6 : 4) if !@move_succeed && sx != 0
  397.     end
  398.   end
  399.   #--------------------------------------------------------------------------
  400.   # ● 前进一步
  401.   #--------------------------------------------------------------------------
  402.   def move_forward
  403.        move_diagonal(*Rmav::INPUT_HV[@direction])
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # ● 后退一步
  407.   #--------------------------------------------------------------------------
  408.   def move_backward
  409.     last_direction_fix = @direction_fix
  410.     @direction_fix = true
  411.     move_diagonal(*Rmav::INPUT_HV[reverse_dir(@direction)], false)
  412.     @direction_fix = last_direction_fix
  413.   end
  414. end  
  415.    
  416. end

  417. if Rmav::Opt_walk[:wait_run_enable]
  418. module Cache
  419. class <<self
  420.   alias_method :character_org_rmav,:character
  421.   def character(filename)
  422.     if $imported[:rmav_walk_wait]||$imported[:rmav_walk_run]
  423.       unless Cache.include?("Graphics/Characters/"+filename)
  424.         filename=~%r{(.+)\@\d{1,2}\#\d{1,2}}
  425.         if $1
  426.           base=$1.sub(/_[wr]\z/,'')
  427.           w=Rmav::CharNames[:wait][base] if $imported[:rmav_walk_wait]
  428.           r=Rmav::CharNames[:run][base] if $imported[:rmav_walk_run]
  429.           character_org_rmav(filename)
  430.           character_org_rmav(w) if w
  431.           character_org_rmav(r) if r

  432.         end
  433.       end
  434.     end
  435.     character_org_rmav(filename)  
  436.   end
  437. end
  438. end

  439. Rmav.charFolder_map
  440. end

复制代码
毁掉一张图的最好方式就是把它用作头像(逃)

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2017-9-2 21:05:56 | 显示全部楼层
本帖最后由 taroxd 于 2017-9-2 21:08 编辑

除非脚本本身提供这个功能,否则没有简单的办法可以做到

大概的做法是把脚本每个更改的方法中都加上一个判断,即

if $game_variables[xx]
  脚本更改后的内容
else
  脚本更改前的内容
end

而且即使这样做也很可能在开关的时候出一些奇怪的 bug。

点评

是……是吗,太遗憾了。可我翻遍整个论坛也只有这个多帧脚本了……  发表于 2017-9-2 21:09

评分

参与人数 1星屑 +15 收起 理由
迷失炎 + 15 我先试试看!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部