Warband: Random Screen Props

Users who are viewing this thread

N0ught

Sergeant Knight at Arms
Ok, so you know how some of the rock screen props shuffle through a random selection of models- is it possible to script other props to do the same thing? :???:

If so, how? Perhaps the code is actually a script and I just can't find it...
 
I've never heard about randomly shuffled models, so I suspect what you speak about are not real scene props but elements of the map. Just like there are trees placed by the terrain generator and trees placed by map editor - latter ones are not shuffled.

However it is possible to implement random shuffling of models by implementing your own ti_before_mission_start trigger in module_mission_templates. Essentially, you place only one type of scene prop on the scene, and then before the mission starts, you iterate through all of them, and replace each instance with another scene prop, randomly chosen from your list. The operations you need are: scene_prop_get_num_instances (to get the total number of pre-placed scene props and run the cycle correctly), scene_prop_get_instance (to get individual instance), prop_instance_is_valid (just in case) and replace_prop_instance.
 
Lav said:
I've never heard about randomly shuffled models, so I suspect what you speak about are not real scene props but elements of the map. Just like there are trees placed by the terrain generator and trees placed by map editor - latter ones are not shuffled.

However it is possible to implement random shuffling of models by implementing your own ti_before_mission_start trigger in module_mission_templates. Essentially, you place only one type of scene prop on the scene, and then before the mission starts, you iterate through all of them, and replace each instance with another scene prop, randomly chosen from your list. The operations you need are: scene_prop_get_num_instances (to get the total number of pre-placed scene props and run the cycle correctly), scene_prop_get_instance (to get individual instance), prop_instance_is_valid (just in case) and replace_prop_instance.

nice trick :smile:.

I will remember this one!
 
Native scripts to take a look at for an idea of what Lav is talking about:
Code:
  # script_replace_scene_items_with_spawn_items_before_ms
  # Input: none
  # Output: none
  ("replace_scene_items_with_spawn_items_before_ms",
    [
      (try_for_range, ":item_no", all_items_begin, all_items_end),
        (scene_item_get_num_instances, ":num_instances", ":item_no"),
        (item_set_slot, ":item_no", slot_item_num_positions, 0),
        (assign, ":num_positions", 0),
        (try_for_range, ":cur_instance", 0, ":num_instances"),
          (scene_item_get_instance, ":scene_item", ":item_no", ":cur_instance"),
          (prop_instance_get_position, "$g_position_to_use_for_replacing_scene_items", ":scene_item"),
          (store_add, ":cur_slot", slot_item_positions_begin, ":num_positions"),
          (item_set_slot, ":item_no", ":cur_slot", "$g_position_to_use_for_replacing_scene_items"),
          (val_add, ":num_positions", 1),
          (val_add, "$g_position_to_use_for_replacing_scene_items", 1),
          (item_set_slot, ":item_no", slot_item_num_positions, ":num_positions"),
        (try_end),
        (replace_scene_items_with_scene_props, ":item_no", "spr_empty"),
      (try_end),
     ]),

  # script_replace_scene_items_with_spawn_items_after_ms
  # Input: none
  # Output: none
  ("replace_scene_items_with_spawn_items_after_ms",
    [
      (try_for_range, ":item_no", all_items_begin, all_items_end),
        (item_get_slot,  ":num_positions", ":item_no", slot_item_num_positions),
        (try_for_range, ":cur_position", 0, ":num_positions"),
          (store_add, ":cur_slot", slot_item_positions_begin, ":cur_position"),
          (item_get_slot, ":pos_no", ":item_no", ":cur_slot"),
          (set_spawn_position, ":pos_no"),
          (spawn_item, ":item_no", 0),
        (try_end),
      (try_end),
     ]),
 
Back
Top Bottom