OSP Code MP Character greenscreen

Users who are viewing this thread

1. Introduction

Alright, this OSP will also be massive. The modding scene of Warband seems to have gone pretty extinct as of late, so I guess I may give people some more goodies before I leave it altogether (as another New Year 2022 present; happy new year!). Before getting rid of all Warband-related stuff, I think it is nice to salvage some stuff I deem worthy enough to share and which will not disrupt balance in MP. Here is a bundle of MP scripts related to one another that I wrote for my mod Varena NeoGK (https://forums.taleworlds.com/index.php?threads/varena-neogk.447294/); they deal with character greenscreen in general. Maybe someone will find them useful, who knows?

To know what I am talking about, here is a picture of the function:
20211111181032-1.jpg

They were written for MP, so some adjustments may be needed to port them to SP or adjust to some other non-Native modules.

2. License

I created the scripts all alone from scratch, therefore giving me credit is mandatory. All adjustments or big modifications may be done at one's discretion, whatever they want to do with the scripts. They may (they work perfectly in Native MP) exhibit some worse scripting than if a professional wrote them, therefore they are provided as they are. I do not want to receive suggestions or improvement solutions regarding them, so respect that please.

3. The scripts and their installation and properties

  • The below script's description from Varena NeoGK's thread linked above: Character greenscreen - capturing current character's face, armor and one item used - allowing to easily cut out a picture for many uses, such as a template for memes or other types of pictures.
Python:
("madmin_varena_my_character", prsntf_manual_end_only, 0, [
    (ti_on_presentation_load,
      [
        (presentation_set_duration, 999999),
        (set_fixed_point_multiplier, 1000),
       
        (create_mesh_overlay, reg0, "mesh_white_plane"), #the background greenscreen
        (overlay_set_color, reg0, 0x00FF00),
        (overlay_set_alpha, reg0, 0xFF),
        (position_set_x, pos1, 0),
        (position_set_y, pos1, 0),
        (overlay_set_position, reg0, pos1),
        (position_set_x, pos1, 999999), #just to be sure
        (position_set_y, pos1, 999999),
        (overlay_set_size, reg0, pos1),
       
#the uncommented section below was uncommented because the button did not work in a presentation called in MP for some reason (leaving it for someone just in case)

        #(create_game_button_overlay, "$g_presentation_obj_character_greenscreen_go_back", "str_back", 0),
        #(position_set_x, pos1, 565),
        #(position_set_y, pos1, 665),
        #(overlay_set_position, "$g_presentation_obj_character_greenscreen_go_back", pos1),
        #(position_set_x, pos1, 60),
        #(position_set_y, pos1, 30),
        #(overlay_set_size, "$g_presentation_obj_character_greenscreen_go_back", pos1),
        #(set_container_overlay, "$g_presentation_obj_character_greenscreen_go_back"),
       
        (create_image_button_overlay_with_tableau_material, reg9, -1, "tableau_greenscreen_2", -1), #center
        (position_set_x, pos1, 270),
        (position_set_y, pos1, -230),
        (overlay_set_position, reg9, pos1),
        (position_set_x, pos1, 1000),
        (position_set_y, pos1, 1000),
        (overlay_set_size, reg9, pos1),
       
        (create_image_button_overlay_with_tableau_material, reg9, -1, "tableau_greenscreen_1", -1), #right
        (position_set_x, pos1, 200),
        (position_set_y, pos1, 30),
        (overlay_set_position, reg9, pos1),
        (position_set_x, pos1, 1400),
        (position_set_y, pos1, 1400),
        (overlay_set_size, reg9, pos1),
       
        (create_image_button_overlay_with_tableau_material, reg9, -1, "tableau_greenscreen_3", -1), #left
        (position_set_x, pos1, -310),
        (position_set_y, pos1, 0),
        (overlay_set_position, reg9, pos1),
        (position_set_x, pos1, 1400),
        (position_set_y, pos1, 1400),
        (overlay_set_size, reg9, pos1),
       
        (create_text_overlay, "$g_presentation_obj_varena_my_character", "@Character greenscreen", tf_double_space|tf_vertical_align_center|tf_center_justify|tf_single_line|tf_with_outline),
        (position_set_x, pos1, 500),
        (position_set_y, pos1, 710),
        (overlay_set_position, "$g_presentation_obj_varena_my_character", pos1),
        (position_set_x, pos1, 1400),
        (position_set_y, pos1, 1400),
        (overlay_set_size, "$g_presentation_obj_varena_my_character", pos1),
        (overlay_set_color, "$g_presentation_obj_varena_my_character", 0xC23A28),
       
        (create_text_overlay, "$g_presentation_obj_varena_my_character_exit", "@Press 'Esc' to exit", tf_double_space|tf_vertical_align_center|tf_center_justify|tf_single_line|tf_with_outline),
        (position_set_x, pos1, 539),
        (position_set_y, pos1, 685),
        (overlay_set_position, "$g_presentation_obj_varena_my_character_exit", pos1),
        (position_set_x, pos1, 900),
        (position_set_y, pos1, 900),
        (overlay_set_size, "$g_presentation_obj_varena_my_character_exit", pos1),
        (overlay_set_color, "$g_presentation_obj_varena_my_character_exit", 0xE05303),

        ]),

    (ti_on_presentation_event_state_change,
        [
          (store_trigger_param_1, ":object"),
          (try_begin),
            (eq, ":object", "$g_presentation_obj_character_greenscreen_go_back"),
            (presentation_set_duration, 0),
          (try_end),
         ]),
   
    (ti_on_presentation_run,
      [(try_begin),
           (this_or_next|key_clicked, key_escape),
           (key_clicked, key_xbox_start),
           (presentation_set_duration, 0),
         (try_end),
    ]),
  ])

Python:
("troop_profile_alpha_mask_greenscreen_3", 0, "mat_troop_portrait_mask", 1024, 1024, 0, 0, 600, 600,
       [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0x0000FF00), #0x00888888
       (cur_tableau_set_ambient_light, 10,11,15),
       (cur_tableau_render_as_alpha_mask),
       (call_script, "script_add_player_to_cur_tableau_for_greenscreen_3", ":troop_no"),
       ]),

    ("troop_profile_color_greenscreen_3", 0, "mat_troop_portrait_color", 1024, 1024, 0, 0, 600, 600,
       [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0xFF00FF00), #0xFFF9E7A8
       (cur_tableau_set_ambient_light, 10,11,15),
       (call_script, "script_add_player_to_cur_tableau_for_greenscreen_3", ":troop_no"),
       ]),
 
     ("troop_profile_alpha_mask_greenscreen_2", 0, "mat_troop_portrait_mask", 1024, 1024, 0, 0, 600, 600,
       [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0x0000FF00), #0x00888888
       (cur_tableau_set_ambient_light, 10,11,15),
       (cur_tableau_render_as_alpha_mask),
       (call_script, "script_add_player_to_cur_tableau_for_greenscreen_2", ":troop_no"),
       ]),

    ("troop_profile_color_greenscreen_2", 0, "mat_troop_portrait_color", 1024, 1024, 0, 0, 600, 600,
       [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0xFF00FF00), #0xFFF9E7A8
       (cur_tableau_set_ambient_light, 10,11,15),
       (call_script, "script_add_player_to_cur_tableau_for_greenscreen_2", ":troop_no"),
       ]),
 
     ("troop_profile_alpha_mask_greenscreen_1", 0, "mat_troop_portrait_mask", 1024, 1024, 0, 0, 600, 600,
       [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0x0000FF00), #0x00888888
       (cur_tableau_set_ambient_light, 10,11,15),
       (cur_tableau_render_as_alpha_mask),
       (call_script, "script_add_player_to_cur_tableau_for_greenscreen_1", ":troop_no"),
       ]),

    ("troop_profile_color_greenscreen_1", 0, "mat_troop_portrait_color", 1024, 1024, 0, 0, 600, 600,
       [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0xFF00FF00), #0xFFF9E7A8
       (cur_tableau_set_ambient_light, 10,11,15),
       (call_script, "script_add_player_to_cur_tableau_for_greenscreen_1", ":troop_no"),
       ]),
   
    ("greenscreen_1", 0, "tableau_with_transparency", 1024, 1024, 0, 0, 600, 600, [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0xFF00FF00),
       (cur_tableau_set_ambient_light, 10,11,15),
       (set_fixed_point_multiplier, 100),
       (cur_tableau_set_camera_parameters, 0, 40, 40, 0, 100000),
   
       (init_position, pos1),
       (position_set_z, pos1, 100),
       (position_set_x, pos1, -20),
       (position_set_y, pos1, -20),
       (cur_tableau_add_tableau_mesh, "tableau_troop_profile_color_greenscreen_1", ":troop_no", pos1, 0, 0),
       (position_set_z, pos1, 200),
       (cur_tableau_add_tableau_mesh, "tableau_troop_profile_alpha_mask_greenscreen_1", ":troop_no", pos1, 0, 0),
    ]),
   
    ("greenscreen_2", 0, "tableau_with_transparency", 1024, 1024, 0, 0, 600, 600, [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0xFF00FF00),
       (cur_tableau_set_ambient_light, 10,11,15),
       (set_fixed_point_multiplier, 100),
       (cur_tableau_set_camera_parameters, 0, 40, 40, 0, 100000),
   
       (init_position, pos1),
       (position_set_z, pos1, 100),
       (position_set_x, pos1, -20),
       (position_set_y, pos1, -20),
       (cur_tableau_add_tableau_mesh, "tableau_troop_profile_color_greenscreen_2", ":troop_no", pos1, 0, 0),
       (position_set_z, pos1, 200),
       (cur_tableau_add_tableau_mesh, "tableau_troop_profile_alpha_mask_greenscreen_2", ":troop_no", pos1, 0, 0),
    ]),
   
    ("greenscreen_3", 0, "tableau_with_transparency", 1024, 1024, 0, 0, 600, 600, [
       (store_script_param, ":troop_no", 1),
       (cur_tableau_set_background_color, 0xFF00FF00),
       (cur_tableau_set_ambient_light, 10,11,15),
       (set_fixed_point_multiplier, 100),
       (cur_tableau_set_camera_parameters, 0, 40, 40, 0, 100000),
   
       (init_position, pos1),
       (position_set_z, pos1, 100),
       (position_set_x, pos1, -20),
       (position_set_y, pos1, -20),
       (cur_tableau_add_tableau_mesh, "tableau_troop_profile_color_greenscreen_3", ":troop_no", pos1, 0, 0),
       (position_set_z, pos1, 200),
       (cur_tableau_add_tableau_mesh, "tableau_troop_profile_alpha_mask_greenscreen_3", ":troop_no", pos1, 0, 0),
    ]),

