OSP Kit Optimisation Simplified KeyConfig Presentation

Users who are viewing this thread

If you have implemented some features that need usage of buttons like custom camera, various formation and tactics codes, shield bashing, iwill be better if platyer can customize the buttons configuration. That's the code about.
I made it simplified so it will be ready to use with minimum extra coding. And there's no need for aditional trigger at mission templates either.
All we need is just copy the code to the relevant files, and adding some constants and strings according to our mod need.
It can support up to 30 keys. If there're more than 20 keys, then the buttons arranged by 3 columns, otherwise there will be 2 columns.
Code:
#-- Dunde's Key Config BEGIN

# Slots Initilizations (Key Defs & Default Values) 
def set_key_config():
   key_config = []
   for i in xrange(len(keys_list)):
      key_config.append((troop_set_slot, key_config_data, slot_default_keys_begin+i, keys_list[i][1]))      
   for i in xrange(len(all_keys_list)):
      key_config.append((troop_set_slot, key_config_data, slot_key_defs_begin+i, all_keys_list[i][0]))
   return key_config[:]   

# Global Variables -> Slots   
def read_key_config():
   global_key = []
   for i in xrange(len(keys_list)):
      global_key.append((troop_set_slot, key_config_data, slot_keys_begin+i, keys_list[i][0]))      
   return global_key[:]   
   
# Slots -> Global Variables   
def write_key_config():
   global_key = []
   for i in xrange(len(keys_list)):
      global_key.append((troop_get_slot, keys_list[i][0], key_config_data, slot_keys_begin+i))      
   return global_key[:]   
   
#-- Dunde's Key Config END
Code:
#-- Dunde's Key Config BEGIN

  ("update_key_config_buttons",
   [(try_for_range, ":no_key", slot_keys_begin, slot_keys_begin+number_of_keys),
       #(store_add, ":off", ":no_key", number_of_keys),
       (store_add, ":off_overlay",  ":no_key", number_of_keys),
       (troop_get_slot, ":ovr", key_config_data, ":off_overlay"), 
       (troop_get_slot, ":key", key_config_data, ":no_key"),
       (assign, ":found", 0), (assign, ":upper_limit", number_of_all_keys),
       (try_for_range, ":no", 0, ":upper_limit"),
          (store_add, ":off_all_keys", ":no", slot_key_defs_begin),
          (troop_slot_eq, key_config_data,  ":off_all_keys", ":key"),
          (store_add, ":off_strings", ":no", key_label_begin),          
          (overlay_set_text, ":ovr", ":off_strings", 0),
          (overlay_set_color, ":ovr", 0x0),
          (assign, ":found", ":no"),
          (assign, ":upper_limit", ":no"),
       (try_end),
       (try_begin),
          (neq, ":found", 0),
       (else_try),
          (eq, ":key", 0xff),
          (overlay_set_text, ":ovr", "@Disabled"),
          (overlay_set_color, ":ovr", 0x800000),
       (else_try),
          (overlay_set_text, ":ovr", "@Undefined!"),
          (overlay_set_color, ":ovr", 0xFF0000),       
       (try_end),          
    (try_end), ]),
   
("init_key_config", set_key_config()),              # Slots Initilizations (Key Defs & Default Values) 
("set_config_slot_key_config", read_key_config()),  # Global Variables -> Slots
("set_global_var_key_config", write_key_config()),  # Slots            -> Global Variables

("reset_to_default_keys",                           # Default Slots    -> Working Slots
 [(try_for_range, ":no", 0, number_of_keys),
      (store_add, ":off", ":no", slot_default_keys_begin),
      (troop_get_slot, ":key", key_config_data, ":off"),
      (val_add, ":off", number_of_keys),
      (troop_set_slot, key_config_data, ":off", ":key"),
  (try_end), ]),
  
("init_all_keys",
 [(call_script, "script_init_key_config"),
  (call_script, "script_reset_to_default_keys"),
  (call_script, "script_set_global_var_key_config"), ]),
 
