OSP Code Combat Automatic Guns

Users who are viewing this thread

This is a mirror of the thread Automatic Guns by Colonel_Ryan on the old Exilian Forums. It contains an Automatic Gun Script from the OSP Author cdvader which has been originally posted at http://mnbmodernwarfare.forumotions.com/t17-comrades-in-muteness which can now only be accessed via the Internet Archive (two snapshots of the page, 1 and 2)

Keep in mind that this script is from 2010. Some things might be easier to do now with operations, which have been introduced with newer versions of the Module System (remark of dstn:Note: The code comes from a time well before WSE and before Warband module system received the operation add_missile).

Afterwards following only a quote of cdvader.

======
Alright, since I was going to make a guide about full auto on Taleworlds later, might as well post it here, in the open.

module_mission_template.py
Python:
automatic_fire_init = (
  ti_before_mission_start, 0, ti_once, [],
  [
    (call_script, "script_autofire_reset_values"),
  ])
 
automatic_fire_test = (
  0.2, 0, 0,
  [
    (key_is_down, key_left_mouse_button),
    (neg|key_is_down, key_right_mouse_button),
    (assign, "$has_item_equipped", 0),
    (get_player_agent_no, ":player"),              
    (call_script, "script_autofire_agent_try_for_items_equipped", ":player", "itm_amer_ar", "itm_union_smg"),
    (eq, "$has_item_equipped", 1),
    (agent_is_alive, ":player"),
    (neg|agent_is_wounded, ":player"),
    (eq, "$autofire_lock", 0),
  ],
  [
    (assign, "$autofire_lock", 1),
    (try_begin),
        (gt, "$ammunition", 0),
        (try_for_agents, ":agent"),
            (get_player_agent_no, ":player"),
            (agent_get_position, pos3, ":player"),
            (position_move_x, pos3, 1),
            (position_move_y, pos3, 96),
            (position_move_z, pos3, 125),
            (particle_system_burst, "psys_muzzle_flash", pos3, 1), #You'll need to make your own muzzle flash particle system, it's rather simple.
            (play_sound, "snd_fullautotest"), #Change the sound to your liking
            (call_script, "script_autofire_get_agent_positions", ":player", ":agent"),
            (try_begin),
                (eq, "$autofire_damage", 1),
                (call_script, "script_autofire_damage_agent", ":player", ":agent", "psys_game_blood", 15, 10, 17), #Particle system not working yet
            (try_end),
            (val_sub, "$ammunition", 1),
        (try_end),
    (else_try),
        (eq, "$ammunition", 0),
        (agent_set_animation, ":player", "anim_reload_crossbow"), #Change the animation to your liking
        (assign, "$ammunition", 180),
    (try_end),    
    (assign, "$autofire_lock", 0),
   ])

autofire_ammo_init = ( #also needed, or you will enter scenes with no ammo.
ti_before_mission_start, 0, ti_once, [],
  [
    (get_player_agent_no, ":player"),
    (agent_has_item_equipped, "itm_cartridges"),
    (assign, "$ammunition", 180),
  ])

module_scripts.py
Python:
#Autofire script by cdvader and Rize---------------------------------------------------------          
#script_autofire_damage_agent
#Input 1: Damager.
#Input 2: Agent.
#Input 3: Particle System Burst.
#Input 4: Particle System Burst Power.
#Input 5: Random damage value BEGIN.
#Input 6: Random damage value END.
#Output: Damage.
("autofire_damage_agent",
  [
    (store_script_param, ":player", 1),
    (store_script_param, ":agent", 2),
    (store_script_param, ":psys", 3),
    (store_script_param, ":psys_power", 4),
    (store_script_param, ":l_range", 5),
    (store_script_param, ":h_range", 6),              
    (try_begin),
        (agent_get_position, pos1, ":agent"),
        (agent_get_position, pos2, ":player"),
        (neg|position_is_behind_position, pos1, pos2),
        (particle_system_burst, ":psys", pos1, ":psys_power"),
        (store_agent_hit_points, ":hp", ":agent", 1),
        (store_random_in_range, ":rand", ":l_range", ":h_range"),
        (val_sub, ":hp", ":rand"),
        (val_max, ":hp", 0),
        (neq, ":agent", ":player"),
        (agent_is_alive, ":agent"),
        (agent_set_hit_points, ":agent", ":hp", 1),
        (assign, reg1, ":hp"),
        (try_begin),
            (gt, reg1, 0),
            (display_message, "@Delivered {reg1} damage."),
        (try_end),
        (try_begin),
            (lt, ":hp", 1),
            (agent_deliver_damage_to_agent, ":player", ":agent"),
        (try_end),                  
    (try_end),
  ]),

