骑马与砍杀中文站论坛

标题: 【战团代码示例】AI拾取弹药的实现 [打印本页]

作者: 武安apk43    时间: 2023-8-4 22:35
标题: 【战团代码示例】AI拾取弹药的实现
本帖最后由 武安apk43 于 2023-9-29 00:01 编辑

首先声明,这个代码需要理解其原理根据需要做修改,因为一些代码关联到我的mod一些其他功能模块。
起因:我想实现骑砍2里的AI拾取弹药功能,看到R大曾经开源过非玩家角色捡地上武器的战场触发器 - MOD制作资料区 - 骑马与砍杀中文站论坛 - Powered by Discuz! (mountblade.com.cn)
但是R大这个有很大局限性,只能拾取dead(避免触发敏感词审核)角色手里的武器,而无法拾取弹药类,更别说单支的弹药了,所以就研究出了这个方案。
结果:
该方案可以实现拾取包括死亡掉落的弹药和单支类弹药,理论上还可以扩展到所有生成类场景item。
下面提供示例代码,添加了一些注解,包含核心实现方法和性能优化方案,仅供参考:
[spoiler=源码]##Wuan  # Archers pick up ammoarchers_pick_up_ammo_triggers =
[
  (3, 0, 0, [(neg|all_enemies_defeated),(ge, "$ai_pick_up_ammo", 1),],# 是否启用拾取弹药AI
    [
      (set_fixed_point_multiplier, 1000),# 必须的
      (try_for_range, ":item_id", all_items_begin, all_items_end),# 循环所有item
        (item_get_type, ":item_type", ":item_id"),
        (call_script, "script_cf_item_is_missile", ":item_id"),# 过滤掉非弹药类item,比较简单的一个脚本,自己写一个即可
        # 拾取dead掉落弹药类item
        (try_begin),
          (scene_spawned_item_get_num_instances, ":instance_number", ":item_id"),# 获取该物品的场景实例个数
          (gt, ":instance_number", 0),
          # (try_begin),
          # (ge, "$cheat_mode", 1),
          # (assign, reg1, ":instance_number"),
          # (str_store_item_name, s1, ":item_id"),
          # (display_message, "@{s1} number: {reg1}"),
          # (try_end),
          (try_for_range, ":index", 0, ":instance_number"),# 在这些场景实例中循环
            (scene_spawned_item_get_instance, ":instance", ":item_id", ":index"), # 获取实例id
            (prop_instance_get_position, pos10, ":instance"),# 获取实例坐标
            (position_set_z, pos10, 10000),
            (position_set_z_to_ground_level, pos10),# 保险起见,让它坐标与地面对齐(这个地面是泛义)
            (try_for_agents, ":agent_no", pos10, 300),# 以该实例坐标为中心三米范围内循环agents, 这里的半径是浮点数,所以必须得set_fixed_point_multiplier,WSE2和战团本体定点数在这里是不一样的
比如设置定点数为1000,WSE2这里的范围单位就是CM,而战团这里的范围单位就是1/1000米

              # 一些判断
              (agent_is_alive, ":agent_no"),
              (agent_is_human, ":agent_no"),
              (agent_is_non_player, ":agent_no"),
              (agent_slot_eq, ":agent_no", slot_agent_is_running_away, 0),
              (agent_get_horse, reg1, ":agent_no"),
              (eq, reg1, -1),
              (agent_get_combat_state, reg1, ":agent_no"),# 非战斗状态
              (neq, reg1, 3),
              (neq, reg1, 4),
              (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),# 获取该agent的远程武器,在外部计算,减少计算量 [1]
              (gt, ":ranged_weapon", 0),
              (agent_get_ammo, ":ammo", ":agent_no", 0),
              (le, ":ammo", 10),# 弹药较少
              (item_slot_eq, ":ranged_weapon", slot_ranged_weapon_ammo_type, ":item_type"),# 获取该远程武器对应弹药,在外部定义,减少计算量 [2]
              (try_begin),                #排除
                (eq, ":item_type", itp_type_thrown),# 如果是投掷类弹药,则需要判断是否强掷技能够高
                (agent_get_troop_id, ":troop_no", ":agent_no"),
                (store_skill_level, reg1, "skl_power_throw", ":troop_no"),
                (item_get_difficulty, reg2, ":item_id"),
                (this_or_next|le, ":ammo", 2), # 弹药相对弓弩类更苛刻
                (lt, reg1, reg2),
              (else_try),
                (agent_slot_ge, ":agent_no", slot_agent_has_ammo_item, 1),#  获取该agent远程武器有弹药类装备或者有空的装备栏,在外部计算,减少大量计算量 [3]
                (try_begin),
                  (agent_get_crouch_mode, reg1, ":agent_no"),# 获取该agent下蹲姿态,如果是站立,则下蹲。需要在module.in启用下蹲 [4]
                  (eq, reg1, 0),
                  # agent下蹲后,如果不是弩手在第一排坚守,由于引擎作用会自动起来
                  (agent_set_crouch_mode, ":agent_no", 1),
                (try_end),
                (try_begin),
                  (agent_slot_eq, ":agent_no", slot_agent_has_ammo_item, 1),# 1代表有有弹药类装备,补充弹药
                  (agent_refill_ammo, ":agent_no"),
                (else_try),
                  (agent_slot_eq, ":agent_no", slot_agent_has_ammo_item, 2),# 2代表没有弹药类装备且有额外空间
                  (agent_equip_item, ":agent_no", ":item_id"), # 装备该item
                (try_end),
                # (display_message, "@pick up amount of ammo!"),
                (scene_prop_set_prune_time, ":instance", 0),# 立即删除实例 [5]
                (break_loop),#WSE,非WSE开发的可通过其他方法实现退出循环操作
              (try_end),
            (try_end),
          (try_end),
        (try_end),
        (eq, "$ai_pick_up_ammo", 2),# 是否启用AI拾取单支类弹药
        (try_for_prop_instances, ":instance", ":item_id", somt_spawned_single_ammo_item),# 这里的somt_spawned_single_ammo_item就是单支类弹药类型的 [6]
          (prop_instance_is_valid, ":instance"),# 一个保险
          # (try_begin),
          # (ge, "$cheat_mode", 1),
          # (str_store_item_name, s1, ":item_id"),
          # (display_message, "@missile: {s1}"),
          # (try_end),
          #以下内容与上面差不多,注释省略
          (prop_instance_get_position, pos10, ":instance"),
          (position_move_y, pos10, 50, 0),# 坐标是在箭尾
          (position_set_z, pos10, 10000),
          (position_set_z_to_ground_level, pos10),
          (try_for_agents, ":agent_no", pos10, 300),
            (agent_is_alive, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_non_player, ":agent_no"),
            (agent_slot_eq, ":agent_no", slot_agent_is_running_away, 0),

            (agent_get_horse, reg1, ":agent_no"),
            (eq, reg1, -1),
            (agent_get_combat_state, reg1, ":agent_no"),
            (neq, reg1, 3),
            (neq, reg1, 4),
            (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),
            (gt, ":ranged_weapon", 0),
            (agent_get_ammo, ":ammo", ":agent_no", 0),
            (le, ":ammo", 10),
            (item_slot_eq, ":ranged_weapon", slot_ranged_weapon_ammo_type, ":item_type"),
            (try_begin),
              (eq, ":item_type", itp_type_thrown),
              (agent_get_troop_id, ":troop_no", ":agent_no"),
              (store_skill_level, reg1, "skl_power_throw", ":troop_no"),
              (item_get_difficulty, reg2, ":item_id"),
              (this_or_next|le, ":ammo", 2),
              (lt, reg1, reg2),
            (else_try),
               (agent_slot_ge, ":agent_no", slot_agent_has_ammo_item, 1),
              (try_begin),
                (agent_get_crouch_mode, reg1, ":agent_no"),
                (eq, reg1, 0),
                (agent_set_crouch_mode, ":agent_no", 1),
              (try_end),
              (try_begin),
                (agent_slot_eq, ":agent_no", slot_agent_has_ammo_item, 1),
                (val_add, ":ammo", 1),# 弹药 + 1
                (agent_set_ammo, ":agent_no", ":item_id", ":ammo"),
              (else_try),
                (agent_slot_eq, ":agent_no", slot_agent_has_ammo_item, 2),
                (agent_equip_item, ":agent_no", ":item_id"),
                (agent_set_ammo, ":agent_no", ":item_id", 1),# 弹药设为1
              (try_end),
              (scene_prop_set_prune_time, ":instance", 0),
              (break_loop),#WSE
            (try_end),
          (try_end),
        (try_end),
      (try_end),
    ])
]
[/spoiler]
[spoiler=补充]
[1] 可在生成agents的触发器计算,将slot值设为其拥有的远程武器
[2] 可在开始游戏的脚本定义,给所有远程武器设定slot,值为对应的弹药类型
[3]可在agent换武器的触发器计算,如果agent有自己远程武器对应的弹药类装备则设slot为1,如果没有并且有额外装备栏空间则设为2
[4] 有能力的可单独做一个弯腰捡东西的动画
[5] OP解释:"but works only with spawned items, for props it is better to practice reuse, for useless props turn off physics and hide them"。详细可看关于场景物化item装备的具体用处 - MOD制作技术区 - 骑马与砍杀中文站论坛 - Powered by Discuz! (mountblade.com.cn)
[6] 知识补充,大部分摘自Modding Q&A [For Quick Questions and Answers] | 页 260 | TaleWorlds Forums :
#object types for "try_for_prop_instances" operation
somt_object = 1   # Scene props (编辑模式放置)
somt_entry = 2   # Entry points 入口点
somt_item = 3  # Scene items (编辑模式放置)
somt_baggage = 4 # 箱子之类的容器?
somt_flora = 5 # 植物类 (trees, rocks, ...)
somt_passage = 6 # Passages 不太了解
somt_spawned_item = 7 # Spawned items (玩家丢弃)
somt_spawned_single_ammo_item = 8 # Spawned items (弹药击中生成)
somt_spawned_unsheathed_item = 9 #   Spawned items 其他dead掉落还是携带模型类?
somt_shield = 10 # 盾牌? 不知是什么
somt_temporary_object = 11 # 临时的?[/spoiler]
[spoiler=测试视频]