#-- Dunde's Key Config END
Code:
   (call_script, "script_init_all_keys"),
Code:
# Key configuration
("key_config", 0, mesh_load_window, 
 [(ti_on_presentation_load, 
  [(presentation_set_duration, 999999),
   (set_fixed_point_multiplier, 1000),
   (assign, "$key_config_button_down", 0), 
   (init_position, pos1),     
   # Tittle
   (position_set_y, pos1, 650),  (position_set_x, pos1, 500),  # Tittle Position
   (position_set_x, pos2, 2000), (position_set_y, pos2, 2000), # Tittle Size
   (create_text_overlay, reg0, "str_keyconfig", tf_center_justify), (overlay_set_color, reg0, 0x000000),
   (overlay_set_position, reg0, pos1), (overlay_set_size, reg0, pos2),
   (position_set_y, pos1, 649),  (position_set_x, pos1, 499),  # Tittle Position
   (create_text_overlay, reg0, "str_keyconfig", tf_center_justify), (overlay_set_color, reg0, 0xFF0000),
   (overlay_set_position, reg0, pos1), (overlay_set_size, reg0, pos2),
   # Notes 
   (position_set_y, pos1, 25), (position_set_x, pos1, 50),   # Notes' Position
   (position_set_x, pos2, 750), (position_set_y, pos2, 750), # Note's Size
   (create_text_overlay,  "$g_presentation_obj_2", "str_keyesc", tf_left_align),
   (overlay_set_position, "$g_presentation_obj_2", pos1), (overlay_set_size, "$g_presentation_obj_2", pos2),
   (overlay_set_color, "$g_presentation_obj_2", 0x678000),  # Note's Color  
   (overlay_set_alpha, "$g_presentation_obj_2", 0x00),      # Note's invisible  
   (position_set_y, pos1, 600),                             # First KeyConfig's Label Position
   (try_begin),
      (le, number_of_keys, two_columns_limit),                 # KeyConfig's Labels Size
      (position_set_x, pos2, 1000), (position_set_y, pos2, 1000), 
      (position_set_x, pos1, 50),
   (else_try),
      (position_set_x, pos2, 750), (position_set_y, pos2, 750),   
      (position_set_x, pos1, 25),
   (try_end),     
   (position_set_x, pos3, 120),  (position_set_y, pos3, 28),   # KeyConfig's Buttons Size     
   (try_for_range, ":no", 0, number_of_keys),
      (store_add, ":off_string", ":no", key_names_begin),             # Offset for Label String
      (store_add, ":off_overlay2", ":no", slot_key_overlay_begin),    # Offset for Buttons Overlay
      (store_add, ":off_overlay1", ":off_overlay2", number_of_keys),  # Offset for Labels Overlay
      (create_text_overlay, reg0, ":off_string", tf_left_align),              # Creating,
      (troop_set_slot, key_config_data, ":off_overlay1", reg0),               # Saving,
      (overlay_set_position, reg0, pos1), (overlay_set_size, reg0, pos2),     # Positioning, and Resizing KeyConfig Labels
      (try_begin),
         (le, number_of_keys, two_columns_limit),
         (position_move_x, pos1, 35),                                         # Move Right to give spave between labels and buttons
      (else_try),
         (position_move_x, pos1, 24), 
      (try_end),   
      (create_game_button_overlay, reg0, "str_no_string", tf_center_justify), # Creating,
      (troop_set_slot, key_config_data, ":off_overlay2", reg0),               # Saving,
      (overlay_set_position, reg0, pos1), (overlay_set_size, reg0, pos3),     # Positioning, and Resizing KeyConfig Buttons
      (try_begin),
         (le, number_of_keys, two_columns_limit),
         (position_move_x, pos1, -35),                                        # Move Left
      (else_try),
         (position_move_x, pos1, -24), 
      (try_end),   
      (position_move_y, pos1, -4),              # Move left, and move down for next keyconfig's label and button
      (try_begin),          
          (le, number_of_keys, two_columns_limit), 
		  (store_mod, ":off_string", number_of_keys, 2),
          (try_begin),
             (eq, ":no", number_of_keys/2),                                   # Half of keyconfigs positions are moved up and right
			 (eq, ":off_string", 1),
             (assign, ":move_y", number_of_keys/2+1), (val_mul, ":move_y", 4),
             (position_move_y, pos1, ":move_y"),
             (position_move_x, pos1, 50),
		  (else_try),
             (eq, ":no", number_of_keys/2 - 1),                               # Half of keyconfigs positions are moved up and right
			 (eq, ":off_string", 0),
             (assign, ":move_y", number_of_keys/2), (val_mul, ":move_y", 4),
             (position_move_y, pos1, ":move_y"),
             (position_move_x, pos1, 50),		  
          (try_end),
      (else_try),          
	      (store_mod, ":off_string", number_of_keys, 3),
		  (try_begin),
		     (eq,  ":off_string", 0),
             (try_begin),
                (eq, ":no", number_of_keys/3 - 1),                            # 2nd 1/3 part of keyconfigs positions are moved up and right
                (assign, ":move_y", number_of_keys/3), (val_mul, ":move_y", 4),
                (position_move_y, pos1, ":move_y"),
                (position_move_x, pos1, 33),
		     (else_try),
                (eq, ":no", number_of_keys/3 + number_of_keys/3 - 1),         # 3nd 2/3 part of keyconfigs positions are moved up and right
                (assign, ":move_y", number_of_keys/3), (val_mul, ":move_y", 4),
                (position_move_y, pos1, ":move_y"),
                (position_move_x, pos1, 33),
             (try_end),
          (else_try),
		     (eq,  ":off_string", 1),
             (try_begin),
                (eq, ":no", number_of_keys/3),                                # 2nd 1/3 part of keyconfigs positions are moved up and right
                (assign, ":move_y", number_of_keys/3+1), (val_mul, ":move_y", 4),
                (position_move_y, pos1, ":move_y"),
                (position_move_x, pos1, 33),
		     (else_try),
                (eq, ":no", number_of_keys/3 + number_of_keys/3),             # 3nd 2/3 part of keyconfigs positions are moved up and right
                (assign, ":move_y", number_of_keys/3), (val_mul, ":move_y", 4),
                (position_move_y, pos1, ":move_y"),
                (position_move_x, pos1, 33),
             (try_end),
          (else_try),
		     (eq,  ":off_string", 2),
             (try_begin),
                (eq, ":no", number_of_keys/3)   ,                            # 2nd 1/3 part of keyconfigs positions are moved up and right
                (assign, ":move_y", number_of_keys/3+1), (val_mul, ":move_y", 4),
                (position_move_y, pos1, ":move_y"),
                (position_move_x, pos1, 33),
		     (else_try),
                (eq, ":no", number_of_keys/3 + number_of_keys/3 + 1),         # 3nd 2/3 part of keyconfigs positions are moved up and right
                (assign, ":move_y", number_of_keys/3+1), (val_mul, ":move_y", 4),
                (position_move_y, pos1, ":move_y"),
                (position_move_x, pos1, 33),
             (try_end),		  
          (try_end),
      (try_end),  
   (try_end),
   (call_script, "script_set_config_slot_key_config"),                        # Get Current KeyConfig
   (call_script, "script_update_key_config_buttons"),                         # Writting the  Captions
   # Other Buttons
   (create_game_button_overlay, "$g_presentation_obj_3", "str_ok", tf_center_justify),          # OK Button
   (create_game_button_overlay, "$g_presentation_obj_4", "str_reset", tf_center_justify),       # RESET Button
   (create_game_button_overlay, "$g_presentation_obj_5", "str_default", tf_center_justify),     # DEFAULT Button
   (create_game_button_overlay, "$g_presentation_obj_6", "str_disable_all", tf_center_justify), # DISABLE ALL Button  
   # Rearrange Buttons
   (position_set_y, pos1, 25),  
   (position_set_x, pos1, 900),         (overlay_set_position, "$g_presentation_obj_3",  pos1),
   (position_set_x, pos1, 900 - 1*160), (overlay_set_position, "$g_presentation_obj_4",  pos1),
   (position_set_x, pos1, 900 - 2*160), (overlay_set_position, "$g_presentation_obj_5",  pos1),
   (position_set_x, pos1, 900 - 3*160), (overlay_set_position, "$g_presentation_obj_6",  pos1), ]),
 (ti_on_presentation_event_state_change, 
  [(store_trigger_param_1, ":object"),
   (assign, ":found", 0),
   (store_add, ":upper_limit", slot_key_overlay_begin, number_of_keys),    #  Checking
   (try_for_range, ":slot", slot_key_overlay_begin, ":upper_limit"),       # for all KeyConfigs Button Overlay
      (troop_slot_eq, key_config_data, ":slot", ":object"),                # Found the Right Button Overlay?
      (assign, "$key_config_button_down", 1),                              # Flag the event
      (assign, "$ovr_no", ":object"),                                      # Get The Overlay 
      (overlay_set_text, "$ovr_no", "str_press_any", tf_center_justify),    # Change it's caption & color
      (overlay_set_color, "$ovr_no", 0x0000FF),
      (overlay_set_hilight_color, "$ovr_no", 0x0000FF),
      (store_sub, "$key_no", ":slot",  number_of_keys),
      (assign, ":found", ":slot"), (assign, ":upper_limit", ":slot"),      # Break the Loops
   (try_end),     
   (try_begin),
      (gt, ":found", 0),                                                  # Skip, the Object is a keyconfig button 
   (else_try),    
     (eq, ":object", "$g_presentation_obj_3"),                            # OK pressed?
     (call_script, "script_set_global_var_key_config"),                   # Write the Config to Global Variable
     (call_script, "script_update_key_config_buttons"),                   # it's not neccessary, just incase
     (presentation_set_duration, 0),
     (change_screen_return),
   (else_try),    
     (eq, ":object", "$g_presentation_obj_4"),                            # RESET pressed? 
     (call_script, "script_set_config_slot_key_config"),                  # Reload Current Config
     (call_script, "script_update_key_config_buttons"),                   # Update Captions
   (else_try),
     (eq, ":object", "$g_presentation_obj_5"),                            # DEFAULT pressed?
     (call_script, "script_reset_to_default_keys"),                       # Reload Default Config
     (call_script, "script_update_key_config_buttons"),                   # Update Captions 
   (else_try),
     (eq, ":object", "$g_presentation_obj_6"),                                    # DISABLE ALL pressed?
     (try_for_range, ":no", slot_keys_begin, slot_keys_begin + number_of_keys),           
         (troop_set_slot, key_config_data, ":no", 0xff),                          # Disable all keys
     (try_end),
     (call_script, "script_update_key_config_buttons"),                           # Update Captions 
   (try_end),
   (try_begin),
      (eq, "$key_config_button_down", 1),                                 # if a Button's waiting to set 
      (overlay_set_alpha, "$g_presentation_obj_2", 0xFF),                 # then make The Note visible
   (try_end), ]),
 (ti_on_presentation_run, 
  [(eq, "$key_config_button_down", 1),                                     # if a Button's waiting to set 
   (assign, "$key_config_button_down", 0),                                 #
   (assign, ":found", 0),
   (store_add, ":upper_limit", slot_key_defs_begin, number_of_all_keys),   # Checking
   (try_for_range, ":no", slot_key_defs_begin,  ":upper_limit"),           # for all keys
      (troop_get_slot, ":key", key_config_data, ":no"),                    # reload the key from slot
      (key_clicked, ":key"),                                               # if that key's clicked?
      (troop_set_slot, key_config_data, "$key_no", ":key"),                # Yes, then save the new config for the button
      (assign, ":found", ":key"),                                          # Flag we found it
      (assign, ":upper_limit", ":no"),                                     # Break the Loops
   (try_end),
   (try_begin),
      (gt, ":found", 0),                                                   # We Found the key
   (else_try),   
      (key_clicked, key_escape),                                           # ESC clicked?
      (troop_set_slot, key_config_data, "$key_no", 0xff),                  # Disable the button
   (else_try),
      (assign, "$key_config_button_down", 1),                              # else? do nothing. The Button's still waiting
   (try_end),
   (try_begin),
      (eq, "$key_config_button_down", 0),                                          # if there's new keyconfig for the button
      (try_for_range, ":no", slot_keys_begin, slot_keys_begin + number_of_keys),   # Check if there is another button use the same key
          (neq, ":no",  "$key_no"),
          (troop_slot_eq, key_config_data, ":no", ":found"),                       # if there is, then disable the button
          (troop_set_slot, key_config_data, ":no", 0xff),
      (try_end),                          
      (overlay_set_hilight_color, "$ovr_no", 0x00ff00),                            # Set the button color back to normal
      (overlay_set_alpha, "$g_presentation_obj_2", 0x00),                          # The Note must be dissapear again
      (call_script, "script_update_key_config_buttons"),                           # Update Captions
   (try_end), ]),  ]), 
