WFaS Coding Health Bars

Users who are viewing this thread

Yagababa

Recruit
Hey guys, sorry to double post.

I found this code for a health bar presentation code, but for some reason they aren't appearing in-game.

Code:
("multiplayer_agent_hp_bar", prsntf_read_only, 0,
        [
            (ti_on_presentation_load,
                [
                    (set_fixed_point_multiplier, 1000),

                    (get_max_players, ":num_players"),
                    (try_for_range, ":player_no", 0, ":num_players"),
                        (player_is_active, ":player_no"),
                        (neg|player_is_busy_with_menus, ":player_no"),

                        (player_get_team_no, ":player_team", ":player_no"),
                        (lt, ":player_team", multi_team_spectator),

                        (player_get_troop_id, ":player_troop", ":player_no"),
                        (ge, ":player_troop", 0),

                        (player_get_agent_id, ":player_agent", ":player_no"),
                        (ge, ":player_agent", 0),

                        (try_for_agents, ":agent_no"),
                            (agent_is_human, ":agent_no"),
                            (neq, ":agent_no", ":player_agent"),

                            (try_begin),
                                (agent_is_alive, ":agent_no"),
                                (agent_get_team, ":agent_team", ":agent_no"),

                                #hp bg
                                (create_mesh_overlay, ":agent_hp_bg_overlay", "mesh_white_plane"),
                                (overlay_set_alpha, ":agent_hp_bg_overlay", 0x44),
                                (overlay_set_color, ":agent_hp_bg_overlay", 0xFF000000),

                                #hp
                                (create_mesh_overlay, ":agent_hp_overlay", "mesh_white_plane"),
                                (overlay_set_alpha, ":agent_hp_overlay", 0x44),
                                (try_begin),
                                    (eq, ":agent_team", ":player_team"),
                                    (overlay_set_color, ":agent_hp_overlay", 0xFF00FF00), #green
                                (else_try),
                                    (overlay_set_color, ":agent_hp_overlay", 0xFFFF0000), #red
                                (try_end),

                                #size & position
                                (agent_get_position, pos1, ":agent_no"),
                                (agent_get_horse, ":horse_agent", ":agent_no"),
                                (try_begin),
                                    (ge, ":horse_agent", 0),
                                    (position_move_z, pos1, 280, 1),
                                (else_try),
                                    (position_move_z, pos1, 180, 1),
                                (try_end),
                                (position_get_screen_projection, pos2, pos1),
                                (position_get_x, ":head_x_pos", pos2),
                                (position_get_y, ":head_y_pos", pos2),

                                #base size
                                (copy_position, pos6, pos1),
                                (copy_position, pos7, pos1),
                                (position_move_z, pos7, 100, 1),
                                (position_get_screen_projection, pos6, pos6),
                                (position_get_screen_projection, pos7, pos7),
                                (position_get_y, ":screen_y_pos_1", pos6),
                                (position_get_y, ":screen_y_pos_2", pos7),
                                (store_sub, ":base_x", ":screen_y_pos_2", ":screen_y_pos_1"),
                                (val_clamp, ":base_x", 20, 161),
                                (store_div, ":base_y", ":base_x", 20),
                                (try_begin),
                                    (is_between, ":head_x_pos", -100, 1100),
                                    (is_between, ":head_y_pos", -100, 850),
                                    (agent_get_position, pos3, ":agent_no"),
                                    (agent_get_position, pos4, ":player_agent"),
                                    (get_distance_between_positions_in_meters, ":distance", pos3, pos4),
                                    #---------------------------------------------------------
                                    (le, ":distance", 80), #distance limit for showing HP bars
                                    #---------------------------------------------------------

                                    #agent no
                                    (agent_get_horse, ":horse_agent", ":agent_no"),
                                    (try_begin),
                                        (ge, ":horse_agent", 0),
                                        (position_move_z, pos3, 280, 1),
                                    (else_try),
                                        (position_move_z, pos3, 180, 1),
                                    (try_end),
                                    #player agent
                                    (agent_get_horse, ":player_horse", ":player_agent"),
                                    (try_begin),
                                        (ge, ":player_horse", 0),
                                        (position_move_z, pos4, 280, 1),
                                    (else_try),
                                        (position_move_z, pos4, 180, 1),
                                    (try_end),
                                    (position_move_z, pos3, 50, 1),
                                    (position_move_z, pos4, 50, 1),
                                    (position_has_line_of_sight_to_position, pos3, pos4),

                                    #hp bg
                                    (assign, ":mad:_offset", ":base_x"),
                                    (val_div, ":mad:_offset", 2),
                                    (val_add, ":mad:_offset", 1),
                                    (store_sub, ":hp_bg_x", ":head_x_pos", ":mad:_offset"),
                                    (store_sub, ":hp_bg_y", ":head_y_pos", 1),
                                    (position_set_x, pos1, ":hp_bg_x"),
                                    (position_set_y, pos1, ":hp_bg_y"),
                                    (overlay_set_position, ":agent_hp_bg_overlay", pos1),
                                    (store_add, ":bg_width", ":base_x", 2),
                                    (val_mul, ":bg_width", 50),
                                    (store_add, ":bg_height", ":base_y", 2),
                                    (val_mul, ":bg_height", 50),
                                    (position_set_x, pos1, ":bg_width"),
                                    (position_set_y, pos1, ":bg_height"),
                                    (overlay_set_size, ":agent_hp_bg_overlay", pos1),
                                    (overlay_set_alpha, ":agent_hp_bg_overlay", 0x66),

                                    #hp
                                    (store_add, ":hp_x", ":hp_bg_x", 1),
                                    (store_add, ":hp_y", ":hp_bg_y", 1),
                                    (position_set_x, pos1, ":hp_x"),
                                    (position_set_y, pos1, ":hp_y"),
                                    (overlay_set_position, ":agent_hp_overlay", pos1),
                                    (store_agent_hit_points, ":agent_hp", ":agent_no"),
                                    (store_mul, ":hp_width", ":agent_hp", 50),
                                    (val_mul, ":hp_width", ":base_x"),
                                    (val_div, ":hp_width", 100),
                                    (val_min, ":hp_width", ":bg_width"),
                                    (store_mul, ":hp_height", ":base_y", 50),
                                    (position_set_x, pos1, ":hp_width"),
                                    (position_set_y, pos1, ":hp_height"),
                                    (overlay_set_size, ":agent_hp_overlay", pos1),

                                (else_try),
                                    (overlay_set_alpha, ":agent_hp_bg_overlay", 0),
                                    (overlay_set_alpha, ":agent_hp_overlay", 0),
                                (try_end),
                            (try_end),
                        (try_end),
                    (try_end),
                ]
            ),
        ]
    ),

