查看: 2762|回复: 4

[已经解决] 詢問在事件腳本中更改屬性抗性以及攻擊次數

[复制链接]
梦石
0
星屑
317
在线时间
67 小时
注册时间
2014-4-17
回帖
10
发表于 2020-8-17 02:41:52 | 显示全部楼层 |阅读模式

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

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

×
想要透過事件中的腳本,更改屬性抗性以及攻擊次數,不過翻不到相關的代碼。

假設希望角色ID1的

屬性ID3的抗性增加10%,以及攻擊次數增加1次,,請問各位大佬這該如何呼叫呢?
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2020-8-17 10:39:38 | 显示全部楼层
本帖最后由 alexncf125 于 2020-8-17 10:43 编辑

http://himeworks.com/2013/07/feature-conditions/

脚本的简介与使用方法请自行翻译,我就不误作说明了

  1. =begin
  2. #===============================================================================
  3. Title: Feature Conditions
  4. Author: Hime
  5. Date: Nov 22, 2014
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Nov 22, 2014
  9.    - fixed bug where conditions were always false
  10. Nov 14, 2014
  11.    - added checks to prevent recursive calls
  12. Jul 10, 2014
  13.    - added support for tagging multiple features in one note-tag
  14. Jul 9, 2014
  15.    - added support for individual features
  16. Jul 16, 2013
  17.    - Initial release
  18. --------------------------------------------------------------------------------   
  19. ** Terms of Use
  20. * Free to use in non-commercial projects
  21. * Contact me for commercial use
  22. * No real support. The script is provided as-is
  23. * Will do bug fixes, but no compatibility patches
  24. * Features may be requested but no guarantees, especially if it is non-trivial
  25. * Credits to Hime Works in your project
  26. * Preserve this header
  27. --------------------------------------------------------------------------------
  28. ** Description

  29. This script allows you to add "feature conditions" to any objects that hold
  30. features. These conditions are used to control whether the features from an
  31. object are applied to your actor or not.

  32. For example, suppose you have shield equips that have special elemental
  33. immunities when the "guard" state is applied. You can add these features to
  34. the shield and then use feature conditions to indicate that the "guard" state
  35. must be applied before the features are transferred.

  36. Feature conditions can be applied at the object level, which means all
  37. conditions must be met for any features to be applied.

  38. Feature conditions can also be applied at the feature level, which provides
  39. finer control over when specific features can be applied.

  40. --------------------------------------------------------------------------------
  41. ** Installation

  42. Place this script below Materials and above Main

  43. --------------------------------------------------------------------------------
  44. ** Usage

  45. To add a feature conditions, use the notetag for any objects with features,
  46. such as Actors, Classes, Weapons, Armors, Enemies, or States. If you are using
  47. the Feature Manager, then it will be applied to skills and items as well.

  48. == Object-level feature conditions ==

  49. For object-level conditions, use the note-tag of the form

  50.    <feature condition>
  51.       FORMULA
  52.    </feature condition>
  53.    
  54. For any valid ruby formula that returns true or false.
  55. Three variables are available for your convenience:

  56.    a - subject the feature applies to
  57.    s - game switches
  58.    v - game variables
  59.    
  60. By "subject" I refer to "actor" or "enemy". For example, a state can be applied
  61. to both actors or enemies, so if the enemy has the state, then that enemy is
  62. the subject. If the actor has the state, then that actor is the subject. Be
  63. careful when writing your formulas.

  64. == Feature-level conditions ==

  65. Applying conditions to individual features is the same as object-level
  66. conditions, except in the note-tag you specify which feature it applies to

  67.    <feature condition: x>
  68.      FORMULA
  69.    </feature condition>
  70.   
  71.    <feature condition: x, y, ... >
  72.      FORMULA
  73.    </feature condition>
  74.    
  75. Where x and y are the ID's of the features. The ID of the feature is based on
  76. its position in the list, so the feature at the top of the list has ID 1, the
  77. next one has ID 2, and so on.

  78. You can specify multiple ID's by separating them with commas.
  79.    
  80. --------------------------------------------------------------------------------
  81. ** Examples

  82. Here are some quick examples of some conditions you might have

  83. * Feature 2 and 3 are applied only if the party has more than 5000 gold

  84.    <feature condition: 2,3 >
  85.      $game_party.gold > 5000
  86.    </feature condition>
  87.      
  88. * Features of the object are only applied if state 23 is applied

  89.    <feature condition>
  90.      a.state?(23)
  91.    </feature condition>
  92.   
  93. #===============================================================================
  94. =end
  95. $imported = {} if $imported.nil?
  96. $imported["TH_FeatureConditions"] = true
  97. #===============================================================================
  98. # ** Configuration
  99. #===============================================================================
  100. module TH
  101.   module Feature_Conditions
  102.     Regex = /<feature[-_ ]condition>(.*?)<\/feature[-_ ]condition>/im
  103.     Ft_Regex = /<feature[-_ ]condition:\s*(.*?)\s*>(.*?)<\/feature[-_ ]condition>/im
  104.   end
  105. end
  106. #===============================================================================
  107. # ** Rest of Script
  108. #===============================================================================
  109. module RPG
  110.   class BaseItem
  111.     def feature_conditions_met?(subject)
  112.       load_notetag_feature_conditions unless @feature_conditions_loaded
  113.       return eval_feature_conditions(subject)
  114.     end
  115.    
  116.     def load_notetag_feature_conditions
  117.       @feature_conditions_loaded = true
  118.       conditions = "true"
  119.       res = self.note.scan(TH::Feature_Conditions::Regex)
  120.       res.each_with_index do |cond, i|
  121.         conditions << " && " if i > 0
  122.         conditions << cond[0]
  123.       end
  124.       build_condition_method(conditions.empty? ? "true" : conditions)      
  125.       load_notetag_individual_feature_conditions
  126.     end
  127.    
  128.     def load_notetag_individual_feature_conditions
  129.       results = self.note.scan(TH::Feature_Conditions::Ft_Regex)
  130.       results.each do |res|
  131.         ids = res[0].strip.split(",")
  132.         ids.each do |id|
  133.           id = id.to_i - 1
  134.           @features[id].feature_condition = res[1]
  135.         end
  136.       end
  137.     end
  138.    
  139.     #---------------------------------------------------------------------------
  140.     # Builds the condition-checking method. This is done for performance
  141.     # reasons since features are checked several hundred times very frequently.
  142.     # It assumes the conditions do not change dynamically once they have been
  143.     # loaded.
  144.     #---------------------------------------------------------------------------
  145.     def build_condition_method(conditions)
  146.       eval(
  147.         "def eval_feature_conditions(a, v=$game_variables, s=$game_switches)
  148.            #{conditions}
  149.          end"
  150.       )
  151.     end
  152.   end
  153.   
  154.   class BaseItem::Feature
  155.     attr_accessor :feature_condition
  156.    
  157.     def feature_condition_met?(subject)
  158.       return true unless @feature_condition
  159.       eval_feature_condition(subject)
  160.     end
  161.    
  162.     def eval_feature_condition(a, v=$game_variables, s=$game_switches)
  163.       eval(@feature_condition)
  164.     end
  165.   end
  166. end

  167. class Game_BattlerBase
  168.   
  169.   def feature_conditions_met?(obj, subject)
  170.     obj.feature_conditions_met?(subject)
  171.   end
  172.   
  173.   alias :th_feature_conditions_all_features :all_features
  174.   def all_features   
  175.     return [] if @feature_eval_checking
  176.     @feature_eval_checking = true
  177.     fts = th_feature_conditions_all_features.select {|ft| ft.feature_condition_met?(self)}
  178.     @feature_eval_checking = false
  179.     return fts
  180.   end
  181. end

  182. class Game_Actor < Game_Battler
  183.   
  184.   alias :th_feature_conditions_feature_objects :feature_objects
  185.   def feature_objects
  186.     fts = th_feature_conditions_feature_objects.select {|obj|
  187.       feature_conditions_met?(obj, self)
  188.     }
  189.     return fts
  190.   end
  191. end

  192. class Game_Enemy < Game_Battler
  193.   
  194.   alias :th_feature_conditions_feature_objects :feature_objects
  195.   def feature_objects
  196.     fts = th_feature_conditions_feature_objects.select {|obj|
  197.       feature_conditions_met?(obj, self)
  198.     }
  199.     return fts   
  200.   end
  201. end
复制代码

点评

我研究看看 不過目前只看出他好像是標住在備註欄裡面的形式..  发表于 2020-8-18 01:16
回复 1 0

使用道具 举报

梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2020-8-18 02:25:15 | 显示全部楼层
本帖最后由 alexncf125 于 2026-5-7 23:34 编辑

啊这...在角色ID1的特性加上"攻击次数增加1次",备注栏里面备注
<feature condition: 1>
  s[13] == true
</feature condition>
之后在地图上透过事件中的脚本,把某开关例如13号开关打开关闭.你会发现,
13号开关打开时,角色ID1的攻击次数增加至2次,13号开关关闭时,会变回1次
这不就搖身一变,成了你说的"透過事件中的脚本"么??
回复 1 0

使用道具 举报

梦石
0
星屑
317
在线时间
67 小时
注册时间
2014-4-17
回帖
10
 楼主| 发表于 2020-8-18 09:38:21 | 显示全部楼层
alexncf125 发表于 2020-8-18 02:25
啊这...在角色ID1的特性加上"攻击次数增加1次",备注栏里面备注

  s[13] == true

對自己的笨感到無地自容
我完全沒轉過來,完全沒這樣想..(一直想著往code的方式去加)
非常感恩大佬
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部