Free-cam after death, battle continues.

Users who are viewing this thread

Chinta Kari

Veteran
Hi folks,

I have seen some threads that treat the topic but I seem too inept to dig it. So I wonder if some charitable soul of the forum would be so kind as to explain me how to do it in a fool-friendly way.

Basically, what I would like is that once the main char falls in combat the battle continues without you plus you get the ability to have a free-cam (like ctrl+e in the edit mode but without having to enable the edit mode).

Anyone? :smile:
 
I think you could enter edit mode(ctrl+e after editmode enabled in first menu) when you die.
You have the edit mode free-cam, and the battle keeps going.

It'd be nice if you could keep looking through the death cam while lying on the ground, though.
 
I know that other mods have this and there are definitely other code snippets around, but that didn't stop me from doing my own implementation  :mrgreen:

It's a fairly straightforward change but it hits a lot of different bits of code.  If you're not sure of you hand-merge skills, make sure to make a backup.  Also in this set of changes is a simple deathcam implementation.  Add the stuff in blue.  Comment out/remove the stuff in red.

All of the action is in module_mission_templates.py.  Start by commenting out the red line.  This turns off the check that the fight ends when the player is defeated.
common_battle_check_victory_condition = (
  1, 60, ti_once,
  [
    (store_mission_timer_a,reg(1)),
    (ge,reg(1),10),
    (all_enemies_defeated, 5),
    (neg|main_hero_fallen, 0),
    (set_mission_result,1),
    (display_message,"str_msg_battle_won"),
    (assign,"$battle_won",1),
    (assign, "$g_battle_result", 1),
    (call_script, "script_play_victorious_sound"),
    ],
  [
    (call_script, "script_count_mission_casualties_from_agents"),
    (finish_mission, 1),
    ])

You'll need to do a similar thing a bit later for sieges.  I've added the line in blue for fun.
common_siege_check_defeat_condition = (
  1, 4, ti_once,
  [
    (main_hero_fallen)
    ],
  [
    (assign, "$pin_player_fallen", 1),
    (display_message, "@You have fallen in battle!"),
    (get_player_agent_no, ":player_agent"),
    (agent_get_team, ":agent_team", ":player_agent"),
    (try_begin),
      (neq, "$attacker_team", ":agent_team"),
      (neq, "$attacker_team_2", ":agent_team"),
      (str_store_string, s5, "str_siege_continues"),
      (call_script, "script_simulate_retreat", 8, 15),
    (else_try),
      (str_store_string, s5, "str_retreat"),
      (call_script, "script_simulate_retreat", 5, 20),
    (try_end),
    (assign, "$g_battle_result", -1),
    (set_mission_result,-1),
    (call_script, "script_count_mission_casualties_from_agents"),
    (finish_mission,0),

    ])

Add this stuff right after the last bit:

common_kt_move_forward_deathcam = (
0, 0, 0,
[
(this_or_next|game_key_clicked, key_w),
(key_is_down, key_w),
(main_hero_fallen),
],
[
(get_player_agent_no, ":player_agent"),
(agent_get_look_position, pos1, ":player_agent"),
(position_move_y, pos1, 10),
(agent_set_position, ":player_agent", pos1),
]
)

common_kt_move_backward_deathcam = (
0, 0, 0,
[
(this_or_next|game_key_clicked, key_s),
(key_is_down, key_s),
(main_hero_fallen),
],
[
(get_player_agent_no, ":player_agent"),
(agent_get_look_position, pos1, ":player_agent"),
(position_move_y, pos1, -10),
(agent_set_position, ":player_agent", pos1),
]
)


common_kt_move_left_deathcam = (
0, 0, 0,
[
(this_or_next|game_key_clicked, key_a),
(key_is_down, key_a),
(main_hero_fallen),
],
[
(get_player_agent_no, ":player_agent"),
(agent_get_look_position, pos1, ":player_agent"),
(position_move_x, pos1, -10),
(agent_set_position, ":player_agent", pos1),
]
)

common_kt_move_right_deathcam = (
0, 0, 0,
[
(this_or_next|game_key_clicked, key_d),
(key_is_down, key_d),
(main_hero_fallen),
],
[
(get_player_agent_no, ":player_agent"),
(agent_get_look_position, pos1, ":player_agent"),
(position_move_x, pos1, 10),
(agent_set_position, ":player_agent", pos1),
]
)

Then, for each of the mission types you care about, add the following lines:

      common_kt_move_forward_deathcam,
      common_kt_move_backward_deathcam,
      common_kt_move_left_deathcam,
      common_kt_move_right_deathcam,
