OSP Code Combat [WIP] Auto-Firing weapons mod

Sauron_mate

Grandmaster Knight
Best answers
0
ithilienranger said:
Sorry for the absence. I have been busy finishing up my college degree and working. I will have a new version ready soon that doesn't need WSE since it is no longer in development. I just need to make some tweaks to timings and accuracy calculations. The new version is much leaner than the old one but I had to remove some of the old features to do that.
Would be great, thank you sir
 

ithilienranger

Knight at Arms
Best answers
0
I updated the opening post with the new code. It isn't perfect but I think it is better than before. Please test it and tell me if there are any changes that should be made.

EDIT: I removed the dependency for WSE.
 

Sauron_mate

Grandmaster Knight
Best answers
0
ithilienranger said:
I updated the opening post with the new code. It isn't perfect but I think it is better than before. Please test it and tell me if there are any changes that should be made.

EDIT: I removed the dependency for WSE.
will you make a multiplayer version?
 

ithilienranger

Knight at Arms
Best answers
0
It is difficult for me to test it in multiplayer because I only have one copy of the game. I may make a multiplayer version but I will need testers for it.
 

Lumos

Section Moderator
WBWF&SNWM&BVC
Best answers
0
ithilienranger said:
It is difficult for me to test it in multiplayer because I only have one copy of the game. I may make a multiplayer version but I will need testers for it.
Might be wrong here cause I'm not very experienced in MP scripting, but I think that you can test any MP codes absolutely fine by yourself if you host a dedicated server and join it as a regular player, because if you test in a non-dedicated server, you are the server and some things may work where they otherwise wouldn't.
 

ithilienranger

Knight at Arms
Best answers
0
I was thinking that there could be bugs when there is more than one player on either type of server. I'll just have to test it as much as I can and hope that it works on full servers.
 

Slawtering

Grandmaster Knight
WBNWWF&SM&BVC
Best answers
0
Unfortunately I don't have a dedicated server but when compiling I had no errors and RGL_Log didn't yield any errors either so we'll have to wait for someone with a dedicated server.
 

mike56

Master Knight
WBNWWF&SM&BVC
Best answers
0
Please, a noob question. Now we dont need WSE, the codes that are in the first post in in these 4 spoilers means that I must copy the content of each spoiler in the the Module System files?

All the content of the "scripts" spoiler must be copied in the module_scripts.py ?
All the content of the "mission_templates" spoiler must be copied in the module_mission_templates.py?

Thanks!
 

ruskimmh

Recruit
Best answers
0
ithilienranger said:
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
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]
help me pls!  :sad:

how do i start with this? where do i put each thing??? i cant figure it, pls help! when i compile i get errors..... i dont know where to place code! pls show me im dumb! pls!
 
Best answers
0
Am I missing something here? It appears that you call a script (set_auto_weapon_stats) in mission templates, but it's not in the script snippet you give us.
 

Druidic

Knight
WBNWVC
Best answers
0
ruskimmh said:
ithilienranger said:
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
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]
help me pls!  :sad:

how do i start with this? where do i put each thing??? i cant figure it, pls help! when i compile i get errors..... i dont know where to place code! pls show me im dumb! pls!
You may not get this message, it being from January, but I think the safest way to go is to put it at the very end of your module_* file. At the VERY bottom. be careful not to put it on the same line as the final "]" symbol, because that will screw up stuff.

It's pretty self-explanatory what files they should go in, by the way. Not to be rude, but the text on the spoiler buttons are actually the names of the files you put them in.

EDIT: I missed a spot. On module_items .py, be sure to put it BEFORE 
["items_end", "Items End", [("shield_round_a",0)], 0, 0, 1, 0, 0],
]

Otherwise it won't work.
 

HungKnight

Regular
Best answers
0
I have to copy and paste into the corresponding module_mission_templates and module_scripts but it appears only fault is faulty module_mission_templates and module_scripts other things work well,  :???: help me how to write in module_mission_templates and module_scripts
 

Lumos

Section Moderator
WBWF&SNWM&BVC
Best answers
0
matteo101man said:
Error: Unable to find object:script_fire_auto_weapon
ERROR: Illegal Identifier:script_fire_auto_weapon

I have the script in module scripts, it's called fire_auto weapon.
Because you've got a blank space where you shouldn't?
 

Druidic

Knight
WBNWVC
Best answers
0
matteo101man said:
Cmon,might anyone know why???
Based on what I see, it can't find the script. I'd check for any blank spaces like Lumos said, but I'd also double-check to see if you placed the lines correctly, or if you accidentally changed the letter of something. It happens.
 

derrikjb

Recruit
Best answers
0
ScreamingCommie said:
Am I missing something here? It appears that you call a script (set_auto_weapon_stats) in mission templates, but it's not in the script snippet you give us.
I second this! :smile:
Compiling gives the error. "Unable to find object: script_set_auto_weapon_stats"
 

goruu

Recruit
Best answers
0
DruDru the Magniscisiscent said:
ruskimmh said:
ithilienranger said:
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
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]
help me pls!  :sad:

how do i start with this? where do i put each thing??? i cant figure it, pls help! when i compile i get errors..... i dont know where to place code! pls show me im dumb! pls!
You may not get this message, it being from January, but I think the safest way to go is to put it at the very end of your module_* file. At the VERY bottom. be careful not to put it on the same line as the final "]" symbol, because that will screw up stuff.

It's pretty self-explanatory what files they should go in, by the way. Not to be rude, but the text on the spoiler buttons are actually the names of the files you put them in.

EDIT: I missed a spot. On module_items .py, be sure to put it BEFORE 
["items_end", "Items End", [("shield_round_a",0)], 0, 0, 1, 0, 0],
]

Otherwise it won't work.
Hi, I might not get a message from you since your reply is 5 years ago from now.

Which file does "constant" and "items" go into?
 

Druidic

Knight
WBNWVC
Best answers
0
goruu said:
Hi, I might not get a message from you since your reply is 5 years ago from now.

Which file does "constant" and "items" go into?
You mean the spoiler tags named "constants" and "items" in the OP?

Those bits in the spoilers would go into "module_constants.py" and "module_items.py", respectively.
 

Anindo

Recruit
Best answers
0
Probably won't get any reply because this is an old thread.

Anyways,

I am completely new to all this, never heard of this game.

BUT saw some youtube video and now I want to have fun. How do I start.