The scripts below referencing external snippets feature Native-only stuff, such as a troop and an animation. They took lots of tweaks and recompilations to get them done (adjusted and aligned perfectly).

Python:
("add_player_to_cur_tableau_for_greenscreen_3", [
    #(store_script_param, ":troop_no", 1),
    #(store_script_param, ":canvas_no", 2),
    (cur_tableau_set_override_flags, af_override_everything),
   
    (multiplayer_get_my_player, ":my_player_no"),
   
    (assign, ":canvas_no", "trp_coop_companion_equipment_ui_0"),
   
    (player_get_agent_id, ":my_agent_no", ":my_player_no"),
    (ge, ":my_agent_no", 0),
   
    (try_for_range, ":cur_inv_slot", 0, 8),
      (agent_get_item_slot, ":cur_item", ":my_agent_no", ":cur_inv_slot"),
      (ge, ":cur_item", 0),
      (cur_tableau_add_override_item, ":cur_item"),
    (try_end),
   
   
    (try_begin),
      (player_get_gender , ":is_female", ":my_player_no"),
      (eq, ":is_female", 1),
      (val_add, ":canvas_no", 1),
    (try_end),
   
    (str_store_player_face_keys, s0, ":my_player_no"),
    (troop_set_face_keys, ":canvas_no", s0),
   
    (assign, ":animation", "anim_pose_3"), #anim_pose_2 is hands on hips, 3 is crossed hands on elbows, 4 is hands on hips but more relaxed

    (set_fixed_point_multiplier, 100),
    (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
    (assign, ":cam_height", 125),
    (assign, ":camera_distance", 300),
    (assign, ":camera_pitch", -3), #camera_pitch lifts the camera up/down around the agent's sphere

    (init_position, pos5),
    (position_set_z, pos5, ":cam_height"),
    # camera looks towards -z axis
    (position_rotate_x, pos5, -90),
    (position_rotate_z, pos5, 180),
    # now apply yaw and pitch
    (assign, ":camera_yaw", -5), #camera_yaw rotates the agent
    (position_move_x, pos5, 20, 0), ##moves the camera horizontally left/right
    (position_rotate_y, pos5, ":camera_yaw"),
    (position_rotate_x, pos5, ":camera_pitch"),
    (position_move_z, pos5, ":camera_distance", 0),
    (position_move_y, pos5, 70, 0), #moves the camera vertically up/down
     

    (init_position, pos2),
    (cur_tableau_add_troop, ":canvas_no", pos2, ":animation", 0),
    (cur_tableau_set_camera_position, pos5),

    (copy_position, pos8, pos5),
    (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
    (position_rotate_z, pos8, 30),
    (position_rotate_x, pos8, -50),
    (cur_tableau_add_sun_light, pos8, 175,150,125),
    ]),
   
    ("add_player_to_cur_tableau_for_greenscreen_2", [
    #(store_script_param, ":troop_no", 1),
    #(store_script_param, ":canvas_no", 2),
    (cur_tableau_set_override_flags, af_override_everything),
   
    (multiplayer_get_my_player, ":my_player_no"),
   
    (assign, ":canvas_no", "trp_coop_companion_equipment_ui_0"),
   
    (player_get_agent_id, ":my_agent_no", ":my_player_no"),
    (ge, ":my_agent_no", 0),
   
    (try_for_range, ":cur_inv_slot", 0, 8),
      (agent_get_item_slot, ":cur_item", ":my_agent_no", ":cur_inv_slot"),
      (ge, ":cur_item", 0),
      (cur_tableau_add_override_item, ":cur_item"),
    (try_end),
   
   
    (try_begin),
      (player_get_gender , ":is_female", ":my_player_no"),
      (eq, ":is_female", 1),
      (val_add, ":canvas_no", 1),
    (try_end),
   
    (str_store_player_face_keys, s0, ":my_player_no"),
    (troop_set_face_keys, ":canvas_no", s0),
   
    (assign, ":animation", "anim_pose_4"), #anim_pose_2 is hands on hips, 3 is crossed hands on elbows, 4 is hands on hips but more relaxed

    (set_fixed_point_multiplier, 100),
    (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
    (assign, ":cam_height", 105),
    (assign, ":camera_distance", 150),
    (assign, ":camera_pitch", 4),

    (init_position, pos5),
    (position_set_z, pos5, ":cam_height"),
    # camera looks towards -z axis
    (position_rotate_x, pos5, -90),
    (position_rotate_z, pos5, 180),
    # now apply yaw and pitch
    (assign, ":camera_yaw", -5),
    (position_move_x, pos5, 20, 0),
    (position_rotate_y, pos5, ":camera_yaw"),
    (position_rotate_x, pos5, ":camera_pitch"),
    (position_move_z, pos5, ":camera_distance", 0),
    (position_move_y, pos5, 70, 0),
     

    (init_position, pos2),
    (cur_tableau_add_troop, ":canvas_no", pos2, ":animation", 0),
    (cur_tableau_set_camera_position, pos5),

    (copy_position, pos8, pos5),
    (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
    (position_rotate_z, pos8, 30),
    (position_rotate_x, pos8, -50),
    (cur_tableau_add_sun_light, pos8, 175,150,125),
    ]),
   
    ("add_player_to_cur_tableau_for_greenscreen_1", [
    #(store_script_param, ":troop_no", 1),
    #(store_script_param, ":canvas_no", 2),
    (cur_tableau_set_override_flags, af_override_everything),
   
    (multiplayer_get_my_player, ":my_player_no"),
   
    (assign, ":canvas_no", "trp_coop_companion_equipment_ui_0"),
   
    (player_get_agent_id, ":my_agent_no", ":my_player_no"),
    (ge, ":my_agent_no", 0),
   
    (try_for_range, ":cur_inv_slot", 0, 8),
      (agent_get_item_slot, ":cur_item", ":my_agent_no", ":cur_inv_slot"),
      (ge, ":cur_item", 0),
      (cur_tableau_add_override_item, ":cur_item"),
    (try_end),
   
   
    (try_begin),
      (player_get_gender , ":is_female", ":my_player_no"),
      (eq, ":is_female", 1),
      (val_add, ":canvas_no", 1),
    (try_end),
   
    (str_store_player_face_keys, s0, ":my_player_no"),
    (troop_set_face_keys, ":canvas_no", s0),
   
    (assign, ":animation", "anim_pose_2"), #anim_pose_2 is hands on hips, 3 is crossed hands on elbows, 4 is hands on hips but more relaxed

    (set_fixed_point_multiplier, 100),
    (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
    (assign, ":cam_height", 115),
    (assign, ":camera_distance", 600),
    (assign, ":camera_pitch", -3),

    (init_position, pos5),
    (position_set_z, pos5, ":cam_height"),
    # camera looks towards -z axis
    (position_rotate_x, pos5, -90),
    (position_rotate_z, pos5, 180),
    # now apply yaw and pitch
    (assign, ":camera_yaw", -5),
    (position_move_x, pos5, -10, 0),
    (position_rotate_y, pos5, ":camera_yaw"),
    (position_rotate_x, pos5, ":camera_pitch"),
    (position_move_z, pos5, ":camera_distance", 0),
    (position_move_y, pos5, 70, 0),
     

    (init_position, pos2),
    (cur_tableau_add_troop, ":canvas_no", pos2, ":animation", 0),
    (cur_tableau_set_camera_position, pos5),

    (copy_position, pos8, pos5),
    (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
    (position_rotate_z, pos8, 30),
    (position_rotate_x, pos8, -50),
    (cur_tableau_add_sun_light, pos8, 175,150,125),
    ]),
 
Top Bottom