I tested the code with some debug messages, and know the trigger is working and the code is running, but they don't show up in-game.
 
Last edited by a moderator:
The entire script does not show up because it is a XenForo bug; things written in a quote/ spoiler and then put in another quote/ spoiler do not show up. I managed to read it because I displayed the HTML code of this webpage. Others may not, so please edit your thread for the other people.

  1. Firstly, specify if the script is meant for MP or SP and if for MP, tell if for server or client. As far as I know, damage calculation is done server-side, so such script will not work client-side unless your modded server will return data to modded client when asked. I may be wrong although it is unlikely.
  2. Secondly, Rubik's Custom Commander kit is quite old and has such script; its operations should be in Warband 1.143 (WFaS runs on 1.143). I recommend checking it out if you want to use it in SP.
  3. Thirdly, check posts after this one: https://forums.taleworlds.com/index...quick-questions-and-answers.6575/post-9182390. There should be a few such script variations to compare with for MP.
 
Upvote 0

Eärendil Ardamírë

Subforum Moderator
WBWF&SM&B
The entire script does not show up because it is a XenForo bug; things written in a quote/ spoiler and then put in another quote/ spoiler do not show up. I managed to read it because I displayed the HTML code of this webpage. Others may not, so please edit your thread for the other people.
I edited the post accordingly, look it up for future references, Yagababa.
Firstly, specify if the script is meant for MP or SP and if for MP, tell if for server or client. As far as I know, damage calculation is done server-side, so such script will not work client-side, unless your modded server will return data to modded client. I may be wrong although it is unlikely.
That was the part about which I wasn't sure anymore since you get the health status of other players automatically. I recall that Pitch managed to create some strings on a client-side mod which lists the health.
 