[/spoiler]
进一步优化
1. dead掉落弹药和射出去的弹药分开计算,并且触发时间错开来;
2.、把所有弹药类item物品放在一起,native排除教程和训练用的,就可以在module_constants.py里定义ammo_begin = "itm_arrows",ammo_end = "itm_pilgrim_disguise",然后循环的时候只循环弹药区间即可




















作者: ggfgfgf    时间: 2023-8-6 18:20
这个可以,不过恕我直言,这个教程有点模糊,实现这个跟搞逆向一样,没有WSE的真实,令人发指,不过还是非常感谢您分享,请问可以用在mod中么
作者: 武安apk43    时间: 2023-8-6 20:20
ggfgfgf 发表于 2023-8-6 18:20
这个可以,不过恕我直言,这个教程有点模糊,实现这个跟搞逆向一样,没有WSE的真实,令人发指,不过还是非 ...

我的代码除了一个break_loop,退出循环操作,其他都没用到wse的op

发这个出来就是分享给大家,随便用。不过我还是希望credit里有我
作者: 武安apk43    时间: 2023-8-6 20:24
本帖最后由 武安apk43 于 2023-8-6 20:27 编辑
ggfgfgf 发表于 2023-8-6 18:20
这个可以,不过恕我直言,这个教程有点模糊,实现这个跟搞逆向一样,没有WSE的真实,令人发指,不过还是非 ...

