OSP Code Combat Crouch Stance and Walking

Users who are viewing this thread

It started long ago from discussion on Q&A. I've gave up atm, but yesterday, playing arround with animation flags for papa's pike bracing animation gave some fresh idea. Thanks to Harry for making the low side animation, I can finish this code, here :
Code:
slot_agent_crouching = 27

global variable must be initialized at game_start script:
"$key_crouch" is key used as crouch/stand toggle for player agent
"$key_crouch_command" is key to command our troops to crouch
"$key_stand_command" is key to command our troops to stand
"$g_crouch_speed_limiter". 1 means that AI agents in crouching stance will be automatically speed limited to prevent them from running.

Usage :
- put these mission template's triggers above mission_templates = [ at module_mission_templates.py
- add + crouching_triggers to trigger list  of any mission templates you want to enable crouching
- put these scripts to module_scripts.py
- Edit 3 animations and add 4 new animations at module_animations.py. You should need custom_anim.brf of the vision LE to get Harry's low side animation.
- If you have Cartread's deployed pavise models you can uncomment the #pavise_related_things

Code:
player_crouch = (0, 0, 2,
  [(neg|main_hero_fallen),(key_clicked,"$key_crouch"),
   (get_player_agent_no, ":player_agent"), (agent_get_horse, ":horse", ":player_agent"), (le, ":horse", 0),
   (try_begin),
   #pavise_related_things BEGIN
   #   (key_is_down, key_left_control),
   #   (call_script, "script_deploy_pavise", ":player_agent"),
   #(else_try),
   #pavise_related_things END
      (agent_get_slot, ":crouching", ":player_agent", slot_agent_crouching),
      (eq, ":crouching", 0),
      (agent_set_animation, ":player_agent", "anim_stand_to_crouch"),
      (agent_set_slot, ":player_agent", slot_agent_crouching, 1),
   (else_try),         
      (agent_set_animation, ":player_agent", "anim_crouch_to_stand"),
      (agent_set_slot, ":player_agent", slot_agent_crouching, 0),
   (try_end)], [])

crouching_command = (0, 0, 0, 
  [(neg|main_hero_fallen),
   (assign, ":command", -1),
   (try_begin),
     (key_clicked, "$key_crouch_command"),
     #Pavise related things BEGIN
     #(try_begin),
     #   (key_is_down, key_left_control),
     #   (assign, ":command", 2),
     #(else_try),
     #Pavise related things END
        (assign, ":command", 1),
     #Pavise related things BEGIN
     #(try_end),   
     #Pavise related things END
   (else_try),
     (key_clicked, "$key_stand_command"),   
     (assign, ":command", 0),
   (try_end),
   (ge, ":command", 0),
   (call_script, "script_crouch_command", ":command"),], [])  
   
crouching_scan = (0, 0, 0,  [(call_script, "script_crouching_scan"),], [])

crouching_triggers = [player_crouch,crouching_command,crouching_scan]

Code:
("crouch_command",
 [(get_player_agent_no, ":player_agent"),
  (agent_get_team, ":player_team", ":player_agent"),
  (store_script_param_1, ":command"),
  (try_for_agents, ":agent"),
    (neq, ":agent", ":player_agent"),
    (agent_is_alive, ":agent"),
    (agent_is_human, ":agent"),    
    (agent_get_team, ":team", ":agent"),
    (eq, ":team", ":player_team"),
    (agent_get_division, ":class", ":agent"),
    (class_is_listening_order, ":player_team", ":class"),
    (agent_get_horse, ":horse", ":agent"),
    (le, ":horse", 0),
    (call_script, "script_agent_do_crouch", ":agent", ":command"),      
 (try_end), ]),
 
("cf_agent_pushed_to_crouch", 
 [(store_script_param_1, ":agent"),
  (get_player_agent_no, ":player_agent"),
  (agent_get_slot, ":crouching", ":agent", slot_agent_crouching),
  (eq, ":crouching", 0),      
  (agent_set_animation, ":agent", "anim_stand_to_crouch"),
  (agent_set_slot, ":agent", slot_agent_crouching, 1),
  (try_begin),
     (neq, ":agent", ":player_agent"),
     (eq, "$g_crouch_speed_limiter", 1),
     (agent_set_speed_limit, ":agent", 0),
  (try_end),  ]),  
  