Upvote 0
That was the part about which I wasn't sure anymore since you get the health status of other players automatically. I recall that Pitch managed to create some strings on a client-side mod which lists the health.
Yes, that is a thing in question. I also am not sure about it, but I am confident such a script in an MP client-side mod would be kind of dangerous, so logic tells me that maybe TW thought about it and made server handle damage calculation.
 
Upvote 0

Eärendil Ardamírë

Subforum Moderator
WBWF&SM&B
The server handles the damage calculation, true, but the client does always know how much health everyone has. Otherwise you wouldn't see the bloody particles on the cloth for example.
 
Upvote 0
The server handles the damage calculation, true, but the client does always know how much health everyone has. Otherwise you wouldn't see the bloody particles on the cloth for example.
Yes, that is correct about effects of blood, but to be honest, only people like TW or WSE devs would know an answer to this. It might be that client receives only data which bone was hit and subsequently applies blood to it; the agent's health remains hidden.
 
Upvote 0

Namakan

Grandmaster Knight
M&BWBWF&SNWVC
I'm fairly sure that the client knows all agents health, you can just use the usual operations to get it (and then display it).

The only thing I'm 100% sure about the client not knowing are unique player IDs, you can only access those serverside.

//edit:
as for the code itself, there's a few things I'm unsure about:
player_is_busy_with_menus might actually also be serverside-only

you seem to have no ti_on_presentation_run (guessing you might have omitted it here to keep things short, but this is what would actually update positions of the labels on screen)

similarly, I can't seem to find any presentation_set_duration, meaning the presentation could just go through initial setup once (thus display your messages) and then quit right away.

there might be more, this was just a quick glance
 
Last edited:
Upvote 0

Yagababa

Recruit
I'm fairly sure that the client knows all agents health, you can just use the usual operations to get it (and then display it).

The only thing I'm 100% sure about the client not knowing are unique player IDs, you can only access those serverside.

//edit:
as for the code itself, there's a few things I'm unsure about:
player_is_busy_with_menus might actually also be serverside-only

you seem to have no ti_on_presentation_run (guessing you might have omitted it here to keep things short, but this is what would actually update positions of the labels on screen)

similarly, I can't seem to find any presentation_set_duration, meaning the presentation could just go through initial setup once (thus display your messages) and then quit right away.

there might be more, this was just a quick glance

I commented out the busy_with_menus condition and tried playing with the duration to no avail...

Here's the updated code still w/ no results:

