本帖最后由 a1550887802 于 2023-9-24 08:52 编辑
先说好,这个是个很简单的玩意,是为了简易添加的可以在攻城战使用的投石机,这里只有代码可供展示,没有任何酷炫的视觉效果,模型使用的是战团模型的修改版,音效使用的是战团自带的音效,没有使用新增的slot。虽然可以增加其他内容以设置为玩家也可以操作的,但是我也只做了ai的部分
没有额外的延伸内容,譬如控制ai开火或者停止,可以移动的逻辑,被破坏的情况,因为我也没时间做那么多,如果你有时间看我的垃圾代码还对此很感兴趣,那么可以尝试继续修改下去
注释很少,代码很乱,不要说我是个菜逼或者完全没有好习惯的编写者,我知道但是我懒得搞那么标准
演示视频在这里
https://www.bilibili.com/video/BV1jj411C7Y2/
废话不多说,直接上代码
########################module_mission_templates的部分#############################
只触发一次,在场景里遍历攻守双方的投石机标识,这些标识是仅仅在编制模式下显示的场景道具(scene_props)
- (0, 0, ti_once, [],
- [
- (try_for_prop_instances, ":origin_no","spr_zz_zz_z_defender_catapult_test_a_marker"),
- (scene_prop_set_team, ":origin_no", 0),
- (prop_instance_get_position,pos30,":origin_no"),
- (set_spawn_position, pos30),
- (spawn_scene_prop,"spr_zz_zz_z_catapult_test_a_code_only"),
- (assign,":scene_prop_e",reg0),
- (scene_prop_set_slot,":scene_prop_e",scene_prop_slots_end, ":origin_no"),
- (try_end),
-
- (try_for_prop_instances, ":origin_no","spr_zz_zz_z_attacker_catapult_test_a_marker"),
- (scene_prop_set_team, ":origin_no", 1),
- (prop_instance_get_position,pos30,":origin_no"),
- (set_spawn_position, pos30),
- (spawn_scene_prop,"spr_zz_zz_z_catapult_test_a_code_only"),
- (assign,":scene_prop_e",reg0),
- (scene_prop_set_slot,":scene_prop_e",scene_prop_slots_end, ":origin_no"),
- (try_end),
-
- ]),
复制代码
用于标注攻守双方的的场景道具,使用了sokf_invisible这个标签,该标签可以让使用此标签的场景道具只在编辑模式中显示
- ###############################################
- ###############################################sokf_invisible
- ("zz_zz_z_defender_catapult_test_a_marker",sokf_invisible,"defender_catapult_test_a",0, [
- (ti_on_scene_prop_init,
- [
- (store_trigger_param_1, ":sprop_instance"),
- (scene_prop_set_slot,":sprop_instance",scene_prop_slots_end,10000),
-
- ]),
- ]),
- ##################################################
- ###############################################sokf_invisible
- ("zz_zz_z_attacker_catapult_test_a_marker",sokf_invisible,"attacker_catapult_test_a",0, [
- (ti_on_scene_prop_init,
- [
- (store_trigger_param_1, ":sprop_instance"),
- (scene_prop_set_slot,":sprop_instance",scene_prop_slots_end,10000),
-
- ]),
- ]),
- ##################################################
复制代码 投石机和投石机的组件部分,这里利用了两个属于场景道具的触发条件,ti_on_scene_prop_init和ti_on_scene_prop_animation_finished
ti_on_scene_prop_init是在场景道具初始化时的触发,可以在这个时刻进行一些特殊的操作
ti_on_scene_prop_animation_finished,这个会检测场景道具在动作结束时进行一些操作
那么,如果在ti_on_scene_prop_init的时候进行了prop_instance_animate_to_position,在场景道具的动作结束时,就会触发ti_on_scene_prop_animation_finished这个条件,也就是说会触发这个条件所控制的触发器,如果在ti_on_scene_prop_animation_finished里又进行prop_instance_animate_to_position,再次等到结束结束,这样就会再次触发ti_on_scene_prop_animation_finished。这种利用了prop_instance_animate_to_position和ti_on_scene_prop_animation_finished两个条件进行的循环,就会一直循环触发下去。除非在代码中设定了不再继续执行动作的内容,否则这个循环不会停止。
- ##################################################投石机的基座,控制投石机的射击方向,还有整个射击流程的控制
- ("zz_zz_z_catapult_test_a_code_only",sokf_moveable|spr_hit_points(180),"catapult_test_a","bo_catapult_test_a",
- [
- (ti_on_scene_prop_init,
- [
- (store_trigger_param_1, ":sprop_instance"),
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (prop_instance_animate_to_position,":sprop_instance",pos45,500),
- (scene_prop_set_cur_hit_points, ":sprop_instance", 600),
- (init_position,pos50),
- (position_move_z, pos50, -50000),
- (set_spawn_position, pos50),
- (spawn_scene_prop,"spr_zz_zz_z_simple_catapult_test_b"),#生成投石机的弹射臂
- (assign,":scene_prop_c",reg0),
- (scene_prop_set_slot,":scene_prop_c",scene_prop_slots_end,":sprop_instance"),
- ]),
- (ti_on_scene_prop_animation_finished,
- [
-
- (store_trigger_param_1, ":sprop_instance"),
- (assign, ":l_distance",60),
- (assign, ":around_z_max",300),
-
- (assign, ":shoot", 0),
-
- (scene_prop_get_slot, ":scene_prop_slots_end", ":sprop_instance", scene_prop_slots_end),
- (scene_prop_get_slot, ":cc", ":sprop_instance", scene_prop_smoke_effect_done),
-
- (scene_prop_get_team, ":sprop_instance_team", ":scene_prop_slots_end"),
-
-
-
- (prop_instance_get_position,pos30,":scene_prop_slots_end"),
-
- (copy_position,pos45,pos30),
-
- (prop_instance_animate_to_position,":sprop_instance",pos45,500),
-
- (scene_prop_get_slot, ":cc", ":sprop_instance", scene_prop_smoke_effect_done),
- (scene_prop_get_hit_points, ":sprop_instance_ammo", ":sprop_instance"),
- (try_begin),
- (neq, ":cc", 1),
- (assign, ":close", 0),
- (get_player_agent_no, ":player_agent"),
-
- (try_for_agents,":cur_agent"),#设置投石机的操作者
- (neq, ":cur_agent", ":player_agent"),
- (neq, ":close", 1),
- (agent_is_alive, ":cur_agent"),
- (agent_is_human, ":cur_agent"),
- (agent_get_team, ":agent_team", ":cur_agent"),
- (eq, ":agent_team", ":sprop_instance_team"),
-
- (agent_get_slot, ":arena_team_set", ":cur_agent", slot_agent_arena_team_set),
- (neq, ":arena_team_set", 1),
-
- (try_for_range,":no",0,5),#这里会把投石机控制者的武器都拆下来,别问我为什么不用切换装备的操作,问就是为了省事
- (agent_get_item_slot, ":cur_weapon", ":cur_agent", ":no"),
- (gt,":cur_weapon",0),
- (agent_unequip_item, ":cur_agent", ":cur_weapon"),
- (try_end),
- (scene_prop_set_slot,":sprop_instance",scene_prop_ccoop_item_drop_start,":cur_agent"),
- (scene_prop_set_slot,":sprop_instance",scene_prop_smoke_effect_done,1),
- (agent_set_slot,":cur_agent",slot_agent_arena_team_set , 1),
-
- (assign, ":close", 1),
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (position_move_x, pos45, -180),
- (agent_set_speed_modifier, ":cur_agent", 1),
- (agent_set_position,":cur_agent",pos45),#
- (agent_set_scripted_destination,":cur_agent",pos45,),#图省事,把操纵者强制固定在投石机的一侧
- (try_end),
-
-
- (try_end),
-
-
- (eq, ":cc", 1),
- (try_begin),
- (scene_prop_get_slot, ":agent_a", ":sprop_instance", scene_prop_ccoop_item_drop_start),
- (agent_is_alive, ":agent_a"),
- (val_add, ":sprop_instance_ammo", 1),
- (scene_prop_set_cur_hit_points, ":sprop_instance", ":sprop_instance_ammo"),
-
- (assign, ":ctrl_agent", ":agent_a"),
-
-
-
-
- (copy_position,pos55,pos30),
- (agent_get_look_position, pos39, ":ctrl_agent"),#透过操纵者的视角控制投石机,因此其实玩家也可以操作投石机,只要玩家是操作者就行(但是没有写控制开火的那部分)
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (position_get_rotation_around_z, ":around_z_a", pos55),
- (position_get_rotation_around_z, ":around_z_b", pos45),
-
- (position_copy_origin,pos39,pos45),
- (position_move_y,pos45,100,0),
- (position_move_y,pos39,100,0),
- (get_distance_between_positions,":distance_tt",pos45,pos39),
- (store_random_in_range, ":var_animate", 10, 12),
-
- (copy_position,pos55,pos45),
- (position_rotate_z,pos55,-90,),
-
-
-
-
-
- (try_begin),#检测是否可以开火
- (val_sub,":around_z_a",":around_z_b"),
- (val_abs,":around_z_a"),
- (le,":around_z_a", ":around_z_max",),
- (agent_get_look_position, pos39, ":ctrl_agent"),
- (position_copy_origin,pos39,pos45),
- (position_move_y,pos39,100,0),
- (le,":distance_tt", ":l_distance",),
- (val_add, ":shoot", 1),
- (else_try),
- (copy_position,pos39,pos30),
- (position_move_y,pos39,100,0),
- (try_end),
-
-
- (try_begin),#转动投石机的方向角
- (position_is_behind_position,pos39, pos55),
- (assign,":rotate_z",1),
- (else_try),
- (assign,":rotate_z",-1),
- (try_end),
-
-
- (try_begin),
- (agent_get_look_position, pos39, ":ctrl_agent"),#
- (prop_instance_get_position, pos45, ":sprop_instance"),
-
- (position_get_rotation_around_z, ":around_z_a", pos39),
- (position_get_rotation_around_z, ":around_z_b", pos45),
- (val_sub,":around_z_a",":around_z_b"),
- (val_abs,":around_z_a"),
- (le,":around_z_a", 3,),
-
- (assign,":rotate_z",0),
- (try_end),
-
-
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (position_copy_origin,pos45,pos30),
- (position_rotate_z,pos45,":rotate_z",),
- (prop_instance_animate_to_position,":sprop_instance",pos45,":var_animate"),#进行动作
-
-
-
- (position_move_x, pos45, -260),
- (agent_get_look_position, pos39, ":agent_a"),
- (position_copy_rotation,pos45,pos39),
- (agent_set_position,":agent_a",pos45),#图省事,把操纵者强制固定在投石机的一侧
-
-
- (try_end),
-
-
- ]),
- ]),
- #########################
- ##################################################投石机的弹射臂,用来执行投石机的投射动画和实际上的投射效果
- ("zz_zz_z_simple_catapult_test_b",sokf_moveable|sokf_type_ladder,"catapult_test_b",0,
- [
- (ti_on_scene_prop_init,
- [
- (store_trigger_param_1, ":sprop_instance"),
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (prop_instance_animate_to_position,":sprop_instance",pos45,10),
- (scene_prop_set_slot,":sprop_instance",scene_prop_smoke_effect_done,0),
-
- (init_position,pos50),
- (position_move_z, pos50, -50000),
- (set_spawn_position, pos50),
- (spawn_scene_prop,"spr_zz_zz_z_simple_catapult_shell_a_test"),#把石头弹生成出来
- (assign,":scene_prop_c",reg0),
- (scene_prop_set_slot,":scene_prop_c",scene_prop_slots_end,":sprop_instance"),
- ]),
- (ti_on_scene_prop_animation_finished,
- [
- (store_trigger_param_1, ":sprop_instance"),
- (assign, ":l_distance",60),
- (scene_prop_get_slot, ":scene_prop_slots_end", ":sprop_instance", scene_prop_slots_end),
- (scene_prop_get_slot, ":cc", ":sprop_instance", scene_prop_smoke_effect_done),#用来控制整个流程的
-
- (prop_instance_get_position,pos40,":scene_prop_slots_end"),
- (try_begin),
- (store_mul,":rotate_z",":cc",1),
- (position_rotate_x,pos40,":rotate_z",),
- (le, ":cc", 80),
- (val_add,":cc",1),
- (try_end),
-
-
- (try_begin),
- (ge, ":cc", 80),
- (assign, ":shoot", 0),#投射条件检测
-
- (scene_prop_get_slot, ":agent_a", ":scene_prop_slots_end", scene_prop_ccoop_item_drop_start),
- (agent_is_alive, ":agent_a"),
- (scene_prop_get_hit_points, ":sprop_instance_ammo", ":scene_prop_slots_end"),
-
- (agent_get_look_position, pos39, ":agent_a"),#
- (prop_instance_get_position, pos45, ":scene_prop_slots_end"),
-
- (position_copy_origin,pos39,pos45),
- (position_move_y,pos45,100,0),
- (position_move_y,pos39,100,0),
- (get_distance_between_positions,":distance_tt",pos45,pos39),
-
- (try_begin),#检测是否可以开火
- (agent_get_look_position, pos39, ":agent_a"),#
- (prop_instance_get_position, pos45, ":scene_prop_slots_end"),
-
- (position_get_rotation_around_z, ":around_z_a", pos39),
- (position_get_rotation_around_z, ":around_z_b", pos45),
- (val_sub,":around_z_a",":around_z_b"),
- (val_abs,":around_z_a"),
- (le,":around_z_a", 30,),
- (le,":distance_tt", ":l_distance",),
-
-
- (val_add, ":shoot", 1),
- (try_end),
-
-
- (try_begin),#检测控制者的目标在射程内
- (agent_ai_get_look_target, ":target", ":agent_a"),
- (neq, ":target", -1),
- (agent_get_position,pos52,":target"),
- (agent_get_position,pos53,":agent_a"),
- (get_distance_between_positions,":distance",pos52,pos53),
- (is_between,":distance", 3000,97000),
- (agent_get_look_position, pos39, ":agent_a"),#
- (val_add, ":shoot", 1),
- (try_end),
-
-
- (ge, ":shoot", 2),#如果投射条件允许
- (ge, ":sprop_instance_ammo", 300),#如果已经装填完成
- (position_move_y,pos45,150,0),
- (position_move_z,pos45,450,0),
- (position_copy_rotation,pos45,pos39),
- (play_sound_at_position, "snd_pistol_shot", pos45, 0),#放个音效
-
-
- (try_for_range,":aa",0,1),#循环执行,没错,这里可以设置复数弹药,因为我之前闲得慌想看天女散花
- (neq, ":aa", 999),
- (store_random_in_range, ":var_15", -6, 7),
- (store_random_in_range, ":var_16", -2, 3),
- (assign, ":var_distance_d", ":distance"),#用来计算投射弹速的
- (assign, ":var_distance_e", ":distance"),#用来计算投射弹速的
-
- (try_begin),
- (ge, ":distance", 9000),
- (val_sub, ":var_distance_e", 100000),
- (val_mul, ":var_distance_e", -1),
- (val_div, ":var_distance_e", 1000),
- (val_mul, ":var_distance_e", -1),
- (val_add, ":var_distance_e", 480),
- (val_div, ":var_distance_d", ":var_distance_e"),
- (else_try),
- (val_sub, ":var_distance_e", 100000),
- (val_mul, ":var_distance_e", -1),
- (val_div, ":var_distance_e", 1000),
- (val_mul, ":var_distance_e", -1),
- (val_add, ":var_distance_e", 380),
- (val_div, ":var_distance_d", ":var_distance_e"),
- (try_end),
-
- (position_rotate_x, pos45, 45, ),#为了方便,所以在默认在理想的投射角度时把石头扔出去了
- (set_fixed_point_multiplier, 10),
- (position_rotate_x_floating, pos45, ":var_16"),
- (position_rotate_z_floating, pos45, ":var_15"),
- (set_fixed_point_multiplier, 1),
- (set_fixed_point_multiplier, 1),
- (store_random_in_range, ":var_16", -2, 3),#加点随机影响
- (val_add, ":var_distance_d", ":var_16"),
- (convert_to_fixed_point, ":var_16"),
- (add_missile, ":agent_a", pos45, ":var_distance_d", "itm_50mm_he_shell", 0, "itm_50mm_he_shell", 0),#把一枚五十毫米高爆炮弹扔到敌人头上,问我就是省事,也可以换成你喜欢的投射道具
- (store_random_in_range, ":var_points", 150, 210),
- (scene_prop_set_cur_hit_points, ":scene_prop_slots_end", ":var_points"),
- (try_end),
-
- (assign, ":cc", 0),#重置流程
- (try_end),
-
- (prop_instance_animate_to_position,":sprop_instance",pos40,10),
- (scene_prop_set_slot,":sprop_instance",scene_prop_smoke_effect_done,":cc"),#如果是射过了,那就重新开始装填
-
- ]),
- ]),
- ###############################################投石机的石头弹,会在投石机装填待发的时候现实在投石机的弹射臂的投射框内,投射后隐藏
- ("zz_zz_z_simple_catapult_shell_a_test",sokf_moveable,"simple_catapult_shell_a_test",0,
- [
- (ti_on_scene_prop_init,
- [
- (store_trigger_param_1, ":sprop_instance"),
- (prop_instance_get_position, pos45, ":sprop_instance"),
- (prop_instance_animate_to_position,":sprop_instance",pos45,10),
- (scene_prop_set_slot,":sprop_instance",scene_prop_smoke_effect_done,0),
- ]),
- (ti_on_scene_prop_animation_finished,
- [
- (store_trigger_param_1, ":sprop_instance"),
-
- (scene_prop_get_slot, ":scene_prop_slots_end", ":sprop_instance", scene_prop_slots_end),
- (scene_prop_get_slot, ":cc", ":scene_prop_slots_end", scene_prop_smoke_effect_done),
- (prop_instance_get_position,pos40,":scene_prop_slots_end"),
- (prop_instance_animate_to_position,":sprop_instance",pos40,1),
-
- (try_begin),
- (ge, ":cc", 80),#如果装好了,就显示
- (scene_prop_set_visibility, ":sprop_instance", 1),
- (else_try),
- (scene_prop_set_visibility, ":sprop_instance", 0),#没装好就不显示
- (try_end),
-
-
-
- ]),
- ]),
- ###############################################
复制代码
|