Code:
####################################################################################################################
# Troops before this point are hardwired into the game and their order should not be changed!
####################################################################################################################
["find_item_cheat","find_item_cheat","find_item_cheat",tf_hero|tf_is_merchant,no_scene,reserved,fac_commoners,[],def_attrib,0,knows_common|knows_inventory_management_10,0],
["random_town_sequence","Random Town Sequence","Random Town Sequence",tf_hero,no_scene,reserved,fac_commoners,[],def_attrib,0,knows_common|knows_inventory_management_10,0],
["tournament_participants","Tournament Participants","Tournament Participants",tf_hero,no_scene,reserved,fac_commoners,[],def_attrib,0,knows_common|knows_inventory_management_10,0],

#####################################
# ARRAYs  
["key_config","Key Config","Key Configs",tf_hero,no_scene,reserved,fac_commoners,[],def_attrib|str_14,0,knows_common|knows_power_draw_2,0],
##################################### 
Code:
#-- Dunde's Key Config BEGIN
from header_triggers import *
#-- Parts to modify as your mod need --------------
keys_list = [("$key_crouch",          key_caps_lock, "Crouching/Standing"),
             ("$key_crouch_command", key_comma, "Command to Stand"),
             ("$key_stand_command",   key_period, "Command to Crouch"),
            ] # end of keys_list
