Project1

标题: 帮我看一下这晕头转向的脚本 [打印本页]

作者: chd114    时间: 2013-7-27 20:28
标题: 帮我看一下这晕头转向的脚本
本帖最后由 hys111111 于 2013-7-28 09:12 编辑
  1.           if @skill.id==1#召唤一枚土之元素核心
  2.             $game_variables[1][$game_variables[3][0]]=1
  3.             if $game_variables[3][0]!=3
  4.               $game_variables[3][0]+=1
  5.             else
  6.               $game_variables[3][0]=0
  7.             end
  8.           elsif @skill.id==2#召唤一枚水之元素核心
  9.                $game_variables[1][$game_variables[3][0]]=2
  10.                if $game_variables[3][0]!=3
  11.                  $game_variables[3][0]+=1
  12.                else
  13.                  $game_variables[3][0]=0
  14.                end
  15.           elsif @skill.id==3#召唤一枚风之元素核心
  16.                $game_variables[1][$game_variables[3][0]]=3
  17.                if $game_variables[3][0]!=3
  18.                  $game_variables[3][0]+=1
  19.                else
  20.                  $game_variables[3][0]=0
  21.                end            
  22.           elsif @skill.id==4#召唤一枚火之元素核心
  23.                $game_variables[1][$game_variables[3][0]]=4
  24.                if $game_variables[3][0]!=3
  25.                  $game_variables[3][0]+=1
  26.                else
  27.                  $game_variables[3][0]=0
  28.                end
  29.           elsif @skill.id==5#衍生技能融合
  30.             for i in 2..6   
  31.               $game_variables[3][i]=0
  32.             end
  33.             for i in 0..3
  34.               if $game_variables[1][i]==1
  35.                 $game_variables[3][2]+=1
  36.               elsif $game_variables[1][i]==2
  37.                 $game_variables[3][3]+=1
  38.               elsif $game_variables[1][i]==3
  39.                 $game_variables[3][4]+=1
  40.               elsif $game_variables[1][i]==4
  41.                 $game_variables[3][5]+=1
  42.               end
  43.             end
  44.             $game_variables[3][6]=[$game_variables[3][2],$game_variables[3][3],$game_variables[3][4],$game_variables[3][5]]
  45.             for i in 0..34
  46.               if $game_variables[3][6]==$game_variables[4][i]
  47.                 if $game_variables[2][$game_variables[3][1]]!=nil
  48.                   $game_actors[1].learn_skill(i+6)
  49.                   $game_variables[2][$game_variables[3][1]]=i+6
  50.                 end
  51.                 if $game_variables[3][1]!=$game_variables[2].size-1#最后一个技能位没占领的话
  52.                   $game_variables[3][1]+=1
  53.                 elsif $game_variables[2][$game_variables[3][1]]==0
  54.                   $game_actors[1].forget_skill($game_variables[2][$game_variables[3][1]]-1)
  55.                   $game_variables[3][1]+=1
  56.                 else
  57.                   $game_actors[1].forget_skill($game_variables[2][$game_variables[3][1]])
  58.                   $game_variables[3][1]=0
  59.                 end
  60.               end
  61.             end
  62.           end
复制代码
衍生技能那出了问题···
  1. $game_variables[1]=[0,0,0,0]
  2. #当前的元素核心
  3. $game_variables[2]=[0,0]
  4. #当前的技能位衍生技能编号
  5. $game_variables[3]=[0,0,0,0,0,0,[0,0,0,0]]
  6. #下一个变换的元素核心、衍生技能位置
  7. #衍生中的四系元素比例、元素衍生配方
复制代码
变量2来记录衍生出的技能,1-5号技能分别为四系元素和衍生大招···在角色升级后变量2可以记录更多衍生技能(可以衍生更多技能),但是衍生的技能一旦超过技能位限制便会遗忘技能,所以在遗忘技能上出了问题···因为两个以上的技能位要遗忘的技能肯定不会是前一个衍生的技能···
作者: wwwcctvty    时间: 2013-7-27 21:21
晕了、、、、、、、话说我只看到一堆变量、、、
作者: chd114    时间: 2013-7-28 09:09
wwwcctvty 发表于 2013-7-27 21:21
晕了、、、、、、、话说我只看到一堆变量、、、

脚本编辑器没法并行全局变量···所以用的普通变量···元素核心没问题,就是衍生技能有问题
作者: hys111111    时间: 2013-7-28 09:14
晕倒……Oksh很喜欢用数组,您就不能改用本地变量什么的吗?(好晕啊)