最核心的就是scene_spawned_item_get_num_instances,scene_spawned_item_get_instance还有try_for_prop_instances时用到的somt_XXX,还有性能优化也是非常重要,因为有三层循环。
判断agent的装备部分全部在其他的ti触发器上计算,然后try_for_agents用坐标限定循环距离范围。分类讨论判断agent装备情况也是很关键的
作者: ggfgfgf    时间: 2023-8-7 14:28
斗胆献丑了,补充了下,不完美啊,性能还需拆分操作优化,我写一起,做个备忘script.py部分

#script_cf_item_is_missile
#return if item is missile
#INPUT: param1 = item_id
#OUTPUT: boolean
        ("cf_item_is_missile",
        [
                (store_script_param, ":item_id", 1),
                (assign, ":result",1),
                (try_begin),
                        (item_get_type, ":item_type", ":item_id"),
                        (neq,":item_type",itp_type_thrown),
                        (neq,":item_type",itp_type_arrows),
                        (neq,":item_type",itp_type_bolts),
                        (neq,":item_type",itp_type_bullets),
                        (assign, ":result",0),
                (try_end),
                (eq, ":result", 1),
        ]),       
       
#script_cf_agent_has_ammo
#return if agent has right ammo
#INPUT: param1 = agent_no
#OUTPUT: false = have space without ammo,true = have ammo
        ("cf_agent_has_ammo",
        [
                (store_script_param, ":agent_no", 1),
                (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),
                (assign, ":result", 1),
                (try_for_range, ":item", 0, 4),
                        (agent_get_item_slot, ":item_id", ":agent_no", ":item"),
                        (try_begin),
                                (eq, ":item_id", -1),
                                (assign, ":result", 0),
                        (else_try),
                                (item_get_type, ":item_type", ":item_id"),
                                (item_slot_eq, ":ranged_weapon", slot_ranged_weapon_ammo_type, ":item_type"),
                                (assign, ":result", 1),
                        (try_end),
                (try_end),
                (eq, ":result", 1),
        ]),       


