Recent content by totallyNotSmurf

  1. OSP Code Combat [WIP] Auto-Firing weapons mod

    I'll do that the next time, thanks  :smile:

    Now, isn't it silly that native has an operation to SET the animation progress but not to GET it? Looks bad to start firing before you have even raised the gun, and it only gets worse when shotgun pellets emit from the actual barrel of the wrong-directed gun model. Maybe it'll work if I keep poking it ...
  2. OSP Code Combat [WIP] Auto-Firing weapons mod

    In case I wasn't clear enough, AFAIK since I got it on steam I can't legitly get any version but the most current. Therefore I cracked a downloaded 1.143. If I am wrong then yay, I won't have to the next time.

    Now I got this script working like a charm with only a few quickly noticeable bugs on my 1.153 using only native operations, if anyone wants it I could post it. Unless I get banned again, that is  :roll:


    Edit: What the hell. Excuses if it's not all nice and tidy, I started M&B modding 2 days ago  :smile:

    In Mission templates I have replaced all WSE operations with native ones, exempt the ready-animation-check I couldn't (I think it might cause inconsistent firing speed)
    ####################################################################
    ################## CHECK IF BULLET CAN BE FIRED ####################
    ####################################################################
    common_auto_fire = (
      0.1, 0, 0,
      [
          (assign, ":player_agent", -1),
          (try_begin),
            (game_in_multiplayer_mode),
            (multiplayer_get_my_player, ":player_no"),
            (player_is_active, ":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            (player_get_agent_id, ":player_agent", ":player_no"),
          (else_try),
            (neg|game_in_multiplayer_mode),
            (get_player_agent_no, ":player_agent"),
          (try_end),
     
    ################### START PRESENTATION IF NEEDED ###################
          (try_begin),
            (neq, ":player_agent", -1),
            (agent_get_wielded_item, ":cur_weapon", ":player_agent", 0),
            (is_between, ":cur_weapon", "itm_uzi", "itm_sevensixtwo_mm_rounds"),
            (neg|is_presentation_active, "prsnt_battle"),
            (neg|is_presentation_active, "prsnt_auto_weapon_reticle"),
            (start_presentation, "prsnt_auto_weapon_reticle"),
          (try_end),
     
          (this_or_next|multiplayer_is_server),
          (neg|game_in_multiplayer_mode),
      ],[
          (try_for_agents, ":shooter_agent"),
            (agent_is_alive, ":shooter_agent"),
            (try_begin),
    ########### CHECK IF AGENT IS IN READY WEAPON ANIMATION ############
                (agent_get_animation, ":shooter_stance", ":shooter_agent", 1),
                (this_or_next|eq, ":shooter_stance", "anim_ready_pistol"),
                (eq, ":shooter_stance", "anim_ready_musket"),

                (agent_get_wielded_item, ":cur_weapon", ":shooter_agent", 0),
                (is_between, ":cur_weapon", "itm_uzi", "itm_sevensixtwo_mm_rounds"),

    #            (agent_get_animation_progress, ":anim_progress", ":shooter_agent", 1), #No native op to replace with AFAIK
    #            (eq, ":anim_progress", 100),

    ############### FIND WEAPON, GET AMMO, SET AMMO TYPE ###############
                (try_for_range, ":cur_slot", 0, 4),
                  (agent_get_item_slot, ":cur_item", ":shooter_agent", ":cur_slot"),
                  (eq, ":cur_item", ":cur_weapon"),
                  (assign, ":weapon_slot", ":cur_slot"),
                (try_end),
                (agent_get_ammo_for_slot, ":ammo", ":shooter_agent", ":weapon_slot"),

                (try_begin),
                  (eq, ":cur_weapon", "itm_uzi"),
                  (assign, ":ammo_item", "itm_nine_mm_rounds"),
                (else_try),
                  (eq, ":cur_weapon", "itm_ak_47"),
                  (assign, ":ammo_item", "itm_sevensixtwo_mm_rounds"),
                (else_try),
                  (eq, ":cur_weapon", "itm_spas_12"),
                  (assign, ":ammo_item", "itm_twelve_gauge_buckshot"),
                (try_end),

    ######### UNEQUIPS AMMO THAT IS UNUSABLE BY WIELDED WEAPON #########
                (try_for_range, ":cur_slot", 0, 4),
                  (agent_get_item_slot, ":cur_item", ":shooter_agent", ":cur_slot"),
                  (neq, ":cur_item", -1),
                  (neq, ":cur_item", ":ammo_item"),
                  (item_get_type, ":ammo_type", ":ammo_item"),
                  (item_get_type, ":cur_type", ":cur_item"),
                  (eq, ":cur_type", ":ammo_type"),
                  (agent_unequip_item, ":shooter_agent", ":cur_item", -1, 1),
                (try_end),

    ########### EQUIPS AMMO THAT IS USABLE BY WIELDED WEAPON ###########
                (try_begin),
                  (neg|agent_has_item_equipped, ":shooter_agent", ":ammo_item"),
                  (agent_equip_item, ":shooter_agent", ":ammo_item"),
                (try_end),

    ############################ REDUCE AMMO ###########################
                (try_begin),
                  (gt, ":ammo", 0),
                  (val_sub, ":ammo", 1),
                  (agent_set_ammo, ":shooter_agent", ":cur_weapon", ":ammo"),
                  (try_begin),
                      (eq, ":cur_weapon", "itm_uzi"),
                      (agent_set_animation, ":shooter_agent", "anim_release_uzi", 1),
                  (else_try),
                      (eq, ":cur_weapon", "itm_ak_47"),
                      (agent_set_animation, ":shooter_agent", "anim_release_ak_47", 1),
                  (else_try),
                      (agent_set_animation, ":shooter_agent", "anim_release_spas_12", 1),
                  (try_end),
                  (call_script, "script_fire_auto_weapon", ":shooter_agent", ":cur_weapon", ":ammo_item"),
                (try_end),
                (agent_set_slot, ":shooter_agent", slot_agent_cool_time, 0),
            (else_try),
    ################## REDUCES RECOIL FOR ALL AGENTS ###################
                (agent_get_slot, ":cool_time", ":shooter_agent", slot_agent_cool_time),
                (agent_get_slot, ":wander", ":shooter_agent", slot_agent_spread),
                (assign, ":factor", 10),
                (val_mul, ":factor", ":cool_time"),
                (val_sub, ":wander", ":factor"),
                (val_max, ":wander", 10),
                (agent_set_slot, ":shooter_agent", slot_agent_spread, ":wander"),
                (val_add, ":cool_time", 1),
                (agent_set_slot, ":shooter_agent", slot_agent_cool_time, ":cool_time"),
            (try_end),
          (try_end),
      ])





    In Scripts I have only replaced spawn_missile with add_missile in the firing script:
    ########################################################################
    ##################### FIRES WEAPON BASED ON STATS ######################
    ########################################################################
      ("fire_auto_weapon",[
          (this_or_next|multiplayer_is_server),
          (neg|game_in_multiplayer_mode),
          (store_script_param, ":shooter_agent", 1),
          (store_script_param, ":shooter_weapon", 2),
          (store_script_param, ":shooter_ammo", 3),

          (item_get_slot, ":auto_accuracy", ":shooter_weapon", slot_item_accuracy),
          (store_sub, ":inaccuracy", 100, ":auto_accuracy"),

    ###################### CALCULATE AGENT INACCURACY #######################
          (agent_get_troop_id, ":shooter_troop", ":shooter_agent"),
          (store_proficiency_level, ":firing_skill", ":shooter_troop", wpt_firearm),
          (store_sub, ":firing_disability", 500, ":firing_skill"),
          (val_div, ":firing_disability", 10),

    ############################# CALCULATE WANDER ##########################
          (item_get_slot, ":weapon_recoil", ":shooter_weapon", slot_item_auto_recoil),
          (val_mul, ":weapon_recoil", 5),
          (agent_get_slot, ":wander", ":shooter_agent", slot_agent_firearm_wander),
          (val_add, ":wander", ":weapon_recoil"),
          (store_mul, ":max_recoil", ":weapon_recoil", 10),
          (val_min, ":wander", ":max_recoil"),
          (agent_set_slot, ":shooter_agent", slot_agent_firearm_wander, ":wander"),

          (agent_get_animation, ":cur_anim", ":shooter_agent", 0),
    ################# INCREASE INACCURACY DUE TO MOVEMENT ###################
          (try_begin),
            (is_between, ":cur_anim", "anim_run_forward", "anim_stand_to_crouch"),
            (val_mul, ":wander", 2),
          (try_end),
    ################### INCREASE INACCURACY DUE TO JUMP #####################
          (try_begin),
            (is_between, ":cur_anim", "anim_jump", "anim_stand_unarmed"),
            (val_mul, ":wander", 3),
          (try_end),
    ################# DECREASE INACCURACY DUE TO CROUCH #####################
          # (try_begin),
            # (this_or_next|eq, ":cur_anim", "anim_crouch_to_stand"),
            # (eq, ":cur_anim", "anim_stand_to_crouch"),
            # (val_mul, ":wander", 2),
            # (val_div, ":wander", 3),
          # (try_end),
    ################## DECREASE INACCURACY DUE TO PRONE #####################
          # (try_begin),
            # (this_or_next|eq, ":cur_anim", "anim_stand_to_prone"),
            # (eq, ":cur_anim", "anim_prone_to_stand"),
            # (val_div, ":wander", 2),
          # (try_end),

          (val_mul, ":wander", ":firing_disability"),
          (val_div, ":wander", 1000),
          (store_add, ":slot_wander", ":inaccuracy", ":wander"),
          (agent_set_slot, ":shooter_agent", slot_agent_spread, ":slot_wander"),

    ################ SEND DATA NEEDED FOR PRSNT TO CLIENTS ##################
          (try_begin),
            (game_in_multiplayer_mode),
            (neg|agent_is_non_player, ":shooter_agent"),
            (agent_get_player_id, ":shooter_player", ":shooter_agent"),
            (multiplayer_send_int_to_player, ":shooter_player", multiplayer_event_autofire, ":slot_wander"),
          (try_end),

          (item_get_slot, ":velocity", ":shooter_weapon", slot_item_shoot_speed),
          (item_get_slot, ":shotgun", ":shooter_weapon", slot_item_auto_shotgun),
    ############# RAISE POS TO EYE LEVEL & MOVE TO END OF GUN ###############
          (agent_get_look_position, pos1, ":shooter_agent"),
          (position_move_z, pos1, 165, 0),
          (position_move_y, pos1, 50, 0),

    #################### SOUNDS AND PARTICLES PLAY HERE #####################
          (item_get_slot, ":sound_id", ":shooter_weapon", slot_item_sound),
          (agent_play_sound, ":shooter_agent", ":sound_id"),
          #(particle_system_burst, "psys_gun_flash", pos1, 10),

    ############ GET INITIAL RANDOMIZED BULLET ANGLE ROTATION ###############
          (store_random_in_range, ":y_rotation", 0, 360),
          (position_rotate_y, pos1, ":y_rotation"),

          (try_begin),
    ############ IF NOT SHOTGUN SPAWN BULLET WITH INACCURACY ################
            (eq, ":shotgun", 0),
           
            (val_add, ":inaccuracy", ":wander"),
            (store_random_in_range, ":mad:_inaccuracy", 0, ":inaccuracy"),
            (set_fixed_point_multiplier, 10),
            (position_rotate_x_floating, pos1, ":mad:_inaccuracy"),

            (set_fixed_point_multiplier, 1),
            (add_missile, ":shooter_agent", pos1, ":velocity", ":shooter_weapon", ":shooter_ammo"),
          (else_try),
    ############## IF SHOTGUN ROTATE X WITH WITH INACCURACY #################
            (store_random_in_range, ":wander_movement", 0, ":wander"),
            (set_fixed_point_multiplier, 10),
            (position_rotate_x_floating, pos1, ":wander_movement"),

    ############# REPEAT FOR EACH PROJECTILE DEFINED BY ITEM ################
            (try_for_range, ":repeat", 0, ":shotgun"),
                (set_fixed_point_multiplier, 10),
                (copy_position, pos2, pos1),

    ################ ROTATES EACH PROJECTILE INTO SECTORS ###################
                (store_div, ":y_rotation", 360, ":shotgun"),
                (val_mul, ":y_rotation", ":repeat"),
                (position_rotate_y, pos2, ":y_rotation"),

    ############ SPAWN PROJECTILE WITH RANDOMIZED INACCURACY ################
                (store_random_in_range, ":mad:_inaccuracy", 0, ":inaccuracy"),
                (position_rotate_x_floating, pos2, ":mad:_inaccuracy"),

                (set_fixed_point_multiplier, 1),
                (add_missile, ":shooter_agent", pos2, ":velocity", ":shooter_weapon", ":shooter_ammo"),
            (try_end),
          (try_end),
      ]),

    Free to use and redistribute as per OP, feedback appreciated.
Back
Top Bottom