Hi i am modding warband using module system. For making the game more random and unique each new game, i started adding new random stuff to the "game_start" script. I just created a basic function that picks random lord from the specified faction and returns the lord's id as reg60. And then at the "game_start"
I used reg60 to assign centers to the random lords. When i compile it though:
I get these warnings. Other than that code works perfectly fine. The game loads and Count Fraichin had 2 Castles as intended. But the weird thing is as i read it from other forum posts, people say when a script named with "cf_" prefix, the game tries to expect an error. But my code works fine? Is my code vulnerable? If it is, how can i improve it? If these warnings are not dangerous should i ignore the warnings? Also the codes that i added:
Here is the "game_start" part:
"script_cf_pick_random_lord" that i created:
Also do you have any suggestions on how should i refactor my code? Specifically "cf_pick_random_lord" function. Its too bulky and long at the moment.
I used reg60 to assign centers to the random lords. When i compile it though:
Code:
Exporting info_page data...
Exporting scripts...
WARNING: Script can fail at operation #436. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #438. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #440. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #443. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #445. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #447. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #450. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #452. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #454. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #457. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #459. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #462. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #464. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #467. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #469. Use cf_ at the beginning of its name: game_start
WARNING: Script can fail at operation #471. Use cf_ at the beginning of its name: game_start
Exporting mission_template data...
Exporting game menus data...
exporting simple triggers...
I get these warnings. Other than that code works perfectly fine. The game loads and Count Fraichin had 2 Castles as intended. But the weird thing is as i read it from other forum posts, people say when a script named with "cf_" prefix, the game tries to expect an error. But my code works fine? Is my code vulnerable? If it is, how can i improve it? If these warnings are not dangerous should i ignore the warnings? Also the codes that i added:
Here is the "game_start" part:
Code:
...
#Now give towns to random lords. (Except for capitals)
# Praven / Capital
(call_script, "script_give_center_to_lord", "p_town_6", "trp_kingdom_1_lord", 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_1", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_4", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_1", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_7", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_1", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_16", reg60, 0),
# Reyvadin / Capital
(call_script, "script_give_center_to_lord", "p_town_8", "trp_kingdom_2_lord", 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_2", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_9", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_2", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_11", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_2", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_13", reg60, 0),
# Tulga / Capital
(call_script, "script_give_center_to_lord", "p_town_10", "trp_kingdom_3_lord", 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_3", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_14", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_3", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_17", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_3", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_18", reg60, 0),
# Sargot / Capital
(call_script, "script_give_center_to_lord", "p_town_1", "trp_kingdom_4_lord", 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_4", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_2", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_4", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_12", reg60, 0),
# Jelkala / Capital
(call_script, "script_give_center_to_lord", "p_town_5", "trp_kingdom_5_lord", 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_5", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_3", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_5", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_15", reg60, 0),
# Shariz / Capital
(call_script, "script_give_center_to_lord", "p_town_19", "trp_kingdom_6_lord", 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_6", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_20", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_6", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_21", reg60, 0),
(call_script, "script_cf_pick_random_lord", "fac_kingdom_6", 1, 21),
(call_script, "script_give_center_to_lord", "p_town_22", reg60, 0),
...
"script_cf_pick_random_lord" that i created:
Code:
# script_cf_pick_random_lord
# Input: faction, 1, 21
# Output: random faction lord troop at reg60
("cf_pick_random_lord",
[
(store_script_param, ":kingdom", 1),
(store_script_param, ":min", 2),
(store_script_param, ":max", 3),
#(call_script, "script_cf_get_random_number", ":min", ":max"), Disabled - 28 march 2022
(store_random_in_range, ":random_lord", ":min", ":max"),
(assign, ":chosen_one", 0), # if it fails, it will return player's id. so that game does not crash?
(try_begin),
(eq, ":kingdom", "fac_kingdom_1"),
(try_begin),
(eq, ":random_lord", 1),
(assign, ":chosen_one", "trp_knight_1_1"),
(else_try),
(eq, ":random_lord", 2),
(assign, ":chosen_one", "trp_knight_1_2"),
(else_try),
(eq, ":random_lord", 3),
(assign, ":chosen_one", "trp_knight_1_3"),
(else_try),
(eq, ":random_lord", 4),
(assign, ":chosen_one", "trp_knight_1_4"),
(else_try),
(eq, ":random_lord", 5),
(assign, ":chosen_one", "trp_knight_1_5"),
(else_try),
(eq, ":random_lord", 6),
(assign, ":chosen_one", "trp_knight_1_6"),
(else_try),
(eq, ":random_lord", 7),
(assign, ":chosen_one", "trp_knight_1_7"),
(else_try),
(eq, ":random_lord", 8),
(assign, ":chosen_one", "trp_knight_1_8"),
(else_try),
(eq, ":random_lord", 9),
(assign, ":chosen_one", "trp_knight_1_9"),
(else_try),
(eq, ":random_lord", 10),
(assign, ":chosen_one", "trp_knight_1_10"),
(else_try),
(eq, ":random_lord", 11),
(assign, ":chosen_one", "trp_knight_1_11"),
(else_try),
(eq, ":random_lord", 12),
(assign, ":chosen_one", "trp_knight_1_12"),
(else_try),
(eq, ":random_lord", 13),
(assign, ":chosen_one", "trp_knight_1_13"),
(else_try),
(eq, ":random_lord", 14),
(assign, ":chosen_one", "trp_knight_1_14"),
(else_try),
(eq, ":random_lord", 15),
(assign, ":chosen_one", "trp_knight_1_15"),
(else_try),
(eq, ":random_lord", 16),
(assign, ":chosen_one", "trp_knight_1_16"),
(else_try),
(eq, ":random_lord", 17),
(assign, ":chosen_one", "trp_knight_1_17"),
(else_try),
(eq, ":random_lord", 18),
(assign, ":chosen_one", "trp_knight_1_18"),
(else_try),
(eq, ":random_lord", 19),
(assign, ":chosen_one", "trp_knight_1_19"),
(else_try),
(eq, ":random_lord", 20),
(assign, ":chosen_one", "trp_knight_1_20"),
(try_end),
(else_try),
(eq, ":kingdom", "fac_kingdom_2"),
(try_begin),
(eq, ":random_lord", 1),
(assign, ":chosen_one", "trp_knight_2_1"),
(else_try),
(eq, ":random_lord", 2),
(assign, ":chosen_one", "trp_knight_2_2"),
(else_try),
(eq, ":random_lord", 3),
(assign, ":chosen_one", "trp_knight_2_3"),
(else_try),
(eq, ":random_lord", 4),
(assign, ":chosen_one", "trp_knight_2_4"),
(else_try),
(eq, ":random_lord", 5),
(assign, ":chosen_one", "trp_knight_2_5"),
(else_try),
(eq, ":random_lord", 6),
(assign, ":chosen_one", "trp_knight_2_6"),
(else_try),
(eq, ":random_lord", 7),
(assign, ":chosen_one", "trp_knight_2_7"),
(else_try),
(eq, ":random_lord", 8),
(assign, ":chosen_one", "trp_knight_2_8"),
(else_try),
(eq, ":random_lord", 9),
(assign, ":chosen_one", "trp_knight_2_9"),
(else_try),
(eq, ":random_lord", 10),
(assign, ":chosen_one", "trp_knight_2_10"),
(else_try),
(eq, ":random_lord", 11),
(assign, ":chosen_one", "trp_knight_2_11"),
(else_try),
(eq, ":random_lord", 12),
(assign, ":chosen_one", "trp_knight_2_12"),
(else_try),
(eq, ":random_lord", 13),
(assign, ":chosen_one", "trp_knight_2_13"),
(else_try),
(eq, ":random_lord", 14),
(assign, ":chosen_one", "trp_knight_2_14"),
(else_try),
(eq, ":random_lord", 15),
(assign, ":chosen_one", "trp_knight_2_15"),
(else_try),
(eq, ":random_lord", 16),
(assign, ":chosen_one", "trp_knight_2_16"),
(else_try),
(eq, ":random_lord", 17),
(assign, ":chosen_one", "trp_knight_2_17"),
(else_try),
(eq, ":random_lord", 18),
(assign, ":chosen_one", "trp_knight_2_18"),
(else_try),
(eq, ":random_lord", 19),
(assign, ":chosen_one", "trp_knight_2_19"),
(else_try),
(eq, ":random_lord", 20),
(assign, ":chosen_one", "trp_knight_2_20"),
(try_end),
(else_try),
(eq, ":kingdom", "fac_kingdom_3"),
(try_begin),
(eq, ":random_lord", 1),
(assign, ":chosen_one", "trp_knight_3_1"),
(else_try),
(eq, ":random_lord", 2),
(assign, ":chosen_one", "trp_knight_3_2"),
(else_try),
(eq, ":random_lord", 3),
(assign, ":chosen_one", "trp_knight_3_3"),
(else_try),
(eq, ":random_lord", 4),
(assign, ":chosen_one", "trp_knight_3_4"),
(else_try),
(eq, ":random_lord", 5),
(assign, ":chosen_one", "trp_knight_3_5"),
(else_try),
(eq, ":random_lord", 6),
(assign, ":chosen_one", "trp_knight_3_6"),
(else_try),
(eq, ":random_lord", 7),
(assign, ":chosen_one", "trp_knight_3_7"),
(else_try),
(eq, ":random_lord", 8),
(assign, ":chosen_one", "trp_knight_3_8"),
(else_try),
(eq, ":random_lord", 9),
(assign, ":chosen_one", "trp_knight_3_9"),
(else_try),
(eq, ":random_lord", 10),
(assign, ":chosen_one", "trp_knight_3_10"),
(else_try),
(eq, ":random_lord", 11),
(assign, ":chosen_one", "trp_knight_3_11"),
(else_try),
(eq, ":random_lord", 12),
(assign, ":chosen_one", "trp_knight_3_12"),
(else_try),
(eq, ":random_lord", 13),
(assign, ":chosen_one", "trp_knight_3_13"),
(else_try),
(eq, ":random_lord", 14),
(assign, ":chosen_one", "trp_knight_3_14"),
(else_try),
(eq, ":random_lord", 15),
(assign, ":chosen_one", "trp_knight_3_15"),
(else_try),
(eq, ":random_lord", 16),
(assign, ":chosen_one", "trp_knight_3_16"),
(else_try),
(eq, ":random_lord", 17),
(assign, ":chosen_one", "trp_knight_3_17"),
(else_try),
(eq, ":random_lord", 18),
(assign, ":chosen_one", "trp_knight_3_18"),
(else_try),
(eq, ":random_lord", 19),
(assign, ":chosen_one", "trp_knight_3_19"),
(else_try),
(eq, ":random_lord", 20),
(assign, ":chosen_one", "trp_knight_3_20"),
(try_end),
(else_try),
(eq, ":kingdom", "fac_kingdom_4"),
(try_begin),
(eq, ":random_lord", 1),
(assign, ":chosen_one", "trp_knight_4_1"),
(else_try),
(eq, ":random_lord", 2),
(assign, ":chosen_one", "trp_knight_4_2"),
(else_try),
(eq, ":random_lord", 3),
(assign, ":chosen_one", "trp_knight_4_3"),
(else_try),
(eq, ":random_lord", 4),
(assign, ":chosen_one", "trp_knight_4_4"),
(else_try),
(eq, ":random_lord", 5),
(assign, ":chosen_one", "trp_knight_4_5"),
(else_try),
(eq, ":random_lord", 6),
(assign, ":chosen_one", "trp_knight_4_6"),
(else_try),
(eq, ":random_lord", 7),
(assign, ":chosen_one", "trp_knight_4_7"),
(else_try),
(eq, ":random_lord", 8),
(assign, ":chosen_one", "trp_knight_4_8"),
(else_try),
(eq, ":random_lord", 9),
(assign, ":chosen_one", "trp_knight_4_9"),
(else_try),
(eq, ":random_lord", 10),
(assign, ":chosen_one", "trp_knight_4_10"),
(else_try),
(eq, ":random_lord", 11),
(assign, ":chosen_one", "trp_knight_4_11"),
(else_try),
(eq, ":random_lord", 12),
(assign, ":chosen_one", "trp_knight_4_12"),
(else_try),
(eq, ":random_lord", 13),
(assign, ":chosen_one", "trp_knight_4_13"),
(else_try),
(eq, ":random_lord", 14),
(assign, ":chosen_one", "trp_knight_4_14"),
(else_try),
(eq, ":random_lord", 15),
(assign, ":chosen_one", "trp_knight_4_15"),
(else_try),
(eq, ":random_lord", 16),
(assign, ":chosen_one", "trp_knight_4_16"),
(else_try),
(eq, ":random_lord", 17),
(assign, ":chosen_one", "trp_knight_4_17"),
(else_try),
(eq, ":random_lord", 18),
(assign, ":chosen_one", "trp_knight_4_18"),
(else_try),
(eq, ":random_lord", 19),
(assign, ":chosen_one", "trp_knight_4_19"),
(else_try),
(eq, ":random_lord", 20),
(assign, ":chosen_one", "trp_knight_4_20"),
(try_end),
(else_try),
(eq, ":kingdom", "fac_kingdom_5"),
(try_begin),
(eq, ":random_lord", 1),
(assign, ":chosen_one", "trp_knight_5_1"),
(else_try),
(eq, ":random_lord", 2),
(assign, ":chosen_one", "trp_knight_5_2"),
(else_try),
(eq, ":random_lord", 3),
(assign, ":chosen_one", "trp_knight_5_3"),
(else_try),
(eq, ":random_lord", 4),
(assign, ":chosen_one", "trp_knight_5_4"),
(else_try),
(eq, ":random_lord", 5),
(assign, ":chosen_one", "trp_knight_5_5"),
(else_try),
(eq, ":random_lord", 6),
(assign, ":chosen_one", "trp_knight_5_6"),
(else_try),
(eq, ":random_lord", 7),
(assign, ":chosen_one", "trp_knight_5_7"),
(else_try),
(eq, ":random_lord", 8),
(assign, ":chosen_one", "trp_knight_5_8"),
(else_try),
(eq, ":random_lord", 9),
(assign, ":chosen_one", "trp_knight_5_9"),
(else_try),
(eq, ":random_lord", 10),
(assign, ":chosen_one", "trp_knight_5_10"),
(else_try),
(eq, ":random_lord", 11),
(assign, ":chosen_one", "trp_knight_5_11"),
(else_try),
(eq, ":random_lord", 12),
(assign, ":chosen_one", "trp_knight_5_12"),
(else_try),
(eq, ":random_lord", 13),
(assign, ":chosen_one", "trp_knight_5_13"),
(else_try),
(eq, ":random_lord", 14),
(assign, ":chosen_one", "trp_knight_5_14"),
(else_try),
(eq, ":random_lord", 15),
(assign, ":chosen_one", "trp_knight_5_15"),
(else_try),
(eq, ":random_lord", 16),
(assign, ":chosen_one", "trp_knight_5_16"),
(else_try),
(eq, ":random_lord", 17),
(assign, ":chosen_one", "trp_knight_5_17"),
(else_try),
(eq, ":random_lord", 18),
(assign, ":chosen_one", "trp_knight_5_18"),
(else_try),
(eq, ":random_lord", 19),
(assign, ":chosen_one", "trp_knight_5_19"),
(else_try),
(eq, ":random_lord", 20),
(assign, ":chosen_one", "trp_knight_5_20"),
(try_end),
(else_try),
(eq, ":kingdom", "fac_kingdom_6"),
(try_begin),
(eq, ":random_lord", 1),
(assign, ":chosen_one", "trp_knight_6_1"),
(else_try),
(eq, ":random_lord", 2),
(assign, ":chosen_one", "trp_knight_6_2"),
(else_try),
(eq, ":random_lord", 3),
(assign, ":chosen_one", "trp_knight_6_3"),
(else_try),
(eq, ":random_lord", 4),
(assign, ":chosen_one", "trp_knight_6_4"),
(else_try),
(eq, ":random_lord", 5),
(assign, ":chosen_one", "trp_knight_6_5"),
(else_try),
(eq, ":random_lord", 6),
(assign, ":chosen_one", "trp_knight_6_6"),
(else_try),
(eq, ":random_lord", 7),
(assign, ":chosen_one", "trp_knight_6_7"),
(else_try),
(eq, ":random_lord", 8),
(assign, ":chosen_one", "trp_knight_6_8"),
(else_try),
(eq, ":random_lord", 9),
(assign, ":chosen_one", "trp_knight_6_9"),
(else_try),
(eq, ":random_lord", 10),
(assign, ":chosen_one", "trp_knight_6_10"),
(else_try),
(eq, ":random_lord", 11),
(assign, ":chosen_one", "trp_knight_6_11"),
(else_try),
(eq, ":random_lord", 12),
(assign, ":chosen_one", "trp_knight_6_12"),
(else_try),
(eq, ":random_lord", 13),
(assign, ":chosen_one", "trp_knight_6_13"),
(else_try),
(eq, ":random_lord", 14),
(assign, ":chosen_one", "trp_knight_6_14"),
(else_try),
(eq, ":random_lord", 15),
(assign, ":chosen_one", "trp_knight_6_15"),
(else_try),
(eq, ":random_lord", 16),
(assign, ":chosen_one", "trp_knight_6_16"),
(else_try),
(eq, ":random_lord", 17),
(assign, ":chosen_one", "trp_knight_6_17"),
(else_try),
(eq, ":random_lord", 18),
(assign, ":chosen_one", "trp_knight_6_18"),
(else_try),
(eq, ":random_lord", 19),
(assign, ":chosen_one", "trp_knight_6_19"),
(else_try),
(eq, ":random_lord", 20),
(assign, ":chosen_one", "trp_knight_6_20"),
(try_end),
(try_end),
(assign, reg60, ":chosen_one"),
]),
Also do you have any suggestions on how should i refactor my code? Specifically "cf_pick_random_lord" function. Its too bulky and long at the moment.