#--------------------------------------------------
all_keys_list   = [
(key_1, "1"), (key_2, "2"), (key_3, "3"), (key_4, "4"), (key_5, "5"), (key_6, "6"), (key_7, "7"), (key_8, "8"), (key_9, "9"), (key_0, "0"), 
(key_a, "A"), (key_b, "B"), (key_c, "C"), (key_d, "D"), (key_e, "E"), (key_f, "F"), (key_g, "G"), (key_h, "H"), (key_i, "I"), (key_j, "J"),
(key_k, "K"), (key_l, "L"), (key_m, "M"), (key_n, "N"), (key_o, "O"), (key_p, "P"), (key_q, "Q"), (key_r, "R"), (key_s, "S"), (key_t, "T"), 
(key_u, "U"), (key_v, "V"), (key_w, "W"), (key_x, "X"), (key_y, "Y"), (key_z, "Z"), 
(key_numpad_0, "Numpad 0"), (key_numpad_1, "Numpad 1"), (key_numpad_2, "Numpad 2"), (key_numpad_3, "Numpad 3"), (key_numpad_4, "Numpad 4"), 
(key_numpad_5, "Numpad 5"), (key_numpad_6, "Numpad 6"), (key_numpad_7, "Numpad 7"), (key_numpad_8, "Numpad 8"), (key_numpad_9, "Numpad 9"), 
(key_num_lock, "Num Lock"), (key_numpad_slash, "Numpad DIV"), (key_numpad_multiply, "Numpad MUL"), 
(key_numpad_minus, "Numpad MIN"), (key_numpad_plus, "Numpad PLUS"), (key_numpad_enter, "Numpad ENTER"), (key_numpad_period, "Numpad DEL)"), 
(key_insert, "Insert"), (key_delete, "Delete"), (key_home, "Home"), (key_end, "End"), (key_page_up, "Page Up"), (key_page_down, "Page Down"), 
(key_up, "Up"), (key_down, "Down"), (key_left, "Left"), (key_right, "Right"),
(key_f1, "F1"), (key_f1, "F2"), (key_f3, "F3"), (key_f4, "F4"),  (key_f5, "F5"),  (key_f6, "F6"), 
(key_f7, "F7"), (key_f8, "F8"), (key_f9, "F9"), (key_f10, "F10"), (key_f11, "F11"), (key_f12, "F12"),
(key_space, "Space Bar"), (key_enter, "Enter"), (key_tab, "Tab"), (key_back_space, "Backspace"), 
(key_open_braces, "[ "), (key_close_braces, " ] "), (key_comma, " < "), (key_period, " > "), (key_slash, " ? "), (key_back_slash, "\\"), 
(key_equals, " = "), (key_minus, " -- "), (key_semicolon, "Semicolon"), (key_apostrophe, "Apostrophe"), (key_tilde, "Tilde"), (key_caps_lock, "Caps Lock"),
(key_left_shift, "Left Shift"), (key_right_shift, "Right Shift"), (key_left_control, "Left Ctrl"), (key_right_control, "Right Ctrl"), (key_left_alt, "Left Alt"), (key_right_alt, "Right Alt"),
(key_left_mouse_button, "Left Click"), (key_right_mouse_button, "Right Click"), (key_middle_mouse_button, "Middle Mouse Button"), 
(key_mouse_button_4, "Mouse Button 4"), (key_mouse_button_5, "Mouse Button 5"), (key_mouse_button_6, "Mouse Button 6"), 
(key_mouse_button_7, "Mouse Button 7"), (key_mouse_button_8, "Mouse Button 8"), (key_mouse_scroll_up, "Mouse Scroll Up"), (key_mouse_scroll_down, "Mouse Scroll Down"), ]