game_start添加
#Items:
        (try_for_range, ":item_id", all_items_begin, all_items_end),
                (item_get_type, ":item_type", ":item_id"),
                        (try_begin),
                                (eq, ":item_type", itp_type_bow),
                                (item_set_slot, ":item_id", slot_ranged_weapon_ammo_type, itp_type_arrows),
                        (else_try),
                                (eq, ":item_type", itp_type_crossbow),
                                (item_set_slot, ":item_id", slot_ranged_weapon_ammo_type, itp_type_bolts),
                        (else_try),
                                (eq, ":item_type", itp_type_thrown),
                                (item_set_slot, ":item_id", slot_ranged_weapon_ammo_type, itp_type_thrown),
                        (try_end),
        (try_end),
       
# Troops:


# Assign banners and renown.

costants.py添加红色(部分已位于文件中,方便搜索)
slot_item_multiplayer_item_class   = 60 #temporary, can be moved to higher values
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher value


slot_ranged_weapon_ammo_type =62#0 for non-ranged weapons


########################################################
##  AGENT SLOTS            #############################
########################################################

........
slot_agent_ranged_weapon = 28


########################################################
##  FACTION SLOTS          #############################
########################################################


heard_common.py添加
#object types for "try_for_prop_instances" operation
somt_object = 1   # Scene props (Edit mode placement)
somt_entry = 2   # Entry points
somt_item = 3  # Scene items (Edit mode placement)
somt_baggage = 4 # Containers like boxes?
somt_flora = 5 # Plants (trees, rocks, ...)
somt_passage = 6 # Passages
somt_spawned_item = 7 # Spawned items (Player discarded)
somt_spawned_single_ammo_item = 8 # Spawned items (Ammunition spawns when hit)
somt_spawned_unsheathed_item = 9 #   Spawned items Other dead agent drops
somt_shield = 10 # shield
somt_temporary_object = 11 # temp



