i typed the formation code copying and pasting it
# script_check_enemies_nearby
# Input: none
# Output: none, fails when enemies are nearby
("check_enemies_nearby",
[
(get_player_agent_no, ":player_agent"),
(agent_is_alive, ":player_agent"),
(try_begin),
(agent_is_defender, ":player_agent"),
(assign, ":player_defender", 1),
(else_try),
(assign, ":player_defender", 0),
(try_end),
(agent_get_position, 1, ":player_agent"),
(assign, ":result", 0),
(try_for_agents,":cur_agent"),
(neq, ":cur_agent", ":player_agent"),
(agent_is_alive, ":cur_agent"),
(agent_is_human, ":cur_agent"),
(try_begin),
(agent_is_defender, ":cur_agent"),
(assign, ":agent_defender", 1),
(else_try),
(assign, ":agent_defender", 0),
(try_end),
(neq, ":player_defender", ":agent_defender"),
(agent_get_position, 2, ":cur_agent"),
(get_distance_between_positions, ":cur_distance", 1, 2),
(le, ":cur_distance", 1500),
(assign, ":result", 1),
(try_end),
(eq, ":result", 0),
]),
]
("formation_start",
[(get_player_agent_no,reg(10)),
(agent_get_position,1,reg(10)),
(try_for_range,reg(20),1,100), #reset of the player dummy-slots
(agent_set_slot,reg(10),reg(20),0),
(try_end),
(try_for_agents,reg(5)),
(assign,reg(0),0),
#Not the player
(neq, reg(5), reg(10)),
#Not Dead
(agent_is_alive, reg(5)),
#Not a Horse?
(agent_is_human, reg(5)),
#If the Selected Troop is an Ally
(agent_is_ally,reg(5)),
(assign,reg(1),1),
(try_begin),
(assign,reg(20),1), #reg(20) is the agent number to use every position only once
(agent_get_slot,reg(21),reg(10),reg(20)), #player agent used as a dummy not to make several agent use one position
(eq,reg(21),0), #number isn't used, yet
(assign,reg(1),reg(20)),
(assign,reg(3),reg(1)),
(val_mul,reg(3),100),
(copy_position,reg(1),1),
(position_move_x,reg(1),reg(3)), #number 1 = 100 metres right to the player agent 2= 200 etc...
(agent_set_scripted_destination,reg(5),reg(1)), #tells the agent to run there
(agent_set_slot,reg(5),1,reg(1)), #tells the agent which position he has - only important if you want to do somethink else with the script, it would work without it right now.
(agent_set_slot,reg(10),reg(20),1), #tells the game that the number is used, by using the player slots.
(else_try),
#very odd, sorry (the more call_scripts are there \/, the more agents will build a formation
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),
(try_end),
(try_end),
]),
("formation_repeat",
[ (val_add,reg(20),1), # adds 1 to the agent number
(agent_get_slot,reg(21),reg(10),reg(20)),
(eq,reg(21),0), # again, is the number already used?
(assign,reg(1),reg(20)), #just copying the number to use it somewhere else...
(assign,reg(3),reg(1)), #again copying
(assign,reg(4),0), #assigns the row of this agent to 0
#-#-#-#-#-#-#-#-#-#
(try_for_range,reg(15),1,100), #this try-code assigns the right row.
(assign,reg(17),reg(15)),
(assign,reg(16),reg(15)),
(val_mul,reg(15),5), #number of troops in one line
(val_mul,reg(16),5), #has to be the same as above
(val_add,reg(16),5), #has to be the same as above
(gt,reg(3),reg(15)),
(le,reg(3),reg(16)),
(assign,reg(15),reg(17)),
(val_mul,reg(15),6), #number of troops in one line + 1
(val_sub,reg(3),reg(15)),
(assign,reg(4),reg(17)),
(try_end),
#delete these lines to get a 1 line formation
#-#-#-#-#-#-#-#-#-#
(val_mul,reg(3),100),
(val_mul,reg(4),200),
(copy_position,reg(1),1),
(position_move_x,reg(1),reg(3)),
(position_move_y,reg(1),reg(4)),
(agent_set_scripted_destination,reg(5),reg(1)),
(agent_set_slot,reg(5),1,reg(1)),
(agent_set_slot,reg(10),reg(20),1),
]),
and it says
ERROR: illegal identifier script_formation_start
error: unable to find object script_formation_start
wen i added it at any thing
mission templates
(
"charge",mtf_battle_mode,charge,
"You lead your men to the charge",
[
(8,mtef_defenders,0,group(1)|aif_start_alarmed,8,[]),
(9,mtef_defenders,0,group(1)|aif_start_alarmed,0,[]),
(10,mtef_attackers,0,aif_start_alarmed,8,[]),
(11,mtef_attackers,0,aif_start_alarmed,0,[]),
(12,mtef_attackers,0,aif_start_alarmed,0,[]),
(13,mtef_attackers,0,aif_start_alarmed,0,[]),
],
[
(ti_tab_pressed, 0, 0, [],
[
(try_begin),
(eq, "$battle_won", 1),
(finish_mission,0),
(else_try),
(call_script, "script_check_enemies_nearby"),
(question_box,"str_do_you_want_to_retreat"),
(else_try),
(display_message,"str_can_not_retreat"),
(try_end),
]),
(ti_question_answered, 0, 0, [],
[(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),
(0, 0, ti_once, [], [(assign,"$battle_won",0),(assign,"$defender_reinforcement_stage",0),(assign,"$attacker_reinforcement_stage",0)]),
(1, 0, 5, [(lt,"$defender_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_defender_count,reg(2)),(lt,reg(2),3)],
[(add_reinforcements_to_entry,0,4),(val_add,"$defender_reinforcement_stage",1)]),
(1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_attacker_count,reg(2)),(lt,reg(2),3)],
[(add_reinforcements_to_entry,3,4),(val_add,"$attacker_reinforcement_stage",1)]),
(1, 60, ti_once, [(store_mission_timer_a,reg(1)),
(ge,reg(1),10),(all_enemies_defeated,2),
(neg|main_hero_fallen,0),
(set_mission_result,1),
(assign, "$g_battle_result", 1),
(display_message,"str_msg_battle_won"),
(assign,"$battle_won",1)],
[(finish_mission,1)]),
(10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
(1, 4, ti_once, [(main_hero_fallen)],
[
(assign, "$g_battle_result", -1),
(set_mission_result,-1),(finish_mission,1)]),
(ti_inventory_key_pressed, 0, 0, [], [[color=red](call_script, "script_formation_start")[/color],(display_message,"str_formation")]),
],
),
module items
["javelin", "Javelin", [("javelin",0),("javelins_quiver", ixmesh_carry)], itp_type_thrown |itp_merchandise|itp_primary|itp_bonus_against_shield ,itcf_throw_javelin|itcf_carry_quiver_back|itcf_show_holster_when_drawn, 75 , weight(5)|difficulty(0)|spd_rtng(91) | shoot_speed(28) | thrust_damage(27 , pierce)|max_ammo(7)|weapon_length(75),imodbits_missile ],
["formation", "Long Spear", [("pike",0)], itp_type_thrown |itp_merchandise|itp_primary|itp_bonus_against_shield ,itcf_throw_javelin|itcf_show_holster_when_drawn, 75 , weight(5)|difficulty(0)|spd_rtng(91) | shoot_speed(28) | thrust_damage(27 , pierce)|max_ammo(17)|weapon_length(75),imodbits_missile ,[(ti_on_weapon_attack,[(call_script,"[color=red]script_formation_start[/color]")])]],
["stones", "Stones", [("throwing_stone",0)], itp_type_thrown |itp_merchandise|itp_primary ,itcf_throw_stone, 1 , weight(4)|difficulty(0)|spd_rtng(97) | shoot_speed(30) | thrust_damage(10 , blunt)|max_ammo(18)|weapon_length(8),imodbit_large_bag ],