number_of_keys            = len(keys_list)
number_of_all_keys        = len(all_keys_list)
two_columns_limit         = 10 

slot_default_keys_begin   = 0
slot_keys_begin           = slot_default_keys_begin + number_of_keys
slot_key_overlay_begin    = slot_keys_begin         + number_of_keys
slot_key_defs_begin       = slot_key_overlay_begin  + number_of_keys + number_of_keys

key_config_data = "trp_key_config"
key_names_begin = "str_key_no1"
key_label_begin = "str_key_1"

#-- Dunde's Key Config END#-- Dunde's Key Config END
Code:
#-- Dunde's Key Config BEGIN
from module_constants import keys_list, all_keys_list

def get_key_strings():
   key_strings = []
   for i_key in xrange(len(all_keys_list)):
       key_strings.append(("key_"+str(i_key+1), all_keys_list[i_key][1]))    
   for i_key in xrange(len(keys_list)):
       key_strings.append(("key_no"+str(i_key+1), keys_list[i_key][2]))      
   return key_strings[:]  
#-- Dunde's Key Config END
Code:
("keyconfig", "Keys Configuration"),
("keyesc", "Press any key to assign to^^or Esc to disable"),
("press_any","Press a key"),
("ok", "Ok"),
("reset", "Reset"),
("default", "Default"),
("disable_all", "Disable All"),
Code:
]  + get_key_strings()