I have this stuff in lead_charge, besiege_inner_battle_castle, besiege_inner_battle_town_center, castle_attack_walls_defenders_sally, castle_attack_walls_belfry, and castle_attack_walls_ladder.

In context, it looks like this (from lead_charge):
      common_battle_tab_press,

      common_kt_move_forward_deathcam,
      common_kt_move_backward_deathcam,
      common_kt_move_left_deathcam,
      common_kt_move_right_deathcam,

      (ti_question_answered, 0, 0, [],
      [(store_trigger_param_1,":answer"),
        (eq,":answer",0),
        (assign, "$pin_player_fallen", 0),
        (try_begin),
          (store_mission_timer_a, ":elapsed_time"),
          (gt, ":elapsed_time", 20),
          (str_store_string, s5, "str_retreat"),
          (call_script, "script_simulate_retreat", 10, 20),
        (try_end),
        (call_script, "script_count_mission_casualties_from_agents"),
        (finish_mission,0),]),

Also in lead_charge, you need to make this change:
      (1, 4, ti_once, [(main_hero_fallen)],
          [
              (assign, "$pin_player_fallen", 1),
              (display_message, "@You have fallen in battle!"),
              (str_store_string, s5, "str_retreat"),
              (call_script, "script_simulate_retreat", 10, 20),
              (assign, "$g_battle_result", -1),
              (set_mission_result,-1),
              (call_script, "script_count_mission_casualties_from_agents"),
              (finish_mission,0)
]),

Unless I've missed something somewhere, that's what I have minus my kill counter.  I've had it in my code for about two weeks so it's reasonably well tested.  As always, credits with publically released mods would be swell.  Props to MartinF and others who discussed this a while back.

Also:  BLAM
 
@Gallus,
The problem with edit mode being that it slows down the game so much, that's why I was looking for some alternative to it.

@kt0
You made my day, many thanks! <3

I am gonna try to put the stuff around and see if it works.

Also, I have a question, if you need to define the cam movement like that, can you still look around with the mouse? And also, could it work out if I add something like this:

common_kt_move_up_deathcam = (
  0, 0, 0,
  [
      (this_or_next|game_key_clicked, key_z),
      (key_is_down, key_z),
      (main_hero_fallen),
  ],
  [
      (get_player_agent_no, ":player_agent"),
      (agent_get_look_position, pos1, ":player_agent"),
      (position_move_z, pos1, 10),
      (agent_set_position, ":player_agent", pos1),
  ]
)


common_kt_move_down_deathcam = (
  0, 0, 0,
  [
      (this_or_next|game_key_clicked, key_x),
      (key_is_down, key_x),
      (main_hero_fallen),
  ],
  [
      (get_player_agent_no, ":player_agent"),
      (agent_get_look_position, pos1, ":player_agent"),
      (position_move_z, pos1, -10),
      (agent_set_position, ":player_agent", pos1),
  ]
)

  to have a full free cam?
 
Yes, you should still be able to look around with the mouse.  When the position is changed and set it's relative to the camera's orientation in the XY plane which is why there isn't any messy maths in there.  It works reasonably well for most things though I fall off of keep walls ocassionally and have to fly back up the ladders/whatever.

I vaguely recall trying to add up and down but don't remember why I didn't (I was, um, drinking that night).  My best advice is to give it a shot and see what happens.  If you do try it, let us know if it works  :mrgreen:
 
Ok, this is the outcome:

First, in your excellent and crystal clear explanation, in the last spoiler, at the end, appears 

(finish_mission,0)]),

and that is kind of nasty because you can't comment it out like that, you still need the  ]),  on a different line. It took me a while to find out where the damned problem was (that kind of hopeless newbie I am).

Secondly, and thinking of future generations, you need to add to your tutorial that it is necessary to change the constant common_battle_tab_press constant because otherwise it is not possible to get out of a battle once you fall to the ground. MartinF suggests here this version, that although not completely perfect works fine:


Code:
common_battle_tab_press = (
  ti_tab_pressed, 0, 0, [],
  [
    (try_begin),
      (eq, "$battle_won", 1),
      (call_script, "script_count_mission_casualties_from_agents"),
      (finish_mission,0),
   (else_try),
      (eq, "$pin_player_fallen", 1),
      (call_script, "script_simulate_retreat", 5, 20),
      (str_store_string, s5, "str_retreat"),
      (call_script, "script_count_mission_casualties_from_agents"),
      (set_mission_result, -1),
      (finish_mission,0),
    (else_try),
      (call_script, "script_cf_check_enemies_nearby"),
      (question_box,"str_do_you_want_to_retreat"),
    (else_try),
      (display_message,"str_can_not_retreat"),
    (try_end),
    ])