("team_order_class_to_crouch", 
 [(store_script_param, ":team",    1),
  (store_script_param, ":class",   2),
  (store_script_param, ":command", 3),
  (get_player_agent_no, ":player_agent"),
  (try_for_agents, ":agent"),
    (neq, ":agent", ":player_agent"),
    (agent_is_alive, ":agent"),
    (agent_is_human, ":agent"),    
    (agent_get_team, ":team_no", ":agent"),
    (eq, ":team_no", ":team"),
    (agent_get_division, ":class_no", ":agent"),
    (this_or_next|eq, ":class_no", ":class"),
    (eq, ":class", grc_everyone),
    (agent_get_horse, ":horse", ":agent"),
    (le, ":horse", 0),
    (call_script, "script_agent_do_crouch", ":agent", ":command"),
 (try_end), ]),
 
("agent_do_crouch",
 [(store_script_param_1, ":agent"), 
  (store_script_param_2, ":action"),
    (agent_get_slot, ":crouching", ":agent", slot_agent_crouching),
    (try_begin),
    #pavise_related_things BEGIN
    #   (eq, ":action", 2),
    #   (call_script, "script_deploy_pavise", ":agent"),
    #(else_try),
    #pavise_related_things END
       (eq, ":action", 0),       
       (agent_set_animation, ":agent", "anim_crouch_to_stand"),
       (agent_set_slot, ":agent", slot_agent_crouching, 0),
    (else_try),
       (eq, ":crouching", 0),      
       (agent_set_animation, ":agent", "anim_stand_to_crouch"),
       (agent_set_slot, ":agent", slot_agent_crouching, 1),
    (else_try),
       (eq, ":crouching", 1),
       (agent_get_animation, ":anim", ":agent",0),
       (neq, ":anim", "anim_stand_to_crouch"),
       (agent_set_animation, ":agent", "anim_stand_to_crouch"),         
    (try_end),   
    (try_begin),
       (eq, "$g_crouch_speed_limiter", 1),
       (try_begin),
          (eq, ":action", 0),
          (agent_set_speed_limit, ":agent", 999999),
       (else_try),
          (eq, ":action", 1),
          (agent_set_speed_limit, ":agent", 0),
       (try_end),        
    (try_end), ]),
 