Code:
("multiplayer_agent_hp_bar", prsntf_read_only, 0,
        [
            (ti_on_presentation_load,
                [
                    (set_fixed_point_multiplier, 1000),

                    (get_max_players, ":num_players"),
                    (try_for_range, ":player_no", 0, ":num_players"),
                        (player_is_active, ":player_no"),
                        #(neg|player_is_busy_with_menus, ":player_no"),

                        (player_get_team_no, ":player_team", ":player_no"),
                        (lt, ":player_team", multi_team_spectator),

                        (player_get_troop_id, ":player_troop", ":player_no"),
                        (ge, ":player_troop", 0),

                        (player_get_agent_id, ":player_agent", ":player_no"),
                        (ge, ":player_agent", 0),

                        (try_for_agents, ":agent_no"),
                            (agent_is_human, ":agent_no"),
                            (neq, ":agent_no", ":player_agent"),

                            (try_begin),
                                (agent_is_alive, ":agent_no"),
                                (agent_get_team, ":agent_team", ":agent_no"),

                                #hp bg
                                (create_mesh_overlay, ":agent_hp_bg_overlay", "mesh_white_plane"),
                                (overlay_set_alpha, ":agent_hp_bg_overlay", 0x44),
                                (overlay_set_color, ":agent_hp_bg_overlay", 0xFF000000),

                                #hp
                                (create_mesh_overlay, ":agent_hp_overlay", "mesh_white_plane"),
                                (overlay_set_alpha, ":agent_hp_overlay", 0x44),
                                (try_begin),
                                    (eq, ":agent_team", ":player_team"),
                                    (overlay_set_color, ":agent_hp_overlay", 0xFF00FF00), #green
                                (else_try),
                                    (overlay_set_color, ":agent_hp_overlay", 0xFFFF0000), #red
                                (try_end),

                                #size & position
                                (agent_get_position, pos1, ":agent_no"),
                                (agent_get_horse, ":horse_agent", ":agent_no"),
                                (try_begin),
                                    (ge, ":horse_agent", 0),
                                    (position_move_z, pos1, 280, 1),
                                (else_try),
                                    (position_move_z, pos1, 180, 1),
                                (try_end),
                                (position_get_screen_projection, pos2, pos1),
                                (position_get_x, ":head_x_pos", pos2),
                                (position_get_y, ":head_y_pos", pos2),

                                #base size
                                (copy_position, pos6, pos1),
                                (copy_position, pos7, pos1),
                                (position_move_z, pos7, 100, 1),
                                (position_get_screen_projection, pos6, pos6),
                                (position_get_screen_projection, pos7, pos7),
                                (position_get_y, ":screen_y_pos_1", pos6),
                                (position_get_y, ":screen_y_pos_2", pos7),
                                (store_sub, ":base_x", ":screen_y_pos_2", ":screen_y_pos_1"),
                                (val_clamp, ":base_x", 20, 161),
                                (store_div, ":base_y", ":base_x", 20),
                                (try_begin),
                                    (is_between, ":head_x_pos", -100, 1100),
                                    (is_between, ":head_y_pos", -100, 850),
                                    (agent_get_position, pos3, ":agent_no"),
                                    (agent_get_position, pos4, ":player_agent"),
                                    (get_distance_between_positions_in_meters, ":distance", pos3, pos4),
                                    #---------------------------------------------------------
                                    (le, ":distance", 80), #distance limit for showing HP bars
                                    #---------------------------------------------------------

                                    #agent no
                                    (agent_get_horse, ":horse_agent", ":agent_no"),
                                    (try_begin),
                                        (ge, ":horse_agent", 0),
                                        (position_move_z, pos3, 280, 1),
                                    (else_try),
                                        (position_move_z, pos3, 180, 1),
                                    (try_end),
                                    #player agent
                                    (agent_get_horse, ":player_horse", ":player_agent"),
                                    (try_begin),
                                        (ge, ":player_horse", 0),
                                        (position_move_z, pos4, 280, 1),
                                    (else_try),
                                        (position_move_z, pos4, 180, 1),
                                    (try_end),
                                    (position_move_z, pos3, 50, 1),
                                    (position_move_z, pos4, 50, 1),
                                    (position_has_line_of_sight_to_position, pos3, pos4),

                                    #hp bg
                                    (assign, ":x_offset", ":base_x"),
                                    (val_div, ":x_offset", 2),
                                    (val_add, ":x_offset", 1),
                                    (store_sub, ":hp_bg_x", ":head_x_pos", ":x_offset"),
                                    (store_sub, ":hp_bg_y", ":head_y_pos", 1),
                                    (position_set_x, pos1, ":hp_bg_x"),
                                    (position_set_y, pos1, ":hp_bg_y"),
                                    (overlay_set_position, ":agent_hp_bg_overlay", pos1),
                                    (store_add, ":bg_width", ":base_x", 2),
                                    (val_mul, ":bg_width", 50),
                                    (store_add, ":bg_height", ":base_y", 2),
                                    (val_mul, ":bg_height", 50),
                                    (position_set_x, pos1, ":bg_width"),
                                    (position_set_y, pos1, ":bg_height"),
                                    (overlay_set_size, ":agent_hp_bg_overlay", pos1),
                                    (overlay_set_alpha, ":agent_hp_bg_overlay", 0x66),

                                    #hp
                                    (store_add, ":hp_x", ":hp_bg_x", 1),
                                    (store_add, ":hp_y", ":hp_bg_y", 1),
                                    (position_set_x, pos1, ":hp_x"),
                                    (position_set_y, pos1, ":hp_y"),
                                    (overlay_set_position, ":agent_hp_overlay", pos1),
                                    (store_agent_hit_points, ":agent_hp", ":agent_no"),
                                    (store_mul, ":hp_width", ":agent_hp", 50),
                                    (val_mul, ":hp_width", ":base_x"),
                                    (val_div, ":hp_width", 100),
                                    (val_min, ":hp_width", ":bg_width"),
                                    (store_mul, ":hp_height", ":base_y", 50),
                                    (position_set_x, pos1, ":hp_width"),
                                    (position_set_y, pos1, ":hp_height"),
                                    (overlay_set_size, ":agent_hp_overlay", pos1),

                                (else_try),
                                    (overlay_set_alpha, ":agent_hp_bg_overlay", 0),
                                    (overlay_set_alpha, ":agent_hp_overlay", 0),
                                (try_end),
                            (try_end),
                        (try_end),
                    (try_end),

                    (presentation_set_duration, 999999),
                ]
            ),
            (ti_on_presentation_run,
                [
                    (set_fixed_point_multiplier, 1000),

                    (get_max_players, ":num_players"),
                    (try_for_range, ":player_no", 0, ":num_players"),
                        (player_is_active, ":player_no"),
                        #(neg|player_is_busy_with_menus, ":player_no"),

                        (player_get_team_no, ":player_team", ":player_no"),
                        (lt, ":player_team", multi_team_spectator),

                        (player_get_troop_id, ":player_troop", ":player_no"),
                        (ge, ":player_troop", 0),

                        (player_get_agent_id, ":player_agent", ":player_no"),
                        (ge, ":player_agent", 0),

                        (try_for_agents, ":agent_no"),
                            (agent_is_human, ":agent_no"),
                            (neq, ":agent_no", ":player_agent"),

                            (try_begin),
                                (agent_is_alive, ":agent_no"),
                                (agent_get_team, ":agent_team", ":agent_no"),

                                #hp bg
                                (create_mesh_overlay, ":agent_hp_bg_overlay", "mesh_white_plane"),
                                (overlay_set_alpha, ":agent_hp_bg_overlay", 0x44),
                                (overlay_set_color, ":agent_hp_bg_overlay", 0xFF000000),

                                #hp
                                (create_mesh_overlay, ":agent_hp_overlay", "mesh_white_plane"),
                                (overlay_set_alpha, ":agent_hp_overlay", 0x44),
                                (try_begin),
                                    (eq, ":agent_team", ":player_team"),
                                    (overlay_set_color, ":agent_hp_overlay", 0xFF00FF00), #green
                                (else_try),
                                    (overlay_set_color, ":agent_hp_overlay", 0xFFFF0000), #red
                                (try_end),

                                #size & position
                                (agent_get_position, pos1, ":agent_no"),
                                (agent_get_horse, ":horse_agent", ":agent_no"),
                                (try_begin),
                                    (ge, ":horse_agent", 0),
                                    (position_move_z, pos1, 280, 1),
                                (else_try),
                                    (position_move_z, pos1, 180, 1),
                                (try_end),
                                (position_get_screen_projection, pos2, pos1),
                                (position_get_x, ":head_x_pos", pos2),
                                (position_get_y, ":head_y_pos", pos2),

                                #base size
                                (copy_position, pos6, pos1),
                                (copy_position, pos7, pos1),
                                (position_move_z, pos7, 100, 1),
                                (position_get_screen_projection, pos6, pos6),
                                (position_get_screen_projection, pos7, pos7),
                                (position_get_y, ":screen_y_pos_1", pos6),
                                (position_get_y, ":screen_y_pos_2", pos7),
                                (store_sub, ":base_x", ":screen_y_pos_2", ":screen_y_pos_1"),
                                (val_clamp, ":base_x", 20, 161),
                                (store_div, ":base_y", ":base_x", 20),
                                (try_begin),
                                    (is_between, ":head_x_pos", -100, 1100),
                                    (is_between, ":head_y_pos", -100, 850),
                                    (agent_get_position, pos3, ":agent_no"),
                                    (agent_get_position, pos4, ":player_agent"),
                                    (get_distance_between_positions_in_meters, ":distance", pos3, pos4),
                                    #---------------------------------------------------------
                                    (le, ":distance", 80), #distance limit for showing HP bars
                                    #---------------------------------------------------------

                                    #agent no
                                    (agent_get_horse, ":horse_agent", ":agent_no"),
                                    (try_begin),
                                        (ge, ":horse_agent", 0),
                                        (position_move_z, pos3, 280, 1),
                                    (else_try),
                                        (position_move_z, pos3, 180, 1),
                                    (try_end),
                                    #player agent
                                    (agent_get_horse, ":player_horse", ":player_agent"),
                                    (try_begin),
                                        (ge, ":player_horse", 0),
                                        (position_move_z, pos4, 280, 1),
                                    (else_try),
                                        (position_move_z, pos4, 180, 1),
                                    (try_end),
                                    (position_move_z, pos3, 50, 1),
                                    (position_move_z, pos4, 50, 1),
                                    (position_has_line_of_sight_to_position, pos3, pos4),

                                    #hp bg
                                    (assign, ":x_offset", ":base_x"),
                                    (val_div, ":x_offset", 2),
                                    (val_add, ":x_offset", 1),
                                    (store_sub, ":hp_bg_x", ":head_x_pos", ":x_offset"),
                                    (store_sub, ":hp_bg_y", ":head_y_pos", 1),
                                    (position_set_x, pos1, ":hp_bg_x"),
                                    (position_set_y, pos1, ":hp_bg_y"),
                                    (overlay_set_position, ":agent_hp_bg_overlay", pos1),
                                    (store_add, ":bg_width", ":base_x", 2),
                                    (val_mul, ":bg_width", 50),
                                    (store_add, ":bg_height", ":base_y", 2),
                                    (val_mul, ":bg_height", 50),
                                    (position_set_x, pos1, ":bg_width"),
                                    (position_set_y, pos1, ":bg_height"),
                                    (overlay_set_size, ":agent_hp_bg_overlay", pos1),
                                    (overlay_set_alpha, ":agent_hp_bg_overlay", 0x66),

                                    #hp
                                    (store_add, ":hp_x", ":hp_bg_x", 1),
                                    (store_add, ":hp_y", ":hp_bg_y", 1),
                                    (position_set_x, pos1, ":hp_x"),
                                    (position_set_y, pos1, ":hp_y"),
                                    (overlay_set_position, ":agent_hp_overlay", pos1),
                                    (store_agent_hit_points, ":agent_hp", ":agent_no"),
                                    (store_mul, ":hp_width", ":agent_hp", 50),
                                    (val_mul, ":hp_width", ":base_x"),
                                    (val_div, ":hp_width", 100),
                                    (val_min, ":hp_width", ":bg_width"),
                                    (store_mul, ":hp_height", ":base_y", 50),
                                    (position_set_x, pos1, ":hp_width"),
                                    (position_set_y, pos1, ":hp_height"),
                                    (overlay_set_size, ":agent_hp_overlay", pos1),

                                (else_try),
                                    (overlay_set_alpha, ":agent_hp_bg_overlay", 0),
                                    (overlay_set_alpha, ":agent_hp_overlay", 0),
                                (try_end),
                            (try_end),
                        (try_end),
                    (try_end),
                ]
            ),
        ]
    ),

