PYTHON SCRIPT/SCHEME EXCHANGE

Users who are viewing this thread

anyone of you talents feel challenged to do a formation that places ranged weapon troop behind a defensive line of melee troops? maw
 
I've thought about it, but it would be pointless, since the ranged troops wouldn't shoot past the defensive melee troops.
 
maw said:
anyone of you talents feel challenged to do a formation that places ranged weapon troop behind a defensive line of melee troops? maw

Impossible till next version, then easy. As of now, ranged units don't follow waypoints. Then they will, and I could make a script which calls the infantry into formation, and then moves the position back and calls archers to formation. I have a feeling a lot of infantry would get shot in the back of the head, though.
 
Mirathei,

I've noted an odd behavior with your script. Some agents don't want to make the formation, they charge the enemy, stop when they're at range, then move backward/forward/bacward/forward... This issue happens when I've no cavalry, and only farmers, watchmen and townsmen. I must say that I've not tried it with "regular" troops (Vaegir or Swandian experienced troops), because I've put the script in a "clean" mod (Native+ your script), and I did not have the time to cheat soldiers...

It still is a clear, light and understandable script. Thanks :grin:
 
André de Cuyne said:
only farmers, watchmen and townsmen.

All three carry ranged weapons. Crossbows for the watchmen, rocks for the farmers and townsmen. Ranged units will not respond to waypoints, so the do not try to get into position untill they put away their ranged weapons. Thus they run toward the enemy with ranged, are charged and thus switch to melee and are told to get in formation. They run back, get far away from the enemy, then switch back  to ranged, and charge forward again. Same thing will happen with any formation code in .808. You need to use pure melee infantry.
 
i think the primary and secondary weapon tf's might fix this: assign all ranged as secondary and all melee weapons as primary. maw
 
No, I tried that too. The units will stay in formation while they have a melee weapon equiped and leave it once they equip their ranged. I could have encountered a fluke, but I doubt it.
 
No ranged footmen. I had a doubt. I know it's possible to detect which weapon an agent is equiped. Maybe it is a solution. Did somebody ever try ?
 
Sheep_Archer said:
How would checking which weapon an agent is currently using help?

To know if the agent is equipped with a ranged weapon. But scripts doesn't concern those equipped with ranged.

Rathyr said:
I'm stupid: How do I implement this?


("formation",
    ...
    ...
    ...
),
Open the file module_scripts.py and put the script before the last bracket (']'). Save and compile the module. Check here for more info about the Module System.
 
Either use a ranged weapon with a ti_on_weapon_attack trigger including (call_script,"script_formation") or use (call_script,"script_formation") in a mission template trigger.
 
This code will make your troops follow 9 waypoints, which can be used with siege towers. You can easily add extra waypoints to it. The waypoints are numbered 11 - 19