Usage :
Just call at any menu, camp menu will be fit :
Code:
   ("options_key",[],"Control Settings.", [(start_presentation, "prsnt_key_config"),]),   
Modify constants and strings marked by :
#-- Parts to modify as your mod need --------------
 
Thank you very much dunde once again. So usefull, and so many things to learn from this :smile:
 
Ikaguia said:
wouldnt it be simpler use global variables instead of slots?
No. You cannot iterate through multiple global variables.
And that would require 1 global variable for the key, another global variable for the associated text, and for the presentation another global variable for the overlay. 3 globals per key you wish to define. Or using 1 faux-troop and whatever number of slots.
 
Hmmm, please guys, copy/pasting from here to notepad makes the whole code be on only one line, and this is very unwieldy. Do you guys would have any tips about this ?

That would be great, thanks in advance.
 
dunde said:
Code:
#-- Dunde's Key Config BEGIN

#-- Parts to modify as your mod need --------------
keys_list = [("$key_camera_toggle",   0xcf),
             ("$key_camera_next",     0xc9),
             ("$key_camera_prev",     0xd1),
             ("$key_camera_zoom_in",  0x4e),
             ("$key_camera_zoom_out", 0x4a),
             ("$key_camera_up",       0xc8),
             ("$key_camera_down",     0xd0),
             ("$key_camera_right",    0xcd),
             ("$key_camera_left",     0xcb), ]
