python code doesn't work

Users who are viewing this thread

the store random number generator in mount and blade has too many duplicate 'random' numbers
here is my code defined in module constants using python
Code:
def randgennodups():
    import random
    output = random.sample(range(10), 1)
    output1 = output[0]
    return output1

("init_town_walkers_bugged", ##too many duplicate "randoms" MB has a ****ty random generator
[
(try_begin),
(try_for_range, ":walker_no", 0, num_town_walkers),
(store_add, ":troop_slot", slot_center_walker_0_troop, ":walker_no"),
(party_get_slot, ":walker_troop_id", "$current_town", ":troop_slot"),
(gt, ":walker_troop_id", 0),
(store_add, ":entry_no", town_walker_entries_start, ":walker_no"),
(store_random_in_range, ":walkers", walker_templates_begin, walker_templates_end),
(set_visitor, ":entry_no", ":walkers"),
(try_end),
(try_for_range, ":walker", walker_templates_begin, walker_templates_end),
(assign, reg1, randgennodups()),(store_random_in_range, reg2, 0, 24),(store_random_in_range, reg3, 5, 15),(store_random_in_range, reg4, 0, 7),
(val_mod, reg1, 10),
(store_random_in_range, reg5, 0, 7),(store_random_in_range, reg6, 0, 7),(store_random_in_range, reg7, 0, 7),
(store_random_in_range, reg8, 0, 7),(store_random_in_range, reg9, 0, 7),
(str_store_troop_face_keys, s1, "trp_player"),
(face_keys_set_hair, s1, reg1),(face_keys_set_beard, s1, reg2),(face_keys_set_age, s1, 0),(face_keys_set_face_texture, s1, reg3),
(face_keys_set_morph_key, s1, 1, reg4),
(face_keys_set_morph_key, s1, 2, reg5),
(face_keys_set_morph_key, s1, 3, reg6),
(face_keys_set_morph_key, s1, 4, reg7),
(face_keys_set_morph_key, s1, 5, reg:cool:,
(face_keys_set_morph_key, s1, 6, reg9),
(face_keys_set_morph_key, s1, 7, reg4),
(face_keys_set_morph_key, s1, 8, reg4),
(troop_set_face_keys, ":walker", s1, 0),
(store_random_in_range, ":clothing", unisex_clothing_start, unisex_clothing_end),
(store_random_in_range, ":clothingf", female_clothing_start, female_clothing_end),
(troop_get_type, ":gender", ":walker"),
(try_begin),
(eq, ":gender", 1),
(troop_add_item, ":walker", ":clothingf"),
(else_try),
(eq, ":gender", 0),
(troop_add_item, ":walker", ":clothing"),
(try_end),
(try_end),
(try_end),
]),

however in game i see the same hair everytime
 
This is how I fixed psevdorandom equipment of agents. When mission starts the random generator aparently uses mission timer as seed for random generator. Each time you enter to the scene random will generate the same sequence. It always uses 0 as time for starting random sequence. So I have just shifted the sequence of random numbers from (0 to 99) wich gives more random results in equipment. I think this also can help for face randomisation. Well at the beginning this code I used for random reequipment and sudenly it changes all randomness.

1) Add this trigger at the begining of each mission.
Python:
(ti_on_agent_spawn, 0, ti_once,[],[
    # Procedure to fix psevdorandom of troops equipment
    (try_for_range, ":i", 0, "$random_seed"), 
      (store_random_in_range, reg10, 0, 2),
    (try_end),

2) Add this code for each mission end possibilty. This can take some time but it is worth it.
Python:
(store_mission_timer_a_msec, "$random_seed"),
(val_mod, "$random_seed", 100),

In the global map I don't think that random can duplicate sequences because random uses time as seed.
Well the first spawned agent will not be randomised. Maybe reequip him.
 
Last edited:
Upvote 0
Back
Top Bottom