missson_templates.py添加
ai_pick_up_ammo = (
        3, 0, 0, [(neg|all_enemies_defeated),],
        [
        (try_for_range, ":item_id", all_items_begin, all_items_end),
                (call_script, "script_cf_item_is_missile", ":item_id"),
                (try_begin),
                        (scene_spawned_item_get_num_instances, ":instance_number", ":item_id"),
                        (gt, ":instance_number", 0),
                        (item_get_type, ":item_type", ":item_id"),
                        (try_for_range, ":index", 0, ":instance_number"),
                                (scene_spawned_item_get_instance, ":instance", ":item_id", ":index"),
                                (prop_instance_get_position, pos10, ":instance"),
                                (position_set_z_to_ground_level, pos10),
                (assign,":run",1),
                                (try_for_agents, ":agent_no", pos10, 300),
                                        (eq,":run",1),
                                        (agent_is_alive, ":agent_no"),
                                        (agent_is_human, ":agent_no"),
                                        (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),
                                        (gt, ":ranged_weapon", 0),
                                        (agent_is_non_player, ":agent_no"),
                                        (agent_slot_eq, ":agent_no", slot_agent_is_running_away, 0),
                                        (agent_get_horse, ":horse", ":agent_no"),
                                        (eq, reg1, ":horse"),
                                        # (agent_get_combat_state, reg1, ":agent_no"),#
                                        # (neq, reg1, 3),
                                        # (neq, reg1, 4),
                                        # (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),#
                                        (agent_get_ammo, ":ammo", ":agent_no", 0),
                                        (item_slot_eq, ":ranged_weapon", slot_ranged_weapon_ammo_type, ":item_type"),
                                        (try_begin),
                                                (eq, ":item_type", itp_type_thrown),
                                                (agent_get_troop_id, ":troop_no", ":agent_no"),
                                                (store_skill_level, ":troop_skl", "skl_power_throw", ":troop_no"),
                                                (item_get_difficulty, ":item_skl", ":item_id"),
                                                # (this_or_next|le, ":ammo", 2),
                                                (lt, ":troop_skl", ":item_skl"),
                                        (else_try),
                                                (agent_set_crouch_mode, ":agent_no", 1),
                                                (try_begin),
                                                        (call_script, "script_cf_agent_has_ammo", ":agent_no"),
                                                        (agent_refill_ammo, ":agent_no"),
                                                (else_try),
                                                        (agent_equip_item, ":agent_no", ":item_id"),
                                                (try_end),
                                                (scene_prop_set_prune_time, ":instance", 0),
                                                (assign,":run",0),
                                        (try_end),
                                (try_end),
                        (try_end),
                (try_end),
       
                (try_for_prop_instances, ":instance", ":item_id", somt_spawned_single_ammo_item),#
                        (prop_instance_is_valid, ":instance"),
                        (prop_instance_get_position, pos10, ":instance"),
                        (position_move_y, pos10, 50, 0),
                        (position_set_z_to_ground_level, pos10),
                        (assign,":run",1),
                        (try_for_agents, ":agent_no", pos10, 300),
                                (eq,":run",1),
                                (agent_is_alive, ":agent_no"),
                                (agent_is_human, ":agent_no"),
                                (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),
                                (gt, ":ranged_weapon", 0),
                                (agent_is_non_player, ":agent_no"),
                                (agent_slot_eq, ":agent_no", slot_agent_is_running_away, 0),


                                (agent_get_horse, ":horse", ":agent_no"),
                                (eq, ":horse", -1),
                                # (agent_get_combat_state, reg1, ":agent_no"),
                                # (neq, reg1, 3),
                                # (neq, reg1, 4),
                               
                                # (agent_get_ammo, ":ammo", ":agent_no", 0),
                                # (le, ":ammo", 10),
                                (item_slot_eq, ":ranged_weapon", slot_ranged_weapon_ammo_type, ":item_type"),
                                (try_begin),
                                        (eq, ":item_type", itp_type_thrown),
                                        (agent_get_troop_id, ":troop_no", ":agent_no"),
                                        (store_skill_level, ":troop_skl", "skl_power_throw", ":troop_no"),
                                        (item_get_difficulty, ":item_skl", ":item_id"),
                                                        # (this_or_next|le, ":ammo", 2),
                                        (lt, ":troop_skl", ":item_skl"),
                                (else_try),
                                        (agent_set_crouch_mode, ":agent_no", 1),
                                        (try_begin),
                                                (call_script, "script_cf_agent_has_ammo", ":agent_no"),
                                                (val_add, ":ammo", 1),
                                                (agent_set_ammo, ":agent_no", ":item_id", ":ammo"),
                                        (else_try),
                                                (agent_equip_item, ":agent_no", ":item_id"),
                                                (agent_set_ammo, ":agent_no", ":item_id", 1),
                                        (try_end),
                                        (scene_prop_set_prune_time, ":instance", 0),
                                        (assign,":run",0),
                                (try_end),
                        (try_end),
                (try_end),
        (try_end),
        ])