#--------------------------------------------------
             
all_keys_list   = [ 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21, 0x22, 0x23, 0x17, 0x24,
                    0x25, 0x26, 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11, 0x2d, 0x15, 0x2c, 0x52, 0x4f, 0x50, 0x51, 
                    0x4b, 0x4c, 0x4d, 0x47, 0x48, 0x49, 0x45, 0xb5, 0x37, 0x4a, 0x4e, 0x9c, 0x53, 0xd2, 0xd3, 0xc7, 0xcf, 0xc9, 0xd1, 0xc8, 
                    0xd0, 0xcb, 0xcd, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x57, 0x58, 0x39, 0x1c, 0x0f, 0x0e, 0x1a, 
                    0x1b, 0x33, 0x34, 0x35, 0x2b, 0x0d, 0x0c, 0x27, 0x28, 0x29, 0x3a, 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xe0, 0xe1, 0xe2, 
                    0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xee, 0xef, ]

number_of_keys            = len(keys_list)
number_of_all_keys        = len(all_keys_list)
two_columns_limit         = 20 

slot_default_keys_begin   = 0
slot_keys_begin           = slot_default_keys_begin + number_of_keys
slot_key_overlay_begin    = slot_keys_begin         + number_of_keys
slot_key_defs_begin       = slot_key_overlay_begin  + number_of_keys + number_of_keys

key_config_data = "trp_key_config"
key_names_begin = "str_key_no1"
key_label_begin = "str_0x02"

#-- Dunde's Key Config END
do I have to add something like this in script_game_start?
Code:
             (assign, "$key_camera_next",     0xc9),
             (assign, "$key_camera_prev",     0xd1),
             (assign, "$key_camera_zoom_in",  0x4e),
             (assign, "$key_camera_zoom_out", 0x4a),
             (assign, "$key_camera_up",       0xc8),
             (assign, "$key_camera_down",     0xd0),
             (assign, "$key_camera_right",    0xcd),
             (assign, "$key_camera_left",     0xcb),
 
oh thanks

also, how do I get the name of a key?

