ithilienranger
Knight at Arms

This has been updated but it is a work in progress!
Changes:
Here is the link to the old version download: http://www.mbrepository.com/file.php?id=2464
Running Credits:
ithilienranger - majority of coding & testing
cmpxchg8b - coding assistance
All other modding experts who have helped me with questions.
Special thanks to Swyter for motivating me to make this
and for mr.master for his patience and support
.
Changes:
- WSE is no longer needed for this mod to work but you should have either version 1.153 or 1.154 of Warband
- Auto shotguns are no longer supported due to performance
- No more crosshair - because it looked bad
- Multiplayer portion not implemented yet
- Multiple ammo types per weapon type no longer supported
- Firing rate is determined by speed_rating
- The AI will fire in bursts by default
- The bullets fire in the direction of the camera which may not be where your agent is facing if on horseback
Code:
[plain]
######################################################################
##################### ADD THESE BELOW OTHER IMPORTS ##################
################# THESE STORE ITEM STATS IN ITEM_SLOTS ###############
######################################################################
from module_items import *
def get_item_accuracy():
item_accuracy = []
for i_item in xrange(len(items)):
item_accuracy.append((item_set_slot, i_item, slot_item_accuracy, get_leg_armor(items[i_item][6])))
return item_accuracy[:]
def get_item_shoot_speed():
item_shoot_speed = []
for i_item in xrange(len(items)):
item_shoot_speed.append((item_set_slot, i_item, slot_item_shoot_speed, get_missile_speed(items[i_item][6])))
return item_shoot_speed[:]
def get_item_speed_rating():
item_speed_rating = []
for i_item in xrange(len(items)):
item_speed_rating.append((item_set_slot, i_item, slot_item_speed_rating, get_speed_rating(items[i_item][6])))
return item_speed_rating[:]
########################################################################
##################### FIRES WEAPON BASED ON STATS ######################
########################################################################
("fire_auto_weapon",[
(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_speed", ":shooter_weapon", slot_item_speed_rating),
(store_sub, ":weapon_recoil", 150, ":weapon_speed"),
(assign, ":max_recoil", ":weapon_recoil"),
(val_div, ":weapon_recoil", 3),
(agent_get_slot, ":wander", ":shooter_agent", slot_agent_firearm_wander),
(val_add, ":wander", ":weapon_recoil"),
(val_clamp, ":wander", 0, ":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),
(val_add, ":wander", ":firing_disability"),
(val_div, ":wander", 3),
(val_add, ":inaccuracy", ":wander"),
############# RAISE POS TO EYE LEVEL & MOVE TO END OF GUN ###############
(agent_get_look_position, pos1, ":shooter_agent"),
(position_move_y, pos1, 80, 0),
(try_begin),
(agent_get_horse, ":horse", ":shooter_agent"),
(gt, ":horse", 0),
(position_move_z, pos1, 240, 0),
(else_try),
(position_move_z, pos1, 150, 0),
(try_end),
#################### SOUNDS AND PARTICLES PLAY HERE #####################
(item_get_slot, ":sound_id", ":shooter_weapon", slot_item_sound),
(agent_play_sound, ":shooter_agent", ":sound_id"),
############ GET INITIAL RANDOMIZED BULLET ANGLE ROTATION ###############
(store_random_in_range, ":y_rotation", 0, 360),
(position_rotate_y, pos1, ":y_rotation"),
#################### SPAWN BULLET WITH INACCURACY #######################
(store_random_in_range, ":x_inaccuracy", 0, ":inaccuracy"),
(set_fixed_point_multiplier, 10),
(position_rotate_x_floating, pos1, ":x_inaccuracy"),
(item_get_slot, ":velocity", ":shooter_weapon", slot_item_shoot_speed),
(set_fixed_point_multiplier, 1),
(add_missile, ":shooter_agent", pos1, ":velocity", ":shooter_weapon", 0, ":shooter_ammo", 0),
]),
#########################################################################
################ SCRIPT TO SET ITEM STATS TO ITEM_SLOTS #################
#########################################################################
("init_item_accuracy", get_item_accuracy()),
("init_item_shoot_speed", get_item_shoot_speed()),
("init_item_speed_rating", get_item_speed_rating()),
[/plain]
Code:
[plain]
####################################################################
####################### INITIALIZE AUTOFIRE ########################
####################################################################
common_init_auto_fire = (
ti_after_mission_start, 0, ti_once, [], [
(this_or_next|multiplayer_is_server),
(neg|game_in_multiplayer_mode),
######### NEEDED TO PREVENT UNINITIALIZE SLOTS FOR CLIENTS #########
############# ADD EACH SCRIPT CALL FROM AUTO ITEM HERE #############
(try_begin),
(multiplayer_is_dedicated_server),
(call_script, "script_set_auto_weapon_stats", "itm_m_249", "snd_pistol_shot"),
(call_script, "script_set_auto_weapon_stats", "itm_AK_47", "snd_pistol_shot"),
(call_script, "script_set_auto_weapon_stats", "itm_UZI", "snd_pistol_shot"),
(try_end),
############### NEEDED TO PREVENT UNINITIALIZE SLOTS ###############
(call_script, "script_init_item_accuracy"),
(call_script, "script_init_item_shoot_speed"),
(call_script, "script_init_item_speed_rating"),
])
common_auto_fire_held = (
0.1, 0.5, 0, [ # adjust the delay to match the time it takes to play the ready animation
(game_key_is_down, gk_attack),
],[
(get_player_agent_no, ":shooter_agent"),
(agent_set_slot, ":shooter_agent", slot_agent_autofire_ready, 1),
])
common_auto_fire_clicked = (
0.1, 0, 0, [
(get_player_agent_no, ":shooter_agent"),
(agent_get_animation, ":shooter_stance", ":shooter_agent", 1),
(this_or_next|eq, ":shooter_stance", "anim_reload_musket"),
(this_or_next|eq, ":shooter_stance", "anim_reload_pistol"),
(neg|game_key_is_down, gk_attack),
],[
(get_player_agent_no, ":shooter_agent"),
(agent_set_slot, ":shooter_agent", slot_agent_autofire_ready, 0),
])
####################################################################
################## CHECK IF BULLET CAN BE FIRED ####################
####################################################################
common_auto_fire = (
0.1, 0, 0, [
(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 WIELDS AN AUTOFIRE WEAPON #############
(agent_get_wielded_item, ":cur_weapon", ":shooter_agent", 0),
(is_between, ":cur_weapon", "itm_uzi", "itm_torch"),
########### 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"),
(assign, ":ready_flag", 0),
(try_begin), #Limits the AI to burst firing
(agent_is_non_player, ":shooter_agent"),
(agent_get_combat_state, ":cur_state", ":shooter_agent"),
(eq, ":cur_state", 3),
(assign, ":ready_flag", 1),
(else_try), #Check if a player has held down the attack button
(neg|agent_is_non_player, ":shooter_agent"),
(agent_slot_eq, ":shooter_agent", slot_agent_autofire_ready, 1),
(assign, ":ready_flag", 1),
(try_end),
(eq, ":ready_flag", 1),
################## FIND WEAPON AND 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),
(assign, ":ammo_item", "itm_cartridges"),
############################ REDUCE AMMO ###########################
(try_begin),
(agent_get_ammo_for_slot, ":ammo", ":shooter_agent", ":weapon_slot"),
(gt, ":ammo", 0),
(val_sub, ":ammo", 1),
(agent_set_ammo, ":shooter_agent", ":cur_weapon", ":ammo"),
####################### SET FIRING ANIMATION #######################
(try_begin),
(eq, ":cur_weapon", "itm_uzi"),
(agent_set_animation, ":shooter_agent", "anim_release_pistol", 1),
(else_try),
(agent_set_animation, ":shooter_agent", "anim_release_musket", 1),
(try_end),
(call_script, "script_fire_auto_weapon", ":shooter_agent", ":cur_weapon", ":ammo_item"),
(try_end),
(else_try),
################## REDUCES RECOIL FOR ALL AGENTS ###################
(agent_get_slot, ":wander", ":shooter_agent", slot_agent_firearm_wander),
(val_sub, ":wander", 20),
(val_min, ":wander", 0),
(agent_set_slot, ":shooter_agent", slot_agent_firearm_wander, ":wander"),
(try_end),
(try_end),
])
[/plain]
#autofire begin
slot_agent_firearm_wander = 30
slot_agent_autofire_ready = 31
#autofire end
#autofire begin
slot_item_accuracy = 62
slot_item_shoot_speed = 63
slot_item_speed_rating = 64
slot_item_sound = 65
#autofire end
slot_agent_firearm_wander = 30
slot_agent_autofire_ready = 31
#autofire end
#autofire begin
slot_item_accuracy = 62
slot_item_shoot_speed = 63
slot_item_speed_rating = 64
slot_item_sound = 65
#autofire end
Code:
[plain]
########################################################################
########## ITEM EXAMPLE FOR AUTOMATIC GUNS ##########
########################################################################
["uzi", "UZI", [("flintlock_pistol",0)], itp_type_pistol |itp_merchandise|itp_primary|itp_cant_use_on_horseback, itcf_shoot_pistol|itcf_carry_revolver_right|itcf_reload_pistol, 67 , weight(3.5)|spd_rtng(100) | shoot_speed(160) | thrust_damage(40, pierce)|max_ammo(30)|accuracy(60),imodbits_none,
[(ti_on_init_item, [(item_set_slot, "itm_uzi", slot_item_sound, "snd_pistol_shot"),])]],
["ak_47", "AK-47", [("crossbow_a",0)], itp_type_musket |itp_merchandise|itp_primary|itp_two_handed|itp_cant_use_on_horseback, itcf_shoot_musket|itcf_carry_crossbow_back|itcf_reload_musket, 67 , weight(4.3)|spd_rtng(75) | shoot_speed(160) | thrust_damage(50, pierce)|max_ammo(50)|accuracy(100),imodbits_none,
[(ti_on_init_item, [(item_set_slot, "itm_ak_47", slot_item_sound, "snd_pistol_shot"),])]],
["m_249", "M-249", [("crossbow_a",0)], itp_type_musket |itp_merchandise|itp_primary|itp_two_handed|itp_cant_use_on_horseback, itcf_shoot_musket|itcf_carry_crossbow_back|itcf_reload_musket, 67 , weight(8)|spd_rtng(50) | shoot_speed(160) | thrust_damage(40, pierce)|max_ammo(100)|accuracy(60),imodbits_none,
[(ti_on_init_item, [(item_set_slot, "itm_m_249", slot_item_sound, "snd_pistol_shot"),])]],
[/plain]
Here is the link to the old version download: http://www.mbrepository.com/file.php?id=2464
Running Credits:
ithilienranger - majority of coding & testing
cmpxchg8b - coding assistance
All other modding experts who have helped me with questions.
Special thanks to Swyter for motivating me to make this