free_order_begin = (ti_once, 0, 0, [],
       [
           (try_for_agents, ":agent"),#get agent_ranged_weapon
                   (agent_set_slot,":agent",slot_agent_ranged_weapon,0),
                   (agent_get_wielded_item, ":item_id", ":agent"),
                   (item_get_type, ":item_type", ":item_id"),
                   (try_begin),
                           (eq,":item_type",itp_type_thrown),
                           (agent_set_slot,":agent",slot_agent_ranged_weapon,":item_id"),
                   (else_try),
                           (eq,":item_type",itp_type_bow),
                           (agent_set_slot,":agent",slot_agent_ranged_weapon,":item_id"),
                   (else_try),
                           (eq,":item_type",itp_type_crossbow),
                           (agent_set_slot,":agent",slot_agent_ranged_weapon,":item_id"),
                   (try_end),
           (try_end),
           ])




作者: 武安apk43    时间: 2023-8-7 16:32
本帖最后由 武安apk43 于 2023-8-7 16:45 编辑
ggfgfgf 发表于 2023-8-7 14:28
斗胆献丑了,补充了下,不完美啊,性能还需拆分操作优化,我写一起,做个备忘script.py部分

#script_cf_ ...

我发现有几个问题哈:
1. call_script, "script_cf_agent_has_ammo"只有agent有对应弹药装备才通过,所以后面的(else_try)包含了没有额外装备栏的情况,这可能会导致agent替换原有装备。你可以看看我最新修改的,在前面添加了一句(agent_slot_ge, ":agent_no", slot_agent_has_ammo_item, 1);
2. 完全可以把两个判断写一起,比如你的可以这样改:

                  (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),
                (assign, ":has_space", 0),
                (assign, ":result", 0),
                (try_for_range, ":item", 0, 4),
                        (agent_get_item_slot, ":item_id", ":agent_no", ":item"),
                        (try_begin),
                                (eq, ":item_id", -1),
                                (assign, ":has_space", 1),
                        (else_try),
                                (item_get_type, ":item_type", ":item_id"),
                                (item_slot_eq, ":ranged_weapon", slot_ranged_weapon_ammo_type, ":item_type"),
                                (assign, ":result", 1),
                        (try_end),
                (try_end),

                (try_begin),
                        (eq, ":result", 0),

                        (eq, ":has_space", 1),
                        (assign, ":result", 2),
                (try_begin),

这样判断":result"大于0就排除了没有额外装备栏的情况。

3.这个其实完全可以写到ti_on_item_wielded里,节省大量计算。因为本质上这个是判断agent是否有ammo类装备,而不是判断是否有弹药。而且几乎所有兵种都是带近战武器的,AI弹药耗尽会自动换武器,包括AI拾取新的弹药装备之后也会触发。所以我用的slot储存这两种情况,而不是调用脚本计算。还有你看我最后新补充了优化方案,也可以节省很多计算量

4.你把slot_agent_ranged_weapon写在ti_once里,有没有考虑过增援生成的agent?可以写在ti_on_agent_spawn或者ti_on_item_wielded里;

其实我之所以不给全我的代码,是因为我的把判断装备部分全都和自动分组系统写在一起了,ti_on_item_wielded,ti_on_item_unwielded,ti_on_agent_mount和ti_on_agent_dismount四个触发器调用脚本。不过也正是因为如此我不清楚ti_on_agent_spawn里判断装备是否有效,没测。因为有可能agent的状态并未更新,比如在ti_on_agent_dismount里判断agent是否有马,就会得到之前骑的马