05.$game_variables[3]=[0,0,0,0,0,0,[0,0,0,0]]
先要定义$game_variables[3]=[0,0,0,0,0,0,[]]
作者: chd114    时间: 2013-7-28 09:43
hys111111 发表于 2013-7-28 09:14
晕倒……Oksh很喜欢用数组,您就不能改用本地变量什么的吗?(好晕啊)


05.$game_variables[3]=[0,0,0 ...

其他变量没问题···问题是我用5号技能的大招衍生技能有问题···因为主角有35个衍生技能,如果就靠一个大招就全部出来了那么大招就废了,所以我的设定就是大招衍生技能有数量限制,现在默认的限制是两个,如果已经做出了两个衍生技能还想做第三个的话第一个被做出来的技能就会被覆盖···如果只是两个技能位也罢了,可是主角的技能位在升级后可以增加···所以问题就在这里,2个技能位的话技能切到死也没有BUG,2个以上的话根本切不出技能
作者: 认真的学    时间: 2013-7-28 10:01
首先想对chd说的是......注释一般写在该段代码的上方= =
  1. if $game_variables[3][6]==$game_variables[4][i]
复制代码
46行出现的4号变量是用来干啥的?
作者: chd114    时间: 2013-7-28 10:21
认真的学 发表于 2013-7-28 10:01
首先想对chd说的是......注释一般写在该段代码的上方= =46行出现的4号变量是用来干啥的? ...

4号变量是元素衍生技能的配方
  1. $game_variables[4]=[]
  2. $game_variables[4][0]=[4,0,0,0]
  3. $game_variables[4][1]=[3,1,0,0]
  4. $game_variables[4][2]=[3,0,1,0]
  5. $game_variables[4][3]=[3,0,0,1]
  6. $game_variables[4][4]=[2,1,1,0]
  7. $game_variables[4][5]=[2,1,0,1]
  8. $game_variables[4][6]=[2,0,1,1]
  9. $game_variables[4][7]=[2,2,0,0]
  10. $game_variables[4][8]=[2,0,2,0]
  11. $game_variables[4][9]=[2,0,0,2]
  12. $game_variables[4][10]=[1,1,1,1]
复制代码
一共35个配方
作者: 认真的学    时间: 2013-7-28 11:05
本帖最后由 认真的学 于 2013-7-28 11:22 编辑

你的代码是说如果最后一个技能位没有被占领,那么当前可用技能位的位置就+1.
如果被占领了但是技能ID是0(这有可能么= =),则遗忘该技能ID-1的技能?
如果被占领了但是技能ID又不是0,就遗忘最后一个技能位的技能(这不是刚学的么= =),并且可用技能位的位置回到0?

我觉得这其实就是一个滚动数组:
1、如果可用技能位上没有技能,那么直接习得新技能。如果可用技能位上有技能,那么忘掉这个技能再习得新技能。
2、可用技能位置+1
3、可用技能位超出范围则回到0.
  1. if $game_variables[3][6]==$game_variables[4][i]
  2.   if $game_variables[2][$game_variables[3][1]]!=nil
  3.     if $game_variables[2][$game_variables[3][1]] != 0
  4.       $game_actors[1].forget_skill($game_variables[2][$game_variables[3][1]])
  5.     end
  6.     $game_actors[1].learn_skill(i+6)
  7.     $game_variables[2][$game_variables[3][1]]=i+6
  8.     $game_variables[3][1] += 1
  9.     if $game_variables[3][1]>=$game_variables[2].size
  10.       $game_variables[3][1] = 0
  11.     end
  12.   end
  13. end
复制代码

作者: chd114    时间: 2013-7-28 11:25
认真的学 发表于 2013-7-28 11:05
你的代码是说如果最后一个技能位没有被占领,那么当前可用技能位的位置就+1.
如果被占领了但是技能ID是0( ...

其实跟DOTA的祈求者是类似的···比如有两个技能位的话[][],当我用祈求者衍生了两个技能,比如技能位变成了[V][A],那么想要再衍生技能的话V就会被替换掉,就会变成[X][A],如果我又衍生技能的话又会变成[X][R]···但是我这个和祈求者还是有区别的,因为主角后期技能位会增多,所以就出问题了···
作者: chd114    时间: 2013-7-28 12:16
认真的学 发表于 2013-7-28 11:05
你的代码是说如果最后一个技能位没有被占领,那么当前可用技能位的位置就+1.
如果被占领了但是技能ID是0( ...
  1. #==============================================================================
  2. # ■ Scene_Skill
  3. #------------------------------------------------------------------------------
  4. #  处理特技画面的类。
  5. #==============================================================================

  6. class Scene_Skill
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #     actor_index : 角色索引
  10.   #--------------------------------------------------------------------------
  11.   def initialize(actor_index = 0, equip_index = 0)
  12.     @actor_index = actor_index
  13.   end
  14.   #--------------------------------------------------------------------------
  15.   # ● 主处理
  16.   #--------------------------------------------------------------------------
  17.   def main
  18.     # 获取角色
  19.     [url=home.php?mod=space&uid=95897]@actor[/url] = $game_party.actors[@actor_index]
  20.     # 生成帮助窗口、状态窗口、特技窗口
  21.     @help_window = Window_Help.new
  22.     @status_window = Window_SkillStatus.new(@actor)
  23.     @skill_window = Window_Skill.new(@actor)
  24.     # 关联帮助窗口
  25.     @skill_window.help_window = @help_window
  26.     # 生成目标窗口 (设置为不可见・不活动)
  27.     @target_window = Window_Target.new
  28.     @target_window.visible = false
  29.     @target_window.active = false
  30.     # 执行过渡
  31.     Graphics.transition
  32.     # 主循环
  33.     loop do
  34.       # 刷新游戏画面
  35.       Graphics.update
  36.       # 刷新输入信息
  37.       Input.update
  38.       # 刷新画面
  39.       update
  40.       # 如果画面切换的话就中断循环
  41.       if $scene != self
  42.         break
  43.       end
  44.     end
  45.     # 准备过渡
  46.     Graphics.freeze
  47.     # 释放窗口
  48.     @help_window.dispose
  49.     @status_window.dispose
  50.     @skill_window.dispose
  51.     @target_window.dispose
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # ● 刷新画面
  55.   #--------------------------------------------------------------------------
  56.   def update
  57.     # 刷新窗口
  58.     @help_window.update
  59.     @status_window.update
  60.     @skill_window.update
  61.     @target_window.update
  62.     # 特技窗口被激活的情况下: 调用 update_skill
  63.     if @skill_window.active
  64.       update_skill
  65.       return
  66.     end
  67.     # 目标窗口被激活的情况下: 调用 update_target
  68.     if @target_window.active
  69.       update_target
  70.       return
  71.     end
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ● 刷新画面 (特技窗口被激活的情况下)
  75.   #--------------------------------------------------------------------------
  76.   def update_skill
  77.     # 按下 B 键的情况下
  78.     if Input.trigger?(Input::B)
  79.       # 演奏取消 SE
  80.       $game_system.se_play($data_system.cancel_se)
  81.       # 切换到菜单画面
  82.       $scene = Scene_Menu.new(1)
  83.       return
  84.     end
  85.     # 按下 C 键的情况下
  86.     if Input.trigger?(Input::C)
  87.       # 获取特技窗口现在选择的特技的数据
  88.       [url=home.php?mod=space&uid=260100]@skill[/url] = @skill_window.skill
  89.       # 不能使用的情况下
  90.       if @skill == nil or not @actor.skill_can_use?(@skill.id)
  91.         # 演奏冻结 SE
  92.         $game_system.se_play($data_system.buzzer_se)
  93.         return
  94.       end
  95.       # 演奏确定 SE
  96.       $game_system.se_play($data_system.decision_se)
  97.       # 效果范围是我方的情况下
  98.       if @skill.scope >= 3
  99.         # 激活目标窗口
  100.         @skill_window.active = false
  101.         @target_window.x = (@skill_window.index + 1) % 2 * 304
  102.         @target_window.visible = true
  103.         @target_window.active = true
  104.         # 设置效果范围 (单体/全体) 的对应光标位置
  105.         if @skill.scope == 4 || @skill.scope == 6
  106.           @target_window.index = -1
  107.         elsif @skill.scope == 7
  108.           @target_window.index = @actor_index - 10
  109.         else
  110.           @target_window.index = 0
  111.         end
  112.       # 效果在我方以外的情况下
  113.       else
  114.         # 公共事件 ID 有效的情况下
  115.         if @skill.common_event_id > 0
  116.           # 预约调用公共事件
  117.          
  118.           if @skill.id==1#召唤一枚土之元素核心
  119.             $game_variables[1][$game_variables[3][0]]=1
  120.             if $game_variables[3][0]!=3
  121.               $game_variables[3][0]+=1
  122.             else
  123.               $game_variables[3][0]=0
  124.             end
  125.           elsif @skill.id==2#召唤一枚水之元素核心
  126.                $game_variables[1][$game_variables[3][0]]=2
  127.                if $game_variables[3][0]!=3
  128.                  $game_variables[3][0]+=1
  129.                else
  130.                  $game_variables[3][0]=0
  131.                end
  132.           elsif @skill.id==3#召唤一枚风之元素核心
  133.                $game_variables[1][$game_variables[3][0]]=3
  134.                if $game_variables[3][0]!=3
  135.                  $game_variables[3][0]+=1
  136.                else
  137.                  $game_variables[3][0]=0
  138.                end            
  139.           elsif @skill.id==4#召唤一枚火之元素核心
  140.                $game_variables[1][$game_variables[3][0]]=4
  141.                if $game_variables[3][0]!=3
  142.                  $game_variables[3][0]+=1
  143.                else
  144.                  $game_variables[3][0]=0
  145.                end
  146.           elsif @skill.id==5#衍生技能融合
  147.             for i in 2..6   
  148.               $game_variables[3][i]=0
  149.             end
  150.             for i in 0..3
  151.               if $game_variables[1][i]==1
  152.                 $game_variables[3][2]+=1
  153.               elsif $game_variables[1][i]==2
  154.                 $game_variables[3][3]+=1
  155.               elsif $game_variables[1][i]==3
  156.                 $game_variables[3][4]+=1
  157.               elsif $game_variables[1][i]==4
  158.                 $game_variables[3][5]+=1
  159.               end
  160.             end
  161.             $game_variables[3][6]=[$game_variables[3][2],$game_variables[3][3],$game_variables[3][4],$game_variables[3][5]]
  162.             for i in 0..34
  163.               if $game_variables[3][6]==$game_variables[4][i]
  164.                 if $game_variables[2][$game_variables[3][1]]!=nil
  165.                   if $game_variables[2][$game_variables[3][1]] != 0
  166.                     $game_actors[1].forget_skill($game_variables[2][$game_variables[3][1]])
  167.                   end
  168.                   $game_actors[1].learn_skill(i+6)
  169.                   $game_variables[2][$game_variables[3][1]]=i+6
  170.                   $game_variables[3][1] += 1
  171.                   if $game_variables[3][1]>=$game_variables[2].size
  172.                     $game_variables[3][1] = 0
  173.                   end
  174.                 end
  175.               end
  176.             end
  177.           end
  178.          
  179.           $game_temp.common_event_id = @skill.common_event_id
  180.           # 演奏特技使用时的 SE
  181.           $game_system.se_play(@skill.menu_se)
  182.           # 消耗 SP
  183.           @actor.sp -= @skill.sp_cost
  184.           # 再生成各窗口的内容
  185.           @status_window.refresh
  186.           @skill_window.refresh
  187.           @target_window.refresh
  188.           # 切换到地图画面
  189.           $scene = Scene_Map.new
  190.           return
  191.         end
  192.       end
  193.       return
  194.     end
  195.     # 按下 R 键的情况下
  196.     if Input.trigger?(Input::R)
  197.       # 演奏光标 SE
  198.       $game_system.se_play($data_system.cursor_se)
  199.       # 移至下一位角色
  200.       @actor_index += 1
  201.       @actor_index %= $game_party.actors.size
  202.       # 切换到别的特技画面
  203.       $scene = Scene_Skill.new(@actor_index)
  204.       return
  205.     end
  206.     # 按下 L 键的情况下
  207.     if Input.trigger?(Input::L)
  208.       # 演奏光标 SE
  209.       $game_system.se_play($data_system.cursor_se)
  210.       # 移至上一位角色
  211.       @actor_index += $game_party.actors.size - 1
  212.       @actor_index %= $game_party.actors.size
  213.       # 切换到别的特技画面
  214.       $scene = Scene_Skill.new(@actor_index)
  215.       return
  216.     end
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # ● 刷新画面 (目标窗口被激活的情况下)
  220.   #--------------------------------------------------------------------------
  221.   def update_target
  222.     # 按下 B 键的情况下
  223.     if Input.trigger?(Input::B)
  224.       # 演奏取消 SE
  225.       $game_system.se_play($data_system.cancel_se)
  226.       # 删除目标窗口
  227.       @skill_window.active = true
  228.       @target_window.visible = false
  229.       @target_window.active = false
  230.       return
  231.     end
  232.     # 按下 C 键的情况下
  233.     if Input.trigger?(Input::C)
  234.       # 因为 SP 不足而无法使用的情况下
  235.       unless @actor.skill_can_use?(@skill.id)
  236.         # 演奏冻结 SE
  237.         $game_system.se_play($data_system.buzzer_se)
  238.         return
  239.       end
  240.       # 目标是全体的情况下
  241.       if @target_window.index == -1
  242.         # 对同伴全体应用特技使用效果
  243.         used = false
  244.         for i in $game_party.actors
  245.           used |= i.skill_effect(@actor, @skill)
  246.         end
  247.       end
  248.       # 目标是使用者的情况下
  249.       if @target_window.index <= -2
  250.         # 对目标角色应用特技的使用效果
  251.         target = $game_party.actors[@target_window.index + 10]
  252.         used = target.skill_effect(@actor, @skill)
  253.       end
  254.       # 目标是单体的情况下
  255.       if @target_window.index >= 0
  256.         # 对目标角色应用特技的使用效果
  257.         target = $game_party.actors[@target_window.index]
  258.         used = target.skill_effect(@actor, @skill)
  259.       end
  260.       # 使用特技的情况下
  261.       if used
  262.         # 演奏特技使用时的 SE
  263.         $game_system.se_play(@skill.menu_se)
  264.         # 消耗 SP
  265.         @actor.sp -= @skill.sp_cost
  266.         # 再生成各窗口内容
  267.         @status_window.refresh
  268.         @skill_window.refresh
  269.         @target_window.refresh
  270.         # 全灭的情况下
  271.         if $game_party.all_dead?
  272.           # 切换到游戏结束画面
  273.           $scene = Scene_Gameover.new
  274.           return
  275.         end
  276.         # 公共事件 ID 有效的情况下
  277.         if @skill.common_event_id > 0
  278.           # 预约调用公共事件
  279.           $game_temp.common_event_id = @skill.common_event_id
  280.           # 切换到地图画面
  281.           $scene = Scene_Map.new
  282.           return
  283.         end
  284.       end
  285.       # 无法使用特技的情况下
  286.       unless used
  287.         # 演奏冻结 SE
  288.         $game_system.se_play($data_system.buzzer_se)
  289.       end
  290.       return
  291.     end
  292.   end
  293. end
复制代码
发现BUG了···如果我按照原来的配方连续切两次技能的话再切第三个技能就只有第三个技能,哪怕技能位有两个···
作者: 认真的学    时间: 2013-7-28 12:27
本帖最后由 认真的学 于 2013-7-28 12:29 编辑
chd114 发表于 2013-7-28 12:16
发现BUG了···如果我按照原来的配方连续切两次技能的话再切第三个技能就只有第三个技能,哪怕技能位有 ...


我明白了,那么这样吧:
把脚本中的X改成一个空闲的变量就好了。
当然,要先定义第X号变量为一个足够长的数组(组合技编号最大是多少,数组长度就要至少比它大1)

  1. if $game_variables[3][6]==$game_variables[4][i]
  2.   if $game_variables[2][$game_variables[3][1]]!=nil
  3.     ski_id = $game_variables[2][$game_variables[3][1]]
  4.     if ski_id != 0
  5.       $game_variables[X][ski_id] -= 1
  6.       if $game_variables[X][ski_id] <= 0
  7.         $game_actors[1].forget_skill(ski_id)
  8.       end
  9.     end
  10.     $game_actors[1].learn_skill(i+6)
  11.     $game_variables[X][i+6] += 1
  12.     $game_variables[2][$game_variables[3][1]]=i+6
  13.     $game_variables[3][1] += 1
  14.     if $game_variables[3][1]>=$game_variables[2].size
  15.       $game_variables[3][1] = 0
  16.     end
  17.   end
  18. end
复制代码

作者: 芯☆淡茹水    时间: 2013-7-28 17:14
完全可把那些变量改成角色本身的属性变量,就像 str   dex   agi .........,这些。
作者: chd114    时间: 2013-7-29 15:52
芯☆淡茹水 发表于 2013-7-28 17:14
完全可把那些变量改成角色本身的属性变量,就像 str   dex   agi .........,这些。 ...

······土元素增加str,水+dex,风+agi,火+int···都用了···总不能用hp吧···
作者: 芯☆淡茹水    时间: 2013-7-29 16:06
我的意思是不用变量记录增加多少,比如 火元素 增加:
在 Game_Actor 下
attr_accessor : fire_plus
然后初始化:
@fire_plus = 0

那么以后要读取和写入就用:actor.fire_plus  ,而不用一大堆变量。

这都是有人教我的。
作者: chd114    时间: 2013-7-30 08:20
芯☆淡茹水 发表于 2013-7-29 16:06
我的意思是不用变量记录增加多少,比如 火元素 增加:
在 Game_Actor 下
attr_accessor : fire_plus

可是我只有一个角色有这四系元素···其他人没有啊,这样显得浪费了




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1