And finally, I don't know why but the movements on the z axis are not happening. I got the feeling that talking about positions instead of move_cam is preventing it, but I am asking some wiser person to pour wisdon on us. Let's see what happens.
 
Chinta Kari said:
(finish_mission,0)]),

and that is kind of nasty because you can't comment it out like that, you still need the  ]),  on a different line. It took me a while to find out where the damned problem was (that kind of hopeless newbie I am).
Yeah, my bad.  When I saw that in my diff I had the choice to either split it out to the next line or to show it like it is in Native.  I chose the later and tried to indicate the intent through color. 

Secondly, and thinking of future generations, you need to add to your tutorial that it is necessary to change the constant common_battle_tab_press constant because otherwise it is not possible to get out of a battle once you fall to the ground.
Yep, saw that too and thought it was part of an unrelated change.  Posting code is like that.  I used to tell my students that any code I ever put in front of them is suspect, and that's certainly the case here!  Programming should always come along side a healthy dose of skepticism. 

For getting it to move like you want, the mission cam stuff is probably more suitable.  My best guess is that agent_set_position snaps to ground height which is probably why I never added up and down movement.  Don't be afraid to experiment with stuff.  It's just code. 
 
I can't get my hands on mission cam stuff working out the way I want and I am sure once you know the command, it must be quite simple (for it is already implemented in the Edit mode).

Can anyone cast light on me? It's pretty dark here in my noobiness.
 
Sorry for Nec- but I wanted to use Kt0 and Martinf's code for reference.

Has anybody got this fully working in WB yet? I can get the camera to stay after fallen as well as the Tab retreat, but for the life of me can't get either of the 2 camera scripts to take.

From Kt0's code:
Code:
common_kt_move_forward_deathcam = (
   0, 0, 0,
   [
      (this_or_next|game_key_clicked, key_w),
      (key_is_down, key_w),
      (main_hero_fallen),
   ],

I always get a syntax error under the '=' when building.

Same error with Martinf' code, a syntax error pointing at the '='
 
froggyluv said:
Sorry for Nec- but I wanted to use Kt0 and Martinf's code for reference.

Has anybody got this fully working in WB yet? I can get the camera to stay after fallen as well as the Tab retreat, but for the life of me can't get either of the 2 camera scripts to take.

From Kt0's code:
Code:
common_kt_move_forward_deathcam = (
   0, 0, 0,
   [
      (this_or_next|game_key_clicked, key_w),
      (key_is_down, key_w),
      (main_hero_fallen),
   ],

I always get a syntax error under the '=' when building.

Same error with Martinf' code, a syntax error pointing at the '='

If you move the code up to around line 632 it compiles without any problems; the deathcam still doesnt work though  :sad:
 
Thanks. I did that and it did compile and just like you said, death cam doesn't activate properly. I also used Martinf's version (see other deathcam thread) and it works -only backwards, from target soldier back to your corpse. Something must have changed with the MS so I guess we'll have to wait...
 
I'm a little confused on how to implement this code. Can it be done simply by adding it to Mission templates.txt using the raw code ?

The reason being is, i have a modded templates file and i have forgotten how to import the .txt files to edit with IDLE.

I know this thread is old, but it seems my only option for a death-cam for 1.011 - using PoP - 2.5. At any rate i'll keep fiddling with the MS.


Edit: Well i have the module system up and running and can edit and build, but how do i edit the existing templates file in my mod directory. If i build a fresh one with the cam-code it won't have the multitude of other changes made by me or by the existing mod.

Edit-2: Well i have kind of found a way to do it. I make the cam edit to mission templates.py then build and cross-reference the raw code with the original mission templates.txt file, then add in the code manually.

However i am stuck again with the implementation of the code.

Kto says "add this right after the last bit"

Does he mean add it here;


common_siege_check_defeat_condition = (
  1, 4, ti_once,
  [
    (main_hero_fallen)
    ],
  [
    (assign, "$pin_player_fallen", 1),
    ])

<cam code starts here> ? 

Or by "Last bit" does he mean after the last line in the file ? ... I know this is dumb, but i find that to be very vague.
 
In the module system, declaring it before the list of actual mission templates allow you to reuse common triggers. It makes no difference once it compiles though, and you can copy triggers over as long as you change the number of triggers after the list of entry points.
 
Back
Top Bottom