还有你粗心的写错了,一次性触发应该是(0, 0, ti_once, 而不是(ti_once, 0, 0,







作者: ggfgfgf    时间: 2023-8-7 20:07
本帖最后由 ggfgfgf 于 2023-8-7 20:37 编辑
武安apk43 发表于 2023-8-7 16:32
我发现有几个问题哈:
1. call_script, "script_cf_agent_has_ammo"只有agent有对应弹药装备才通过,所 ...

感谢大佬回复,我的mod修改了增援,没有增援,一次全上,所以不用担心,哈哈,您的mod我玩了,厉害,着色器很优秀
ti_on_item_wielded调用这个脚本把reg0赋值给slot
#script_cf_agent_has_ammo
#return if agent has right ammo to slot_agent_has_ammo_item
#INPUT: param1 = agent_no
#OUTPUT:reg0:1 = have ammo,2 = have space without ammo
        ("cf_agent_has_ammo",
        [
                (store_script_param, ":agent_no", 1),
                (agent_get_slot, ":ranged_weapon", ":agent_no", slot_agent_ranged_weapon),
        (assign, ":has_space", 0),
        (assign, ":result", 0),
        (try_for_range, ":item", 0, 4),
                        (agent_get_item_slot, ":item_id", ":agent_no", ":item"),
                        (try_begin),
                                (eq, ":item_id", -1),
                                (assign, ":has_space", 1),
                        (else_try),
                                (item_get_type, ":item_type", ":item_id"),
                                (item_slot_eq, ":ranged_weapon", slot_ranged_weapon_ammo_type, ":item_type"),
                                (assign, ":result", 1),
                        (try_end),
        (try_end),


        (try_begin),
            (eq, ":result", 0),
            (eq, ":has_space", 1),
            (assign, ":result", 2),
        (try_begin),
                (assign,reg0,":result"),
        ]),        




作者: ggfgfgf    时间: 2023-8-7 23:00
武安apk43 发表于 2023-8-7 16:32
我发现有几个问题哈:
1. call_script, "script_cf_agent_has_ammo"只有agent有对应弹药装备才通过,所 ...

大佬能问您个问题么?很好奇您mod仿砍2可以穿过人群挤开队友的功能是怎么实现的?跟WSE有关吗,感谢

作者: 武安apk43    时间: 2023-8-8 00:08
本帖最后由 武安apk43 于 2023-8-8 00:34 编辑
ggfgfgf 发表于 2023-8-7 23:00
大佬能问您个问题么?很好奇您mod仿砍2可以穿过人群挤开队友的功能是怎么实现的?跟WSE有关吗,感谢

[strike]
我其实是受TW官网一个帖子启发的,你可以看看,没有用WSE。https://forums.taleworlds.com/index.php?threads/pierce-through-multiple-enemies-in-a-line.458998/#post-9872322

[/strike]
不好意思看错了,我以为你说的武器贯穿。那个挤过友军的实际原理很简单,就是以玩家为中心循环附近的agent,然后分类讨论各种情况,通过set position 让AI移动而已,有点用,但也不是非常有效果
作者: 武安apk43    时间: 2023-9-20 18:27
补充一个:
(try_for_agents, <agent_no>[, <position_no>, <radius_fixed_point>]),, 这里的半径是浮点数,所以必须得set_fixed_point_multiplier
作者: 武安apk43    时间: 2023-9-28 23:48
本帖最后由 武安apk43 于 2023-9-29 00:01 编辑

(try_for_agents, ":agent_no", pos10, 300),这里的半径是浮点数,所以必须得set_fixed_point_multiplier,WSE2和战团本体定点数在这里是不一样的
比如设置
定点数为1000,WSE2这里的范围单位就是CM,而战团这里的范围单位就是1/1000米




欢迎光临 骑马与砍杀中文站论坛 (https://bbs.mountblade.com.cn/) Powered by Discuz! X3.4