exmaple:
my mission template is like this:
Code:
abilities_help = (
	 0, 0, 0,[(key_clicked, key_n),(eq, "$abilities_help", 1),
	(tutorial_message, "@Combat abilities:^^J : RAGE, +5 Power strike, +5 Power throw, +5 Agility, lasts for 2xStrength sec, requires 14 Strength ^^K : FOCUS, +10xIntelligence to weapon proficiencies, +5 Agility, lasts for 2xIntelligence sec, requires 14 Intelligence ^^O : SPRINT, +7 Athletics, +15 Agility, lasts for 2xAgility seconds, requires 14 Agility ^^T : WHISTLE FOR HORSE, call a horse to come to you, more than one with higher Charisma, requires 14 Charisma ^^Y : FIRST AID, treat your immediate wounds to recover 3xFirstAid+Intelligence hitpoints, requires 14 Intelligence ^^U : BATTLECRY, rally your wounded troops to fight and recover 3xLeadership+Charisma percent of their hitpoints ^^B : WARCRY, unleash a fearsome cry to terrify weaker oppnents around you ^^G : TAUNT, attract the attention of your enemies, more with higher charisma^^All combat abilites can be used every 60 seconds in battle ^^Press H to close help."),(assign, "$abilities_help", 0),
	], []),
	(0, 0, 0,[(key_clicked, key_n),(eq, "$abilities_help", 0),
	(tutorial_message, "@ "),(assign, "$abilities_help", 1),
	], []),
	(3, 0, ti_once, [], [(assign, "$abilities_help", 1),
	(display_message,"@Press N for help",0x6495ed), 
	])
I've made all that keys customizable using this kit but I want my code to show the correct keys.

edit:
would it be something like this?
Code:
(troop_get_slot, ":key", key_config_data, "$abilities_sprint"),
(store_add, ":key_string", ":key", key_label_begin),
(str_store_string, s1, ":key_string"),
 
To make the presentation display correct name of the keys, you should modify this part of module_strings.py:
Code:
# K E Y F u n c t i o n A s s i g nme n t L a b e l 
# - - P a r t s t o mo d i f y a s y o u r mo d n e e d - - - - - - - - - - - - - -
 ( " k e y _ n o 1 " , " T o g g l e C ame r a Mo d e " ) ,
 ( " k e y _ n o 2 " , " N e x t B O T " ) ,
 ( " k e y _ n o 3 " , " P r e v B O T " ) ,
 ( " k e y _ n o 4 " , " C ame r a Z o om I n " ) ,
 ( " k e y _ n o 5 " , " C ame r a Z o om O u t " ) ,
 ( " k e y _ n o 6 " , " C ame r a T u r n U p " ) ,
 ( " k e y _ n o 7 " , " C ame r a T u r n D own " ) ,
 ( " k e y _ n o 8 " , " C ame r a T u r n R i g h t " ) ,
 ( " k e y _ n o 9 " , " C ame r a T u r n L e f t " ) ,
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
edit:
i don't know why my code above have extra space after each char. Please ignore it and refers to the starter post. i'm sorry for this, I write this post from my mobile device.
 
I did follow all instructions in the first post, but I want a script that make something like this:
if "$key_sprint" is "0x1f"(s)
input = "$key_sprint"
output = "str_0x1f"
 
T_T it doesn't work
Somebody said:
(store_add, ":string", "$key_sprint", "str_0x02"),

the key is N and it shows "Press Numpad MIN for help" instead of  "Press N for help"
when I press Numpad Min it does nothing and when I press N it does.
 
Oh, I'm sorry that I missunderstood your question. So, you want to display a message that describe what key to click to perform something.
Code:
  (assign,":upperlimit",  number_of_all_keys), (try_for_range, ":no", 0, ":upper_limit"),
      (store_add, ":off_all_keys", ":no", slot_key_defs_begin),
      (troop_slot_eq, key_config_data,  ":off_all_keys", "$key_sprint"),
      (store_add, ":off_strings", ":no", key_label_begin),          
      (assign, ":found", ":no"),
      (assign, ":upper_limit", ":no"),
   (try_end),
   (try_begin),
      (neq, ":found", 0),
      (neq, ":key", 0xff),
      (str_store_string, s0, ":off_strings"),
      (display_message, "@Press {s0} to sprint"),
   (try_end),
 
Back
Top Bottom