I edited the post accordingly, look it up for future references, Yagababa.

Thanks Eärendil, appreciate you
 
Last edited by a moderator:
Upvote 0

Yagababa

Recruit
Alright I think my issue is on a different scale entirely. I just can't get presentations to show up client-side at all. Here's an example of something simple I tried to no effect:

Presentations:
("multiplayer_agent_hp_bar", prsntf_read_only, 0,
[
(ti_on_presentation_load,
[
(create_mesh_overlay, ":agent_hp_bg_overlay", "mesh_white_plane"),
(position_set_x, pos1, 100),
(position_set_y, pos1, 100),
(overlay_set_position, ":agent_hp_bg_overlay", pos1),
(overlay_set_size, ":agent_hp_bg_overlay", pos1),
(presentation_set_duration, 999999),
]),
]),

Mission Templates:
multiplayer_agent_hp_bar = (
0, 0, 0,
[],
[
(start_presentation, "prsnt_multiplayer_agent_hp_bar"),
])

I made sure to call multiplayer_agent_hp_bar in the appropriate mission template, but still nothing shows up except for the millions of debug messages from every frame.
 
Upvote 0

Vetrogor

Sergeant at Arms
I use this code in SP not sure if it works in MP
Python:
    (ti_battle_window_opened, 0, 0, [], [
      (start_presentation, "prsnt_battle_window"),
    ]),
If it doesn't work than try this
Python:
    (1, 0, 0, [
      (neg|presentation_is_active, "prsnt_battle_window"),
    ], [
      (start_presentation, "prsnt_battle_window"),
    ]),
 
Upvote 0
Top Bottom