Regular one:
      (0.5, 0, 0, [],
       [
           (get_player_agent_no, ":player_agent_no"),
           (entry_point_get_position,1,11),(entry_point_get_position,5,15),
           (entry_point_get_position,2,12),(entry_point_get_position,6,16),
           (entry_point_get_position,3,13),(entry_point_get_position,7,17),
           (entry_point_get_position,4,14),(entry_point_get_position,8,1:cool:,
           (entry_point_get_position,9,19),
           (try_for_agents,":agents"),
             (neq, ":agents", ":player_agent_no"),
             (agent_is_alive, ":agents"),
             (agent_is_human, ":agents"),
             (neg|agent_is_defender, ":agents"),
             (agent_get_slot, ":agent_destination", ":agents", 1),
             (str_store_agent_name,40,":agents"),
             (assign,reg(40),":agent_destination"),
#             (display_message, "str_debug_string_1"),
             (agent_get_position, 35, ":agents"),
             (try_begin),
               (eq, ":agent_destination", 0),
               (try_begin),
                 (agent_set_scripted_destination, ":agents", 1),
                 (agent_set_slot,":agents",1,1),
(assign,":agent_destination",1),
               (try_end),
             (else_try),
                 (eq,":agent_destination",1),
               (try_begin),
     (get_distance_between_positions,":current_destination",35,1),
                 (lt,":current_destination", 200),
                 (agent_set_scripted_destination, ":agents", 2),
                 (agent_set_slot,":agents",1,2),
(assign,":agent_destination",2),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",2),
               (try_begin),
     (get_distance_between_positions,":current_destination",35,2),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 3),
                 (agent_set_slot,":agents",1,3),
(assign,":agent_destination",3),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",3),
               (try_begin),
                  (get_distance_between_positions,":current_destination",35,3),
                 (lt,":current_destination", 100),
                (agent_set_scripted_destination, ":agents", 4),
                 (agent_set_slot,":agents",1,4),
(assign,":agent_destination",4),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",4),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,4),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 5),
                 (agent_set_slot,":agents",1,5),
(assign,":agent_destination",5),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",5),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,5),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 6),
                 (agent_set_slot,":agents",1,6),
(assign,":agent_destination",6),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",6),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,6),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 7),
                 (agent_set_slot,":agents",1,7),
(assign,":agent_destination",7),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",7),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,7),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", :cool:,
                 (agent_set_slot,":agents",1,:cool:,
(assign,":agent_destination",:cool:,
                  (try_end),
             (else_try),
                 (eq,":agent_destination",:cool:,
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,:cool:,
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 9),
                 (agent_set_slot,":agents",1,9),
(assign,":agent_destination",9),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",9),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,9),
                 (lt,":current_destination", 300),
                   (agent_clear_scripted_mode, ":agents"),
                   (agent_set_slot,":agents",1,10),#with agent slot 10 you can check which agents are already clear of scripts, and you could call new scripts on them
(try_end),
                (try_end),
   (try_end),

With this second version the first troops to arrive at waypoint 8 (the last waypoint before the ramp) will wait for around a minute if the ramp is already open. I did this so troops would pile up and not get slaughtered one by one. After a minute they will procede to waypoint 9, which is located on the wall and troops will skip waypoint 8.
      (0.5, 0, 0, [],
       [
           (get_player_agent_no, ":player_agent_no"),
           (entry_point_get_position,1,11),(entry_point_get_position,5,15),
           (entry_point_get_position,2,12),(entry_point_get_position,6,16),
           (entry_point_get_position,3,13),(entry_point_get_position,7,17),
           (entry_point_get_position,4,14),(entry_point_get_position,8,1:cool:,
           (entry_point_get_position,9,19),
           (try_for_agents,":agents"),
             (neq, ":agents", ":player_agent_no"),
             (agent_is_alive, ":agents"),
             (agent_is_human, ":agents"),
             (neg|agent_is_defender, ":agents"),
             (agent_get_slot, ":agent_destination", ":agents", 1),
             (str_store_agent_name,40,":agents"),
             (assign,reg(40),":agent_destination"),
#             (display_message, "str_debug_string_1"),
             (agent_get_position, 35, ":agents"),
             (try_begin),
               (eq, ":agent_destination", 0),
               (try_begin),
                 (agent_set_scripted_destination, ":agents", 1),
                 (agent_set_slot,":agents",1,1),
(assign,":agent_destination",1),
               (try_end),
             (else_try),
                 (eq,":agent_destination",1),
               (try_begin),
     (get_distance_between_positions,":current_destination",35,1),
                 (lt,":current_destination", 200),
                 (agent_set_scripted_destination, ":agents", 2),
                 (agent_set_slot,":agents",1,2),
(assign,":agent_destination",2),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",2),
               (try_begin),
     (get_distance_between_positions,":current_destination",35,2),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 3),
                 (agent_set_slot,":agents",1,3),
(assign,":agent_destination",3),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",3),
               (try_begin),
                  (get_distance_between_positions,":current_destination",35,3),
                 (lt,":current_destination", 100),
                (agent_set_scripted_destination, ":agents", 4),
                 (agent_set_slot,":agents",1,4),
(assign,":agent_destination",4),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",4),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,4),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 5),
                 (agent_set_slot,":agents",1,5),
(assign,":agent_destination",5),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",5),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,5),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 6),
                 (agent_set_slot,":agents",1,6),
(assign,":agent_destination",6),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",6),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,6),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 7),
                 (agent_set_slot,":agents",1,7),
(assign,":agent_destination",7),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",7),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,7),
                 (lt,":current_destination", 100),
  (try_begin),
   (neq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", :cool:,
                   (agent_set_slot,":agents",1,:cool:,
       (assign,":agent_destination",:cool:,
   (else_try),
   (eq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", 9),
                   (agent_set_slot,":agents",1,9),
       (assign,":agent_destination",9),    
   (try_end),
                (try_end),
             (else_try),
                 (eq,":agent_destination",:cool:,
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,:cool:,
                 (lt,":current_destination", 100),
                 (agent_set_slot,":agents",1,9),
(assign,":agent_destination",9),
(assign,"$front_tower_reached",1),
(else_try),
   (eq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", 9),
                   (agent_set_slot,":agents",1,9),
       (assign,":agent_destination",9),    
   (try_end),
             (else_try),
                 (eq,":agent_destination",9),
               (try_begin),
                   (eq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", 9),
                   (agent_set_slot,":agents",1,10),
   (try_end),
             (else_try),
                 (eq,":agent_destination",10),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,10),
                 (lt,":current_destination", 300),
                   (agent_clear_scripted_mode, ":agents"),
                   (agent_set_slot,":agents",1,11),
(try_end),
                (try_end),
   (try_end),
        ]),
(10, 30, 0, [(eq,"$front_tower_reached",1)],
       [(assign, "$lower_ramp",1)]),

Tips for using the script in combination with a siege tower:
- If you're using ramps, put AI limiters in the centre so they can't get back to the previous ramp
- If you're using ramps, make sure the waypoints aren't too far in the corner, or else the ones who reached it get surrouned by those who haven't reached it

Enjoy! :smile:
 
This is how you'd best construct the siege tower if you want it to include ramps:


Here's how you set AI barriers and the first waypoint:


This is how you should set the 16 m AI barriers through the middle of it, also covering the ramps. You can also see you you should set the waypoints.


Tip: Make it so that when they're just in scripted reach of the waypoint, they're just behind the AI barrier.
 
Raz it gave me a sintax error

tuple index out of range

Code:
  (
    "castle_attack_walls2",mtf_battle_mode,-1,
    "You attack the walls of the castle...",
    [
     (0,mtef_attackers,af_override_horse,aif_start_alarmed,1,[]),
     (0,mtef_attackers,af_override_horse,aif_start_alarmed,4,[]),
     (8,mtef_defenders,af_override_horse,aif_start_alarmed,2,[]),
     (9,mtef_defenders,af_override_horse,aif_start_alarmed,2,[]),
     (10,mtef_defenders,af_override_horse|af_override_weapons|af_override_head,2,[itm_practice_bow2,itm_arrows,itm_sword,itm_shield_round_e]),
     ],
    [
      (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,"$enemy_reinforcement_stage",0),(assign,"$friend_reinforcement_stage",0)]),
      (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),(display_message,"str_msg_battle_won"),(assign,"$battle_won",1),(assign, "$g_battle_result", 1)],
           [(finish_mission,1)]),
      (10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
      (1, 4, ti_once, [(main_hero_fallen,0)],
          [(set_mission_result,-1),(finish_mission,1)]),
       #Lead attackers climb the ramps over to the walls
      # We assume:
      # entry_point 1 = start of first ramp
      # entry_point 2 = end of first ramp
      # entry_point 3 = start of second ramp
      # entry_point 4 = end of second ramp
      
      (0.5, 0, 0, [], 
       [
           (get_player_agent_no, ":player_agent_no"),
           (entry_point_get_position,1,11),(entry_point_get_position,5,15),
           (entry_point_get_position,2,12),(entry_point_get_position,6,16),
           (entry_point_get_position,3,13),(entry_point_get_position,7,17),
           (entry_point_get_position,4,14),(entry_point_get_position,8,18),
           (entry_point_get_position,9,19),
           (try_for_agents,":agents"),
             (neq, ":agents", ":player_agent_no"),
             (agent_is_alive, ":agents"),
             (agent_is_human, ":agents"),
             (neg|agent_is_defender, ":agents"),
             (agent_get_slot, ":agent_destination", ":agents", 1),
             (str_store_agent_name,40,":agents"),
             (assign,reg(40),":agent_destination"),
#             (display_message, "str_debug_string_1"),
             (agent_get_position, 35, ":agents"),
             (try_begin),
               (eq, ":agent_destination", 0),
               (try_begin),
                 (agent_set_scripted_destination, ":agents", 1),
                 (agent_set_slot,":agents",1,1),
				 (assign,":agent_destination",1),
               (try_end),
             (else_try),
                 (eq,":agent_destination",1),
               (try_begin),
			     (get_distance_between_positions,":current_destination",35,1),
                 (lt,":current_destination", 200),
                 (agent_set_scripted_destination, ":agents", 2),
                 (agent_set_slot,":agents",1,2),
				 (assign,":agent_destination",2),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",2),
               (try_begin),
			     (get_distance_between_positions,":current_destination",35,2),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 3),
                 (agent_set_slot,":agents",1,3),
				 (assign,":agent_destination",3),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",3),
               (try_begin),
                  (get_distance_between_positions,":current_destination",35,3),
                 (lt,":current_destination", 100),
                (agent_set_scripted_destination, ":agents", 4),
                 (agent_set_slot,":agents",1,4),
				 (assign,":agent_destination",4),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",4),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,4),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 5),
                 (agent_set_slot,":agents",1,5),
				 (assign,":agent_destination",5),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",5),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,5),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 6),
                 (agent_set_slot,":agents",1,6),
				 (assign,":agent_destination",6),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",6),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,6),
                 (lt,":current_destination", 100),
                 (agent_set_scripted_destination, ":agents", 7),
                 (agent_set_slot,":agents",1,7),
				 (assign,":agent_destination",7),
                  (try_end),
             (else_try),
                 (eq,":agent_destination",7),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,7),
                 (lt,":current_destination", 100),
				  (try_begin),
				   (neq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", 8),
                   (agent_set_slot,":agents",1,8),
 			       (assign,":agent_destination",8),
				   (else_try),
				   (eq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", 9),
                   (agent_set_slot,":agents",1,9),
 			       (assign,":agent_destination",9),				   
				   (try_end),
                (try_end),
             (else_try),
                 (eq,":agent_destination",8),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,8),
                 (lt,":current_destination", 100),
                 (agent_set_slot,":agents",1,9),
 				 (assign,":agent_destination",9),
				 (assign,"$front_tower_reached",1),
				 (else_try),
				   (eq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", 9),
                   (agent_set_slot,":agents",1,9),
 			       (assign,":agent_destination",9),				   
				   (try_end),
             (else_try),
                 (eq,":agent_destination",9),
               (try_begin),
                   (eq, "$lower_ramp",1),
                   (agent_set_scripted_destination, ":agents", 9),
                   (agent_set_slot,":agents",1,10),
				   (try_end),
             (else_try),
                 (eq,":agent_destination",10),
               (try_begin),
                 (get_distance_between_positions,":current_destination",35,10),
                 (lt,":current_destination", 300),
                   (agent_clear_scripted_mode, ":agents"),
                   (agent_set_slot,":agents",1,11),
				 (try_end),
                (try_end),
			   (try_end),
        ]),
	(10, 30, 0, [(eq,"$front_tower_reached",1)], 
       [(assign, "$lower_ramp",1)]),
      (ti_inventory_key_pressed, 0, 0, [],
       [
           (try_begin),
             (eq,"$ramp",0),
             (assign,"$ramp",1),
             (call_script,"script_ramp"),
           (else_try),
             (eq,"$ramp",1),
             (assign,"$ramp",0),
             (call_script,"script_ramp2"),
           (try_end),
]),
    ],
  ),

and i don't use m&b dev because mi firewall blocks but i think this aren't the error
 
DarkAnd said:
Raz it gave me a sintax error

tuple index out of range

and i don't use m&b dev because mi firewall blocks but i think this aren't the error
Ah, you copied the :cool: didn't you? You should quote first because there's a smiley in the code.
 
Back
Top Bottom