("crouching_scan",
 [(try_for_agents, ":agent"),
     (agent_is_alive, ":agent"),
     (agent_is_human, ":agent"),
     (agent_get_slot, ":crouching", ":agent", slot_agent_crouching),
     (gt, ":crouching", 0),     
     (agent_get_horse, ":horse", ":agent"),
     (le, ":horse", 0),
     (assign, ":forced_to_stand", 0),
     (agent_get_wielded_item, ":weapon", ":agent", 0),
     (try_begin),
     #pavise_related_things BEGIN
     #   (assign, ":behind", 0),
     #   (try_begin),
     #      (call_script, "script_cf_is_behind_pavise", ":agent", "spr_pavise_shield1"),
     #      (assign, ":behind", 1),
     #   (else_try),
     #      (call_script, "script_cf_is_behind_pavise", ":agent", "spr_pavise_shield3"),
     #      (assign, ":behind", 1),        
     #   (try_end),   
     #   (eq, ":behind", 1),
     #   (agent_get_attack_action, ":action", ":agent"),
     #   (gt, ":action", 0),
     #   (assign, ":forced_to_stand", 1),   
     #(else_try),   
     #pavise_related_things END
        (lt, ":weapon", 0),     
     (else_try),   
        (item_get_type, ":weapon_type", ":weapon"),     
        (eq, ":weapon_type", itp_type_crossbow),
        (try_begin),
          (agent_get_attack_action, ":action", ":agent"), # Loading Crossbow always standing
          (eq, ":action", 5),
          (assign, ":forced_to_stand", 1),
        (try_end),
     (else_try),
        (eq, ":weapon", itm_long_bow),                    # Attacking with Longbow always standing
        (agent_get_attack_action, ":action", ":agent"),
        (this_or_next|eq, ":action", 1), (eq, ":action", 2),
        (assign, ":forced_to_stand", 1),        
     (try_end),
     (agent_get_speed, pos6, ":agent"),
     (set_fixed_point_multiplier, 100),
     (position_get_y,":speed",pos6), (store_mul, ":speed2", ":speed",2), (val_abs, ":speed2"),
     (position_get_x,":drift",pos6), (assign, ":abs_drift", ":drift"), (val_abs, ":abs_drift"), 
     (try_begin),
       (eq,":forced_to_stand", 1),
       (try_begin),
          (agent_get_animation, ":anim", ":agent",0),
          (eq, ":anim", "anim_stand_to_crouch"),
          (agent_set_animation, ":agent", "anim_crouch_to_low"),
          (agent_set_slot, ":agent", slot_agent_crouching, 3),
       (try_end),
     (else_try),
       (this_or_next|eq, ":abs_drift", 0),
       (lt, ":abs_drift", ":speed2"),
       (try_begin),        
          (eq, ":speed", 0),
          (try_begin),
            (eq, ":crouching", 3),
            (agent_set_animation, ":agent", "anim_stand_to_crouch"),
            (agent_set_slot, ":agent", slot_agent_crouching, 1),
          (try_end),  
       (else_try),
          (eq, ":crouching", 1),
          (agent_set_animation, ":agent", "anim_crouch_to_low"),
          (agent_set_slot, ":agent", slot_agent_crouching, 2),
       (else_try), 
          (agent_set_slot, ":agent", slot_agent_crouching, 3),     
          (is_between, ":speed", 1, 200),     
          (agent_set_animation, ":agent", "anim_walk_forward_crouch"),
       (else_try),
          (is_between, ":speed", -200, 0),     
          (agent_set_animation, ":agent", "anim_walk_backward_crouch"),
       (try_end),
     (else_try),
       (lt, ":abs_drift", 200),
       (agent_set_slot, ":agent", slot_agent_crouching, 3),
       (try_begin),
         (gt, ":drift", 0),
         (agent_set_animation, ":agent", "anim_walk_right_crouch"),
       (else_try),
         (agent_set_animation, ":agent", "anim_walk_left_crouch"),         
       (try_end),  
     (try_end),       
 (try_end), ]), 
   
#pavise_related_things BEGIN   
#("cf_is_behind_pavise",
# [(store_script_param, ":agent_no", 1),   
#  (store_script_param, ":pavise", 2),   
#  (set_fixed_point_multiplier, 100),
#  (assign, ":behind", 0),
#  (agent_get_position, pos5, ":agent_no"),
#  (scene_prop_get_num_instances, ":num_pavises", ":pavise"),
#  (try_for_range, ":pavise_no", 0, ":num_pavises"),
#     (eq, ":behind", 0),
#     (scene_prop_get_instance, ":pavise_prop_id", ":pavise", ":pavise_no"),
#     (prop_instance_is_valid, ":pavise_prop_id"),
#     (scene_prop_get_hit_points, ":hp", ":pavise_prop_id"),
#     (gt, ":hp", 0),
#     (prop_instance_get_position, pos2, ":pavise_prop_id"),
#     (position_transform_position_to_local, pos3, pos5, pos2),
#     (position_get_y, ":posy", pos3),
#     (is_between, ":posy", 0, 100),
#     (position_get_x, ":posx", pos3),
#     (is_between, ":posx", -70, 70),
#     (assign, ":behind", 1),
#   (try_end),  
#   (eq, ":behind", 1), ]),     
#
#  
#("deploy_pavise",
# [(store_script_param, ":agent_no", 1),  
#  (agent_get_wielded_item, ":shield_item", ":agent_no", 1),
#  (try_begin),
#     (is_between, ":shield_item", "itm_tab_shield_pavise_a", "itm_tab_shield_pavise_c"),
#     (assign, ":pavise_shield","spr_pavise_shield3"),
#  (else_try),
#     (is_between, ":shield_item", "itm_tab_shield_pavise_c", "itm_tab_shield_small_round_a"),
#     (assign, ":pavise_shield","spr_pavise_shield1"),
#  (else_try),
#     (assign, ":pavise_shield", 0),
#  (try_end),
#  (try_begin),  
#    (gt, ":pavise_shield", 0),
#    (call_script, "script_cf_agent_pushed_to_crouch",":agent_no"), 
#    (set_fixed_point_multiplier, 100), 
#    (agent_get_position, pos2, ":agent_no"),
#    (position_move_y, pos2, 75, 0),
#    (position_set_z_to_ground_level, pos2),
#    (set_spawn_position, pos2),
#    (spawn_scene_prop, ":pavise_shield"),
#    (agent_unequip_item, ":agent_no", ":shield_item"),
#  (try_end), ]),   
#pavise_related_things END

