本帖最后由 杰喵喵 于 2024-2-20 11:30 编辑
简易的炮兵,使用场景道具:
参考了九章大佬的投石机做的:
【战团】简易的简单投石机 - MOD制作技术区 - 骑马与砍杀中文站论坛 - Powered by Discuz! (mountblade.com.cn)
测试效果视频:
https://www.bilibili.com/video/B ... id_from=333.999.0.0
直接上代码:
1.mt部分:
- ##攻城武器部分
- common_siege_weapon = (0, 0, 1,
- [
- (key_is_down|this_or_next,key_n),
- (key_clicked,key_n),
- ],
- [
- (get_player_agent_no, ":player_agent"),
- (agent_is_alive, ":player_agent"),
- (agent_get_team,":team",":player_agent"),
- (init_position,pos40),
- (agent_get_position,pos40,":player_agent"),
- (set_spawn_position, pos40),
- (spawn_scene_prop,"spr_war_machinery_huopao_gear"),
- (assign,":sprop_instance",reg0),
- (scene_prop_set_team, ":sprop_instance", ":team"),
- (scene_prop_get_team, ":scene_prop_team", ":sprop_instance"),
- (position_move_x, pos40, -150),
- (set_spawn_position,pos40),
- (spawn_agent,"trp_swadian_sergeant"),#刷新兵种
-
- (agent_force_rethink, reg0),#强制重新思考
- (agent_ai_set_aggressiveness, reg0, 2500),#攻击性
- (agent_set_slot, reg0, slot_agent_courage_score, 12000),#战场勇气
-
- (assign,":agent_a",reg0),
- (agent_set_team,":agent_a",":scene_prop_team"),
- (scene_prop_set_slot,":sprop_instance",scene_prop_in_use_for_agent,":agent_a"),
- (agent_set_speed_modifier, ":agent_a", 100),
- (agent_set_position,":agent_a",pos40),
-
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (prop_instance_animate_to_position,":sprop_instance",pos45,100),
-
- ]
- )
复制代码 2.场景道具部分
- #不设置血量和碰撞体减少难度
- ("war_machinery_huopao_gear",sokf_moveable,"huopao_gear","0",
- [
- (ti_on_scene_prop_init,
- [
- (store_trigger_param_1, ":sprop_instance"),
- (scene_prop_set_slot, ":sprop_instance", scene_prop_effect_done,0),
- (scene_prop_set_slot, ":sprop_instance", scene_prop_ammo_count,20),
- ]),
-
- (ti_on_scene_prop_animation_finished,
- [
-
- (store_trigger_param_1, ":sprop_instance"),
- (scene_prop_get_slot, ":ctrl_agent", ":sprop_instance", scene_prop_in_use_for_agent),
- (gt,":ctrl_agent",0),
- (agent_is_alive, ":ctrl_agent"),
- (agent_is_human, ":ctrl_agent"),
-
- (agent_get_team,":agent_team",":ctrl_agent"),
- (agent_get_division, ":agent_division", ":ctrl_agent"),
- (team_get_movement_order, ":movement_order", ":agent_team", ":agent_division"),
-
- #剩余弹药处理,一但弹药为零就不会进入这里
- (assign, ":run_go", 1),
- (scene_prop_get_slot, ":ammo_count", ":sprop_instance", scene_prop_ammo_count),
- (try_begin),
- (lt, ":ammo_count",1),
- (agent_clear_scripted_mode,":ctrl_agent"),
- (assign, ":run_go", 0),
- #隐身处理
- (scene_prop_get_visibility, ":flag_visibility", ":sprop_instance"),
- (try_begin),
- (ge, ":flag_visibility",1),
- (scene_prop_set_visibility, ":sprop_instance", 0),
- (try_end),
- (try_end),
- (eq, ":run_go", 1),
-
- #ctrl_agent 与火炮距离计算
- (assign,":distance_instance",300),
- (try_begin),
- (agent_get_position,pos52,":ctrl_agent"),
- (prop_instance_get_position,pos53,":sprop_instance"),
- (get_distance_between_positions,":distance_instance", pos52,pos53),
- (try_end),
-
- #敌人接近计算
- (assign,":cached_enemie",0),#没有敌人接近
- (agent_ai_get_num_cached_enemies, ":num", ":ctrl_agent"),
- (try_begin),
- (ge,":num",1),
- (agent_ai_get_cached_enemy, ":enemies", ":ctrl_agent", 0),
- (agent_is_alive,":enemies"),
- (agent_get_position,pos52,":enemies"),
- (agent_get_position,pos53,":ctrl_agent"),
- (get_distance_between_positions,":distance_enemy", pos52,pos53),
- (le,":distance_enemy",300),
- (assign,":cached_enemie",1),#有敌人接近
- (try_end),
-
-
- #ctrl_agent 战斗状态是否会丢下火炮
- (assign,":drop_the_gun",0),
- (try_begin),
- (agent_slot_eq, ":ctrl_agent", slot_agent_is_running_away, 1),#逃跑 #且命令不是撤退,掉下火,炮
- (neg|eq,":movement_order",mordr_retreat),
- (assign,":drop_the_gun",1),
- (else_try),
- (eq,":cached_enemie",1),#有敌人接近
- (assign,":drop_the_gun",1),
- (try_end),
-
- #射击条件计算 ctrl_agent的大腿l位置可以看到target的头部
- (assign, ":shoot", 0),
- (try_begin),
- (agent_ai_get_look_target, ":target", ":ctrl_agent"),
- (gt, ":target", -1),
- (agent_is_alive,":target"),
- (agent_get_bone_position, pos52, ":target", 9,1),#头部
- (agent_get_bone_position, pos53, ":ctrl_agent", 1,1),#大腿l位置
- (position_has_line_of_sight_to_position, pos53, pos52),
- (get_distance_between_positions,":distance_enemy",pos53,pos52),
- (is_between,":distance_enemy", 300,25000),
- (val_add, ":shoot", 1),
- (try_end),
-
- (try_begin),#火炮允许射击 需要敌人不接近且满足射击条件
- (eq,":drop_the_gun",0),
- (eq,":cached_enemie",0),
- (ge, ":shoot", 1),
-
- (agent_set_speed_modifier,":ctrl_agent",50),
- #强制设定ctrl_agent 看向 target 的头部
- (agent_get_bone_position, pos52, ":target", 9,1),
- (agent_set_look_target_position,":ctrl_agent",pos52),
- (prop_instance_get_position,pos35,":sprop_instance"),
- (agent_get_look_position, pos36, ":ctrl_agent"),
- (position_move_y,pos35,200,0),
- (position_move_y,pos36,200,0),
- (position_get_rotation_around_z, ":agent_look_around_z", pos36),
- (position_get_rotation_around_z, ":sprop_instance_around_z", pos35),
- (store_sub,":sub_value",":agent_look_around_z",":sprop_instance_around_z"),
- (assign,":sub_value_a",":sub_value"),
- (val_abs,":sub_value_a"),
- #火炮跟随ctrl_agent视角计算
- (assign,":rotate_z",0),
- (try_begin),
- (ge,":sub_value_a",3),
- (store_div,":rotate_z",":sub_value_a",3),
- (val_max,":rotate_z",3),
- (try_begin),
- (gt,":sub_value",0),
- (val_mul,":rotate_z",1),
- (else_try),
- (lt,":sub_value",0),
- (val_mul,":rotate_z",-1),
- (try_end),
- (try_end),
-
- (try_begin),#火炮移动瞄准目标
- (neg|eq,":rotate_z",0),
- (prop_instance_get_position,pos45,":sprop_instance"),
- (position_rotate_z,pos45,":rotate_z"),
- (position_set_z_to_ground_level,pos45),
- (prop_instance_animate_to_position,":sprop_instance",pos45,10),
- (position_move_x, pos45, -150),
- (position_copy_rotation,pos45,pos36),
- #(agent_set_position,":ctrl_agent",pos45),快速移动 ctrl_agent
- (agent_set_scripted_destination,":ctrl_agent",pos45),
- (else_try),#火炮开炮
- (prop_instance_get_position,pos45,":sprop_instance"),
- (position_set_z_to_ground_level,pos45),
- (prop_instance_animate_to_position,":sprop_instance",pos45,1),
- (position_move_x, pos45, -150),
- (agent_set_scripted_destination,":ctrl_agent",pos45),
-
- (scene_prop_get_slot, ":effect_done", ":sprop_instance", scene_prop_effect_done),
- #发射时间间隔设置
- (assign,":cunt_done",300),
- (try_begin),
- (lt,":effect_done",":cunt_done"),
- (val_add,":effect_done",1),
- (scene_prop_set_slot,":sprop_instance",scene_prop_effect_done,":effect_done"),
- (try_end),
- (ge,":effect_done",":cunt_done"),
- (scene_prop_set_slot,":sprop_instance",scene_prop_effect_done,0),
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (position_move_y,pos45,200,0),
- (position_move_z,pos45,100,0),
- (position_copy_rotation,pos45,pos36),
- (store_random_in_range, ":var_15", -2, 2),
- (store_random_in_range, ":var_16", -2, 2),
- (call_script,"script_cf_fire_round_ai_c",":distance_enemy"),
- (assign, ":rotate_x_floating", reg30),
- (val_div, ":rotate_x_floating", 10),
- (set_fixed_point_multiplier, 10),
- (convert_to_fixed_point, ":rotate_x_floating"),
- (set_fixed_point_multiplier, 10),
- (position_rotate_x_floating, pos45, ":var_16"),
- (position_rotate_z_floating, pos45, ":var_15"),
- (position_rotate_x_floating, pos45, ":rotate_x_floating"),
- (set_fixed_point_multiplier, 1),
- (set_fixed_point_multiplier, 1),
- (store_random_in_range, ":var_16", 56, 66),
- (convert_to_fixed_point, ":var_16"),
- (add_missile, ":ctrl_agent", pos45, ":var_16", "itm_gun_barrel", 0, "itm_artillery_ammunition", 0),
- (particle_system_burst, "psys_pistol_smoke_big", pos45,25),
- (play_sound_at_position,"snd_gun_barrel_fire",pos45,0),
- (val_sub,":ammo_count",1),
- (scene_prop_set_slot, ":sprop_instance", scene_prop_ammo_count,":ammo_count"),
- (try_end),
- (else_try),#非战斗中ctrl_agent 远离了火炮归位,回来拉火炮
- (eq,":drop_the_gun",0),
- (ge,":distance_instance",300),
- (prop_instance_get_position,pos45,":sprop_instance"),
- (position_set_z_to_ground_level,pos45),
- (prop_instance_animate_to_position,":sprop_instance",pos45,1),
- (position_move_x, pos45, -150),
- (agent_set_scripted_destination,":ctrl_agent",pos45),
- (agent_set_speed_modifier,":ctrl_agent",100),
- (else_try),#非战斗中ctrl_agent 自由移动火炮跟随
- (eq,":drop_the_gun",0),
- (agent_clear_scripted_mode,":ctrl_agent"),
- (init_position,pos50),
- (agent_get_position,pos50,":ctrl_agent"),
- (position_move_x,pos50,150),
- (position_move_y,pos50,-150),
- (position_set_z_to_ground_level,pos50),
- (prop_instance_animate_to_position,":sprop_instance",pos50,25),
- (agent_set_speed_modifier,":ctrl_agent",50),
- (else_try),#ctrl_agent 战斗或者逃跑,火炮丢在原地方
- (eq,":drop_the_gun",1),
- (prop_instance_get_position,pos45,":sprop_instance"),
- (position_set_z_to_ground_level,pos45),
- (prop_instance_animate_to_position,":sprop_instance",pos45,1),
- (agent_set_speed_modifier,":ctrl_agent",100),
- (try_end),
-
-
- ]),
- ]),
复制代码
3.脚步部分,九章大佬的简易瞄准
- #九章大佬的投石机代码-开始#
- ("cf_fire_round_ai_c",#简易测距c(60弹速,最大射程24000)返回值需要浮点化
- [
- (store_script_param, ":var_14", 1),
- (assign,":time",0),
- (try_begin),
- (le, ":var_14", 3000),
- (assign,":var_14",0),
- (assign,":time",0),
- (else_try),
- (is_between, ":var_14", 3000,4400),
- (val_div, ":var_14", 150),#1-2
- (assign,":time",1),
- (else_try),
- (is_between, ":var_14", 4400,5200),
- (val_div, ":var_14", 130),#2-3
- (assign,":time",1),
- (else_try),
- (is_between, ":var_14", 5200,7000),
- (val_div, ":var_14", 120),#3-4
- (assign,":time",1),
- (else_try),
- (is_between, ":var_14", 7000,11400),
- (val_div, ":var_14", 104),#4-5
- #(val_add, ":var_14", -1),
- (assign,":time",2),
- (else_try),
- (is_between, ":var_14", 11400,14500),
- (val_div, ":var_14", 99),#5-6
- #(val_add, ":var_14", -1),
- (assign,":time",3),
- (else_try),
- (is_between, ":var_14", 14500,17100),
- (val_div, ":var_14", 93),#6-7
- #(val_add, ":var_14", -1),
- (assign,":time",3),
- (else_try),
- (is_between, ":var_14", 17100,18900),
- (val_div, ":var_14", 88),#7-8
- #(val_add, ":var_14", -1),
- (assign,":time",4),
- (else_try),
- (is_between, ":var_14", 18900,20400),
- (val_div, ":var_14", 84),#9-12
- #(val_add, ":var_14", -1),
- (assign,":time",5),
- (else_try),
- (is_between, ":var_14", 20400,21200),
- (val_div, ":var_14", 85),#12-15
- #(val_add, ":var_14", -1),
- (assign,":time",5),
- (else_try),
- (is_between, ":var_14", 21200,21600),
- (val_div, ":var_14", 78),#15-17
- #(val_add, ":var_14", -2),
- (assign,":time",5),
- (else_try),
- (is_between, ":var_14", 21600,22600),
- (val_div, ":var_14", 77),#17-20
- #(val_add, ":var_14", -2),
- (assign,":time",8),
- (else_try),
- (is_between, ":var_14", 22600,23100),
- (val_div, ":var_14", 73),#20-22
- #(val_add, ":var_14", -2),
- (assign,":time",6),
- (else_try),
- (is_between, ":var_14", 23100,23500),
- (val_div, ":var_14", 69),#20-22
- #(val_add, ":var_14", -2),
- (assign,":time",6),
- (else_try),
- (is_between, ":var_14", 23500,24000),
- (val_div, ":var_14", 64),#20-22
- #(val_add, ":var_14", -2),
- (assign,":time",7),
- (else_try),
- (is_between, ":var_14", 24000,99000),
- #(val_div, ":var_14", 64),#20-22
- #(val_add, ":var_14", -2),
- (assign,":var_14",55),
- (assign,":time",8),
- (try_end),
- (assign,reg30,":var_14"),
- (assign,reg31,":time"),
- #(try_end),
- ]),
复制代码
4.常量
- #工作计数
- scene_prop_effect_done = 33
- #弹药计数
- scene_prop_ammo_count = 34
复制代码
|