OSP Code QoL Modified Custom 3rd Person Camera for WB

Users who are viewing this thread

Hi all,

I'd like to share this modified Custom Camera code that I implemented in TLD, originally by dunde within the Script Exchange Thread. I've modified it to add another preset (inspired by La Grandmaster's Camera Presets in The Reckoning.)

I've also added the ability to 'switch shoulders' during the Fixed-Camera preset, just for more flexibility.

Summary of what it does:
  • 1st Preset - Fixed 3rd Person, Over the Shoulder Camera. I've added code where if you press left/right arrow keys, it switches shoulders
    • Press END to activate Fixed Camera
           
    • Press left/right arrow keys to switch shoulders

  • 2nd Preset - Custom 3rd Person Camera that can be zoomed in/out, tilted up/down
    • Keys can be modified
    • Press END from Fixed-Camera to activate Custom Camera
    • Press and hold +/- to Zoom In/Out
    • Press and hold up/down arrow keys to tilt up/down
    • Press and hold SHIFT when zooming / tilting the camera to enable smoothing
    • When using a bow / thrown weapon, the camera will snap into 'default' camera for ease of use. Once projectile is fired, it will snap back to Custom Camera


Screenshots:

Custom Camera
tiNpY.jpg
-dKbg.jpg
B3K9O.jpg


Fixed Camera
4EBNR.jpg
fcu0Z.jpg
-E6Xw.jpg
bjSWI.jpg
f92w0.jpg
GdZjK.jpg
_g4CC.jpg
KavwX.jpg

Code:

Code:
camera_init =  (0,0,ti_once,[(get_player_agent_no, "$cam_current_agent"), (gt, "$cam_current_agent", -1)],
                           [(assign,"$cam_mode", 0),(assign, "$shoot_mode",0), (assign, "$cam_free", 0)])

camera_mode =  ( 0, 0, 0, [], 
 [(try_begin),
     (eq, "$cam_mode", 1), ## Custom Camera
     (set_fixed_point_multiplier, 100),
     (agent_get_look_position, pos7, "$cam_current_agent"),
     (position_get_rotation_around_x, ":angle", pos7), 
     (store_sub, ":reverse", 0, ":angle"),
     (position_rotate_x, pos7, ":reverse"),
     (position_move_y, pos7, "$g_camera_y"),
     (position_move_z, pos7, "$g_camera_z"),
     (agent_get_horse, ":horse_agent", "$cam_current_agent"),
     (try_begin),
        (ge, ":horse_agent", 0),
        (position_move_z, pos7, 80),        
     (try_end),
     (store_mul, ":reverse", -1, "$g_camera_y"),
     (store_atan2, ":drop", "$g_camera_z", ":reverse"),
     (convert_from_fixed_point, ":drop"),
     (val_sub, ":angle", ":drop"),
     (position_rotate_x, pos7, ":angle"),
     (mission_cam_animate_to_position, pos7, 100, 0), 
 (else_try),
      (eq, "$cam_mode", 2), ## Fixed Camera
      (try_begin),
        (eq,"$cam_shoulder",0),   ## Shoulder
          (set_fixed_point_multiplier, 100),                         
          (agent_get_look_position, pos7, "$cam_current_agent"),
          (position_move_z, pos7,  180),
          (position_move_y, pos7, -190),
          (position_move_x, pos7, 70),
          (agent_get_horse, ":horse_agent", "$cam_current_agent"),
          (try_begin),
              (ge, ":horse_agent", 0),
              (position_move_z, pos7, 80),
          (try_end),
         (mission_cam_animate_to_position, pos7, 100),   
      (else_try),
        (eq,"$cam_shoulder",1),  ## Shoulder
          (set_fixed_point_multiplier, 100),                         
          (agent_get_look_position, pos7, "$cam_current_agent"),
          (position_move_z, pos7,  180),
          (position_move_y, pos7, -190),
          (position_move_x, pos7, -70),
          (agent_get_horse, ":horse_agent", "$cam_current_agent"),
          (try_begin),
              (ge, ":horse_agent", 0),
              (position_move_z, pos7, 80),
          (try_end),
         (mission_cam_animate_to_position, pos7, 100),   
      (try_end),
  (else_try),
     (lt, "$cam_mode", 3),
     (main_hero_fallen),
     (agent_get_position, 1, "$cam_current_agent"),     
     (get_player_agent_no, ":player_agent"),
     (agent_set_position, ":player_agent", 1),
  (try_end),])


camera_set      = ( 0, 0, 0,[(key_clicked, "$key_camera_toggle"), (lt, "$cam_mode", 3),(neq, "$shoot_mode", 1)],
# toggling only when came mode =0, 1, 2 (3=disable) ; shoot_mode=1 temporary diable toggling
 [(try_begin),
     (eq, "$cam_mode", 0), 
     (assign, "$cam_mode", 2),
     (display_message, "@Fixed Custom Camera"),
     (display_message, "@Press Left / Right Arrow Keys to Switch Shoulders"),
  (else_try), 
     (eq, "$cam_mode", 2),
     (assign, "$cam_mode", 1),
     (display_message, "@Free-Mode Custom Camera"),
     (display_message, "@Use +/- to zoom in/out"),
     (display_message, "@Use Up/Down arrow keys to tilt up/down"),
  (else_try),
    (eq, "$cam_mode", 1), ## Commented Out Agent Switching when Player dies.
    # (try_begin),
    #    (neg|main_hero_fallen, 0),
    #    (get_player_agent_no, "$cam_current_agent"),                  
    # (try_end), 
     (assign, "$cam_mode", 0),
     (display_message, "@Default Camera"),
  (try_end),
  (mission_cam_set_mode, "$cam_mode"),])


camera_zoom_in         = ( 0, 0, 0,[(key_is_down, "$key_camera_zoom_plus"),  (eq, "$cam_mode", 1)], [(val_add, "$g_camera_y",1),(neg|key_is_down, key_left_shift),(val_add, "$g_camera_y",9),(val_min,"$g_camera_y",-50),])
camera_zoom_out        = ( 0, 0, 0,[(key_is_down, "$key_camera_zoom_min"),   (eq, "$cam_mode", 1)], [(val_sub, "$g_camera_y",1),(neg|key_is_down, key_left_shift),(val_sub, "$g_camera_y",9),])
camera_raise           = ( 0, 0, 0,[(key_is_down, "$key_camera_height_plus"),(eq, "$cam_mode", 1)], [(val_add, "$g_camera_z",1),(neg|key_is_down, key_left_shift),(val_add, "$g_camera_z",9),])
camera_lower           = ( 0, 0, 0,[(key_is_down, "$key_camera_height_min"), (eq, "$cam_mode", 1)], [(val_sub, "$g_camera_z",1),(neg|key_is_down, key_left_shift),(val_sub, "$g_camera_z",9),(val_max,"$g_camera_z", 50),])
camera_cycle_fowards   = ( 0, 0, 0,[(key_clicked, "$key_camera_next"),(try_begin),(eq, "$cam_mode", 3),(call_script, "script_dmod_cycle_forwards"), (else_try), (eq,"$cam_mode",2),(assign, "$cam_shoulder",0), (display_message, "@Fixed Camera - Right Shoulder"),(try_end),], [])
camera_cycle_backwards = ( 0, 0, 0,[(key_clicked, "$key_camera_prev"),(try_begin),(eq, "$cam_mode", 3),(call_script, "script_dmod_cycle_backwards"),(else_try), (eq,"$cam_mode",2),(assign, "$cam_shoulder",1), (display_message, "@Fixed Camera - Left Shoulder"),(try_end),], [])

camera_shot   = ( 0, 0, 0,[(key_is_down, key_left_mouse_button), (eq, "$cam_mode", 1)], [(get_player_agent_no, ":player_agent"), (eq, ":player_agent","$cam_current_agent"),(agent_get_wielded_item,":weapon","$cam_current_agent",0), (neq,":weapon",-1),(item_get_type, ":type", ":weapon"), (this_or_next|eq,":type",itp_type_bow),(this_or_next|eq,":type",itp_type_crossbow),(eq,":type",itp_type_thrown),(assign, "$cam_mode", 0),(assign,"$shoot_mode",1),(mission_cam_set_mode, "$cam_mode")])
camera_normal = ( 0, 0, 0,[(neg|key_is_down, key_left_mouse_button), (eq, "$shoot_mode",1)], [(assign, "$cam_mode", 1),(assign,"$shoot_mode",0),(mission_cam_set_mode, "$cam_mode")])          
              
###############CUSTOM CAMERA END ################################

Usage:
Code:
      camera_init,
      camera_mode,
      camera_raise,
      camera_lower,
      camera_zoom_out,
      camera_zoom_in,
      camera_set,
      camera_cycle_fowards,
      camera_cycle_backwards,
      camera_shot, camera_normal,

Code:
 #### Custom Camera Scripts by dunde, modified to add Shoulder Switching global (Kham)
("init_camera",
 [(assign, "$key_camera_toggle",key_end),                #END button to toggle camera mode
  (assign, "$key_camera_next",key_right),                #right key to jump to next bot
  (assign, "$key_camera_prev",key_left),                 #left key to jump to prev bot
  (assign, "$key_camera_zoom_plus",key_numpad_plus),     #Num + to zoom in
  (assign, "$key_camera_zoom_min",key_numpad_minus),     #Num - to zoom out
  (assign, "$key_camera_height_plus",key_up),
  (assign, "$key_camera_height_min",key_down),
  (assign, "$cam_free", 0),
  (assign, "$g_camera_z", 300),       
  (assign, "$g_camera_y", -1000),
  (assign, "$cam_shoulder", 0),
 ]),

Code:
# Modified MartinF's code for DeathCam 
# script_dmod_cycle_forwards
# Output: New $dmod_current_agent
# Used to cycle forwards through valid agents
("dmod_cycle_forwards",
 [(assign, ":agent_moved", 0),
  (assign, ":first_agent", -1),
  (get_player_agent_no, ":player_agent"),
  (agent_get_team, ":player_team", ":player_agent"),
  (agent_get_team, ":prev_team", "$cam_current_agent"),
  (try_for_agents, ":agent_no"),
     (neq, ":agent_moved", 1),
     (agent_is_human, ":agent_no"),
     (agent_is_alive, ":agent_no"),
     (agent_get_team, ":cur_team", ":agent_no"),
     (agent_get_troop_id, ":troop_id", ":agent_no"), 
     (this_or_next|troop_is_hero, ":troop_id"), 
     (neg|key_is_down, key_left_shift),
     (this_or_next|eq, ":cur_team", ":prev_team"),
     (neg|key_is_down, key_left_control),
     (this_or_next|neq, ":cur_team", ":prev_team"), 
     (neg|key_is_down, key_left_alt),             
     (this_or_next|eq, "$cam_free", 1),         
     (eq, ":cur_team", ":player_team"),
     (try_begin),
        (lt, ":first_agent", 0),                         # Find the 1st agent alive and (1 team or free mod)
        (assign, ":first_agent", ":agent_no"),
     (try_end),
     (gt, ":agent_no", "$cam_current_agent"),            # Find next agent  alive and (1 team or free mod)
     (assign, "$cam_current_agent", ":agent_no"),
     (assign, ":agent_moved", 1),
  (try_end),
  (try_begin),
     (eq, ":agent_moved", 0),                            # Next Agent not found, but 1st agent found, then the next is the first one
     (neq, ":first_agent", -1),
     (assign, "$cam_current_agent", ":first_agent"),
     (assign, ":agent_moved", 1),        
  (else_try),
     (eq, ":agent_moved", 0),
     (eq, ":first_agent", -1),
     (display_message, "@No Troops Left."),
  (try_end),
  (try_begin),
     (eq, ":agent_moved", 1),                            # there is next one
     (try_begin),
        (agent_is_alive, ":player_agent"),             # if player is still alive, push to mode 1
        (assign, "$cam_mode", 1),
        (mission_cam_set_mode, "$cam_mode"),
     (try_end),
     (str_store_agent_name, 1, "$cam_current_agent"),
  (try_end),]),
   
# script_dmod_cycle_backwards
# Output: New $dmod_current_agent
# Used to cycle backwards through valid agents
("dmod_cycle_backwards",
 [(assign, ":new_agent", -1),
  (assign, ":last_agent", -1),
  (get_player_agent_no, ":player_agent"),
  (agent_get_team, ":player_team", ":player_agent"),
  (agent_get_team, ":prev_team", "$cam_current_agent"),      
  (try_for_agents, ":agent_no"),
     (agent_is_human, ":agent_no"),
     (agent_is_alive, ":agent_no"),
     (agent_get_team, ":cur_team", ":agent_no"),
     (agent_get_troop_id, ":troop_id", ":agent_no"), 
     (this_or_next|troop_is_hero, ":troop_id"), 
     (neg|key_is_down, key_left_shift),
     (this_or_next|eq, ":cur_team", ":prev_team"),
     (neg|key_is_down, key_left_control),
     (this_or_next|neq, ":cur_team", ":prev_team"),
     (neg|key_is_down, key_left_alt),
     (this_or_next|eq, "$cam_free", 1),    
     (eq, ":cur_team", ":player_team"),
     (assign, ":last_agent", ":agent_no"),          # Ok, the last
     (lt, ":agent_no", "$cam_current_agent"),
     (assign, ":new_agent", ":agent_no"),           # prev agent    
  (try_end),
  (try_begin),
     (eq, ":new_agent", -1),
     (neq, ":last_agent", -1),
     (assign, ":new_agent", ":last_agent"),               
  (else_try),
     (eq, ":new_agent", -1),
     (eq, ":last_agent", -1),
     (display_message, "@No Troops Left."),
  (try_end),
  (try_begin),
     (neq, ":new_agent", -1),                       # There is prev agent
     (assign, "$cam_current_agent", ":new_agent"), 
     (try_begin),
        (agent_is_alive, ":player_agent"),
        (assign, "$cam_mode", 1),
        (mission_cam_set_mode, "$cam_mode"),
     (try_end),
     (str_store_agent_name, 1, "$cam_current_agent"),
  (try_end), ]),

Note that I've commented the ability to have the agent switching during death cam as I did not want it for TLD. Please make your own modifications to allow it back again.

Credit goes to:
dunde
rubik
Martin F
La Grandmaster


 
hi there about the camera as you said i have added your code but it said camera_init unexpected indent how can i fix dat error :???:
you should copy other module system codes line by line understanding what you are copying. module system syntax changes a lot between modules.
 
Back
Top Bottom