Code:
 ["walk_forward_crouch", acf_enforce_lowerbody, amf_priority_continue|amf_use_cycle_period|amf_client_prediction,
   # DUNDE :
   #[1.7, "low_walk", 0, 48, arf_use_walk_progress,pack2f(0.4,0.9)],
   [1.7, "low_walk", 0, 48, arf_use_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0]],
 ["stand_to_crouch", acf_enforce_lowerbody, amf_priority_continue|amf_client_prediction|amf_keep,
   [1.0, "crouch_down", 0, 81,  arf_blend_in_1, 0, (0.0,0,0.0)]],
 ["crouch_to_stand", acf_enforce_lowerbody, amf_priority_continue|amf_client_prediction|amf_play,
   [1.0, "crouch_down", 154, 185, arf_blend_in_1, 0, (0.0,0,0.0)]],

Code:
["walk_backward_crouch", acf_enforce_lowerbody, amf_priority_continue|amf_use_cycle_period|amf_client_prediction,
  [1.7, "low_walk", 48, 0, arf_use_inv_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0]],
["walk_left_crouch", acf_enforce_lowerbody, amf_priority_continue|amf_use_cycle_period|amf_client_prediction,
  [1.7, "crouch_side", 58, 0, arf_use_inv_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0]],
["walk_right_crouch", acf_enforce_lowerbody, amf_priority_continue|amf_use_cycle_period|amf_client_prediction,
  [1.7, "crouch_side", 0, 58, arf_use_inv_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0]],  
["crouch_to_low", acf_enforce_lowerbody, amf_priority_kick|amf_client_prediction|amf_play,
  [0.7, "crouch_down", 154, 180, arf_blend_in_1, 0, (0.0,0,0.0)]],

and the result :
Player crouching behind a deployed pavise shield
Crouching Formation


Credits :
harry_ for low side animation
 