#script_autofire_agent_has_item_equipped
#Input 1: Agent.
#Input 2: Weapon item.
#Output: $has_item_equipped variable.
("autofire_agent_has_item_equipped",
  [
    (store_script_param, ":agent", 1),
    (store_script_param, ":item", 2),
    (try_begin),
        (agent_get_wielded_item, ":w_item", ":agent", 0),
        (eq, ":w_item", ":item"),
        (assign, "$has_item_equipped", 1),
    (else_try),
        (assign, "$has_item_equipped", 0),
    (try_end),
  ]),
   
#script_autofire_agent_try_for_items_equipped
#Input 1: Agent.
#Input 2: Weapon item BEGIN.
#Input 3: Weapon item END.
#Output: $has_item_equipped variable.
("autofire_agent_try_for_items_equipped",
  [
    (store_script_param, ":agent", 1),
    (store_script_param, ":item_begin", 2),
    (store_script_param, ":item_end", 3),
    (try_for_range, ":all_items", ":item_begin", ":item_end"),
        (agent_get_wielded_item, ":w_item", ":agent", 0),
        (is_between, ":w_item", ":all_items"),
        (assign, "$has_item_equipped", 1),
    (else_try),
        (agent_get_wielded_item, ":w_item", ":agent", 0),
        (eq, ":w_item", ":item_begin"),
        (assign, "$has_item_equipped", 1),
    (else_try),
        (agent_get_wielded_item, ":w_item", ":agent", 0),
        (eq, ":w_item", ":item_end"),
        (assign, "$has_item_equipped", 1),
    (else_try),
        (troop_get_type, ":walker", ":agent"),
        (eq, ":walker", tf_walker),
        (assign, "$has_item_equipped", 1),
    (else_try),
        (assign, "$has_item_equipped", 0),
    (try_end),
  ]),  
   
#script_autofire_reset_values
#Input: None.
#Output: Resetted values.
("autofire_reset_values",
  [
    #(assign, "$dist_val", 100),
    (assign, "$autofire_lock", 0),
    (assign, "$autofire_damage", 0),
    (assign, "$has_item_equipped", 0),
    ]),
   
#script_autofire_get_agent_positions
#Input 1: Shooter.
#Input 2: Agent.
#Output: Positions.
("autofire_get_agent_positions",
  [
    (store_script_param, ":player", 1),
    (store_script_param, ":agent", 2),
    (agent_get_look_position, pos1, ":player"),
    (agent_get_position, pos2, ":agent"),
    (agent_get_position, pos3, ":player"),
    (get_distance_between_positions, ":dist", pos1, pos2),
    #(assign, "$dist_val", 100),
    (get_distance_between_positions, ":range", pos2, pos3),
    (lt, ":range", 2000), #Increase range here
    (try_begin),
        (neq, ":agent", ":player"),
        (lt, ":dist", 100),
        (assign, "$autofire_damage", 1),
    (else_try), #TODO: Fix this try_for_range loop to drastically decrease the size of the script.
        #(try_for_range, reg2, 0, 250),
            #(neq, ":agent", ":player"),
            #(position_move_y, pos1, 100),
            #(position_move_z, pos1, -100),
            #(get_distance_between_positions, ":dist", pos1, pos2),
            #(val_add, "$dist_val", 100),
            #(lt, ":dist", "$dist_val"),
            #(assign, "$autofire_damage", 1),
        #(try_end),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 200),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 300),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 400),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (lt, ":dist", 500),
        (neg|position_is_behind_position, pos2, pos1),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 600),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 700),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 800),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 900),
        (assign, "$autofire_damage", 1),
    (else_try),
        (neq, ":agent", ":player"),
        (position_move_y, pos1, 100),
        (position_move_z, pos1, -100),
        (get_distance_between_positions, ":dist", pos1, pos2),
        (neg|position_is_behind_position, pos2, pos1),
        (lt, ":dist", 1000),
        (assign, "$autofire_damage", 1),
    (else_try),
        (assign, "$autofire_damage", 0),
    (try_end),
  ]),
#---------------------------------------------------------

It's 50% incomplete as I said, in that it can shoot through walls or people, its spread is rather large, and it has a rather low range. If you want to make the spread lower, remove from the last groups of coding that include "lt, ":dist"".
In fact, there's lots of more coding to make in order to balance range and spread properly. Maybe you could observe it carefully to learn more about coding.
 
Last edited:
Back
Top Bottom