Looks good! (though I must admit, I strongly hoped you'd figured out a way to get agent_set_walk_forward_animation to work and avoid having to use agent_set_position)

I'm guessing the speed problems are coming from the use of position_move_y. There's some funny business about the way it handles/doesn't handle the fixed-point-multiplier and the comment in header_operations that it moves the position in increments of centimeters being fictitious. (Or, perhaps my personal distrust of said operation goes too far.)



 
Specialist said:
Any chances you could make this work in MP?

May be, but this code's too expensive (using of set_position) for dealing with multiple player agents. It may cause lag.

Caba`drin said:
Looks good! (though I must admit, I strongly hoped you'd figured out a way to get agent_set_walk_forward_animation to work and avoid having to use agent_set_position)
I think the operation can't be used for player agent, just like agent_set_speed_limit

Caba`drin said:
I'm guessing the speed problems are coming from the use of position_move_y. There's some funny business about the way it handles/doesn't handle the fixed-point-multiplier and the comment in header_operations that it moves the position in increments of centimeters being fictitious. (Or, perhaps my personal distrust of said operation goes too far.)
I don't think so. position_move_* 's fine as long as we set fixed_point_multiplier before. The problem is, the trigger's called for every frame, and it will be vary for every machine. In fact, when I activated frap's recording, my framerate 's down from 80s to 30 and then the movement speed's decreased.
Here's the version with timing for movement. It will set  low walk speed being 10 cm/s.
Code:
player_do_low_walk = (0, 0, 0, 
  [(get_player_agent_no, ":player_agent"), (agent_slot_ge, ":player_agent", slot_agent_crouching, 1),
   (try_begin),
      (game_key_is_down, gk_move_forward),
      (agent_set_animation,":player_agent", "anim_walk_forward_crouch"),
      (store_mission_timer_a_msec, ":timer"),
      (try_begin),
        (agent_slot_eq, ":player_agent", slot_agent_crouching, 1),                 
        (agent_set_slot, ":player_agent", slot_agent_crouching, 2),         
      (else_try),
        (set_fixed_point_multiplier, 1000),
        (agent_get_slot, ":last_timer", ":player_agent", slot_agent_last_walk),
        (store_sub, ":diff", ":timer", ":last_timer"),
        (val_div, ":diff", 10),           
        (agent_get_position, pos1, ":player_agent"),
        (position_move_y, pos1, ":diff", 0),
        (agent_set_position, ":player_agent", pos1),
      (try_end),  
      (agent_set_slot, ":player_agent", slot_agent_last_walk, ":timer"),
   (else_try),
      (agent_slot_ge, ":player_agent", slot_agent_crouching, 2),
      (agent_set_animation,":player_agent", "anim_stand_to_crouch"), 
      (agent_set_slot, ":player_agent", slot_agent_crouching, 1),
   (try_end), ], [])
 
The reason it's lagging is because you keep resetting the animation state.  The animation shouldn't need to be called every frame like that.
 
That's awesome. Good to see that someone had done it.

I'm doing machinachions on this idea for some time, but as I'm the lamest in Python it would take some time to understand the language first.

I don't want to get offtopic, but adding with this a sprinting function with some kind of stamina bar (to men and horses) would be awesome.


Edit: Corrected awful sentence construction
 
xenoargh said:
The reason it's lagging is because you keep resetting the animation state.  The animation shouldn't need to be called every frame like that.

It's the only way to force the game not to use standard walking animation. It seems that if we set the same animation to current played animation, the game just continue playing it not reseting the animation. It looks like too fast now, for the game makes the agent running while we holding the forward key.

BTW, here's my last version. It don't use set_position anymore, instead using standard walking/running speed and supporting backward movement too. I set the animation priority lower now, letting the agent play seath/unseath weapon while do low walking. Even attacking is possibel, but due to weird looks, I decided to make the agent stop moving if the player attack/defend while moving.

Code:
 ["walk_forward_crouch", acf_enforce_lowerbody, amf_priority_continue|amf_use_cycle_period|amf_client_prediction,
   # DUNDE :
   #[1.7, "low_walk", 0, 48, arf_use_walk_progress,pack2f(0.4,0.9)],
   [1.7, "low_walk", 0, 48, arf_use_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0]],
 ["stand_to_crouch", acf_enforce_lowerbody, amf_priority_kick|amf_client_prediction|amf_keep,
   [1.0, "crouch_down", 0, 81,  arf_blend_in_1, 0, (0.0,0,0.0)]],
 ["crouch_to_stand", acf_enforce_lowerbody, amf_priority_kick|amf_client_prediction|amf_play,
   [1.0, "crouch_down", 154, 185, arf_blend_in_1, 0, (0.0,0,0.0)]],

Code:
["walk_backward_crouch", acf_enforce_lowerbody, amf_priority_continue|amf_use_cycle_period|amf_client_prediction,
  [1.7, "low_walk", 48, 0, arf_use_inv_walk_progress|arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0]],

["crouch_to_low", acf_enforce_lowerbody, amf_priority_kick|amf_client_prediction|amf_play,
  [1.0, "crouch_down", 154, 180, arf_blend_in_1, 0, (0.0,0,0.0)]],
# ["unused_human_anim_14", 0, 0, [1.0, "anim_human", 0, 1, 0]],
# ["unused_human_anim_15", 0, 0, [1.0, "anim_human", 0, 1, 0]],


Code:
player_do_crouch = (0, 0, 2, [(key_clicked, key_z)],
  [(get_player_agent_no, ":player_agent"),
   (agent_get_horse, ":horse", ":player_agent"),
   (le, ":horse", 0),
   (agent_get_slot, ":crouching", ":player_agent", slot_agent_crouching),
   (try_begin),
     (eq, ":crouching", 0),
     (display_message,"@crouch key pressed (begin)."),
     (assign, ":crouching", 1),     
     (agent_set_animation,":player_agent", "anim_stand_to_crouch"),               
     #(agent_set_walk_forward_animation, ":player_agent", "anim_walk_forward_crouch"),
   (else_try),
     (ge, ":crouching", 1),
     (display_message,"@crouch key pressed (end)."),
     (assign, ":crouching", 0),
     (agent_set_animation,":player_agent", "anim_crouch_to_stand"),
     #(agent_set_walk_forward_animation, ":player_agent", "anim_run_forward"),
   (try_end),
   (agent_set_slot, ":player_agent", slot_agent_crouching, ":crouching"), ]) 

player_do_low_walk = (0, 0, 0, 
  [(get_player_agent_no, ":player_agent"), (agent_slot_ge, ":player_agent", slot_agent_crouching, 1),
   (try_begin),
      (agent_get_attack_action, ":must_zero1", ":player_agent"),
      (agent_get_defend_action, ":must_zero2", ":player_agent"),
      (this_or_next|neq, ":must_zero1", 0), (neq, ":must_zero2", 0),
      (try_begin),
        (agent_slot_ge, ":player_agent", slot_agent_crouching, 2),
        (agent_set_animation,":player_agent", "anim_stand_to_crouch"), 
        (agent_set_slot, ":player_agent", slot_agent_crouching, 1),
      (try_end),  
   (else_try),  
      (game_key_is_down, gk_move_forward), 
      (try_begin),        
        (agent_slot_eq, ":player_agent", slot_agent_crouching, 1),
        (agent_set_animation,":player_agent", "anim_crouch_to_low"),        
        (agent_set_slot, ":player_agent", slot_agent_crouching, 2),         
      (else_try),  
        (agent_set_animation,":player_agent", "anim_walk_forward_crouch"),
      (try_end),
   (else_try),  
      (game_key_is_down, gk_move_backward), 
      (try_begin),        
        (agent_slot_eq, ":player_agent", slot_agent_crouching, 1),
        (agent_set_animation,":player_agent", "anim_crouch_to_stand"),        
        (agent_set_slot, ":player_agent", slot_agent_crouching, 2),         
      (else_try),  
        (agent_set_animation,":player_agent", "anim_walk_backward_crouch"),
      (try_end),       
   (else_try),
      (agent_slot_ge, ":player_agent", slot_agent_crouching, 2),
      (agent_set_animation,":player_agent", "anim_stand_to_crouch"), 
      (agent_set_slot, ":player_agent", slot_agent_crouching, 1),
   (try_end), ], [])
 
sth wrong there...
(agent_get_attack_action, ":must_zero1", ":player_agent"),
(agent_get_defend_action, ":must_zero2", ":player_agent"),
(this_or_next|neq, ":must_zero1", 0), (neq, ":must_zero2", 0),

if you are atacking, this will return true, because you are not defending, if you are defending, this will also return true, because you are not atacking, if you are not atacking nor defending, it will also return true, the only way to make it return false, is atacking and defending at the same time, and that is impossible.
 
If we're attacking then must_zero1>0.
If we're defending then must_zero2>0.

So, if we're attacking or defending then (this_or_next|neq, ":must_zero1", 0), (neq, ":must_zero2", 0), will be passed, and the agent will stand up (playing normal walking/running animation). I made it that way because the  low walking stance animation will make the agent looks weird when attacking or defending.

 
I have an MP version of a crouch code I was working on a while ago. I think it's actually good to go, it just needs animations for every direction except forwards. I'll dig it up later today and we can compare notes.

That reminds me, if anyone is interested doing some stereotypical ninja and/or pirate armors and weapons, let me know. I have a mod on hiatus simply because I'm not yet practiced enough in modelling to make good armor/clothing.

Edit:
Here's my code server-side. I have server events to handle crouching down and getting up. Ideally (ie. if I had the animations atm) I would have made checks for each of the 9 possibilities for vX and vY. I don't have anything to account for a speed change, but would it be possible to use an animation displacement to fudge it?

Code:
server_crouch = (0, 0, 0, [(multiplayer_is_server),],[
	(try_for_agents, ":cur"),
		(agent_is_alive, ":cur"),
		(agent_is_human, ":cur"),
		(agent_slot_eq,":cur",crouch_slot,1),
		
		(agent_get_speed, pos6, ":cur"),
		(set_fixed_point_multiplier, 1000),
		(position_get_x,":vX",pos6),
		(position_get_y,":vY",pos6),
		(val_abs,":vX"), #Remove these when I get more animations
		(val_abs,":vY"), #and test for each below.
		
		(try_begin),
			(this_or_next|gt, ":vX", 0),
			(gt, ":vY", 0),
			(agent_set_animation, ":cur", "anim_walk_forward_crouch"),
		(else_try),
			(agent_set_animation, ":cur", "anim_crouch_idle"),
		(try_end),
	(try_end),
])

Edit 2: This is not optimized in any way. I haven't played around with timing intervals to see if I can cut the number of checks and maintain a smooth look.
 
Ah, checking agent's speed. Very clever method that 's never crossed my mind before. So we need no key  check and can be generalized for all agents.
Thank you, MadocComadrin.
 
Couldn't you just lower the player's agility? I mean, the minimum (in Native) is like 6. Remove 4 agility while low walking, then add 4 agility back when you hit the button to stand up. :wink:
 
MadocComadrin said:
Next thing to try would be using the animation displacement to fudge speed reduction when crouch-walking.
Then I need an animator to do that. My current solution now is using your method to check agent's speed and if it 's above certain value it will play normal walking/running animation instead of low walking. I will need low side moving animations too. Currently if the agent side moving is more then a half of it's forward/backward speed then the agent will be forced to stand.
Certain actions with items will force agent to stand too, like crossbow reloading and longbow shooting to prevent the item's planted to the ground.

Specialist said:
Couldn't you just lower the player's agility? I mean, the minimum (in Native) is like 6. Remove 4 agility while low walking, then add 4 agility back when you hit the button to stand up. :wink:
For player/hero agent, using slot to significantly reduce athletics skill for the relevant troop id while the agent's crouching will be easier and there's no risk to permanently loosing attribute if the script failed.
But I prefer to use speed checking and forcing to stand method at least until I have animation with proper displacement like MadocComadrin referred.
 
MadocComadrin said:
I have an MP version of a crouch code I was working on a while ago. I think it's actually good to go, it just needs animations for every direction except forwards.

Code:
server_crouch = (0, 0, 0, [(multiplayer_is_server),],[
	(try_for_agents, ":cur"),
		(agent_is_alive, ":cur"),
		(agent_is_human, ":cur"),
		(agent_slot_eq,":cur",crouch_slot,1),
		
		(agent_get_speed, pos6, ":cur"),
		(set_fixed_point_multiplier, 1000),
		(position_get_x,":vX",pos6),
		(position_get_y,":vY",pos6),
		(val_abs,":vX"), #Remove these when I get more animations
		(val_abs,":vY"), #and test for each below.
		
		(try_begin),
			(this_or_next|gt, ":vX", 0),
			(gt, ":vY", 0),
			(agent_set_animation, ":cur", "anim_walk_forward_crouch"),
		(else_try),
			(agent_set_animation, ":cur", "anim_crouch_idle"),
		(try_end),
	(try_end),
])

where to paste this to get it to work?
 
Put it above
mission_templates = [
at module_mission_templates.py and then add :
server_crouch,
at your multiplayer's mission template. And it seems that the code is server side.
 
Back
Top Bottom