OSP Code QoL Personal Kill Count

Users who are viewing this thread

Artam

Sergeant at Arms
M&BWBWF&SNWVC
Hello everyone,

I am noob at moding but with SupaNinjaMan's help, I managed to create personal kill counter in battle. Same as Prophecy of Pendor mod but little uglier. In battle, Kill count displays the amount of troops you killed or wounded.

Update #1: I've made adjustments to the code according to Dj_FRedy's comments.

Update #2: I've made the personal kill count more visible and less ugly. I am sure there is better way to do this but at the moment this is the best I can do.

Update #3: I've made the personal kill count more visible and less ugly. And I've greatly reduced the number of mesh-related garbage scripts.

Screenshot in spoiler
Source code in spoiler,
Search "(agent_set_slot, ":cur_agent", slot_agent_map_overlay_id, 0)", in module_presentations.py, then insert the line as following:
Code:
        (try_begin),
          (gt, ":cur_time", 200),
          (game_key_clicked, gk_view_orders),
          (try_for_agents, ":cur_agent"),
            (agent_set_slot, ":cur_agent", slot_agent_map_overlay_id, 0),
          (try_end),
          (presentation_set_duration, 0),
######################################################################################
### BEGIN + PERSONAL KILL COUNT by Artam
######################################################################################
          (start_presentation, "prsnt_killcount"),
######################################################################################
### END - PERSONAL KILL COUNT
###################################################################################### 
        (try_end),
Paste the following into module_presentations.py:
Code:
######################################################################################
### BEGIN + PERSONAL KILL COUNT by Artam
######################################################################################
  ("killcount",prsntf_read_only,0,[
      (ti_on_presentation_load,
       [
		(assign, "$presentation_killcount"),
		(set_fixed_point_multiplier, 1000),
		
		(create_mesh_overlay, "$g_presentation_obj_1", "mesh_white_plane"),
		(overlay_set_color, "$g_presentation_obj_1", 0x000000),
		(overlay_set_alpha, "$g_presentation_obj_1", 0x80),
		(position_set_x, pos1, 4200),
		(position_set_y, pos1, 1700),
		(overlay_set_size, "$g_presentation_obj_1", pos1),
		(position_set_x, pos1, 0),
		(position_set_y, pos1, 700),
		(overlay_set_position, "$g_presentation_obj_1", pos1),

		(create_text_overlay, "$g_presentation_obj_2", s1, tf_with_outline|tf_left_align),
		(overlay_set_color, "$g_presentation_obj_2", 0xFFFFFF),
		(overlay_set_position, "$g_presentation_obj_2", pos1),
		
		(presentation_set_duration, 999999),
       ]),

      (ti_on_presentation_run,
       [
		(get_player_agent_no, ":player_agent"),
		(agent_get_kill_count, reg1, ":player_agent", 1),           #SupaNinjaMan
		(agent_get_kill_count, ":kill_count", ":player_agent"),     #SupaNinjaMan
		(agent_get_kill_count, ":wound_count", ":player_agent", 1), #SupaNinjaMan
		(store_add, reg1, ":kill_count", ":wound_count"),
		(str_store_string, s1, "@{reg1} kills"),
		(overlay_set_text, "$g_presentation_obj_2", s1),
       ]),
     ]),
######################################################################################
### END - PERSONAL KILL COUNT
######################################################################################
Search "lead_charge", "village_attack_bandits", "village_raid", "besiege_inner_battle_castle", "castle_attack_walls_defenders_sally", "castle_attack_walls_belfry", "castle_attack_walls_ladder" and "bandit_lair" in module_mission_templates.py and paste "(0, 0, ti_once, [], [(start_presentation, "prsnt_killcount")]), # Personal Kill Count" below  of common_battle_order_*. Just as follows:
Code:
      common_battle_order_panel,
      common_battle_order_panel_tick,
      (0, 0, ti_once, [], [(start_presentation, "prsnt_killcount")]), # Personal Kill Count

As I mentioned above I am 99.9% noob at coding and as you already figure that I am not native English speaker but I think all of you understand what I meant.:smile: Feel free to use and modify. (If you actually modify please share your code here so I can learn. )
  • I couldn't do this personal kill count thing without help of rubik's troop ratio bar presentation and SupaNinjaMan, I thank them sincerely.
  • I thank Dj FRedy for his kind comments and guidance.

Cheers,
 

Antonis

Marquis
WBWF&SVCNW
Cool! I saw your post in the Mod makers thread and though "That should be made into a kit!"
You took care of it excellently.  :smile:
 

Dj_FRedy

Archduke
M&BWBNWVCWF&S
Welcome to the moding of warband Artam, if you allow me to comment a couple of points regarding your code:

I don't think it's going to work properly. Check the global variable '$presentation_killcount_active'.
Do not use 'try_begin' if there is no condition, e.g. 'eq'.
You are also using redundant code in 'ti_on_presentation_load', you don't need to recover the deaths in this trigger, declaring it in 'ti_on_presentation_run' is enough.
(assign, reg1, 1), this is not necessary...
If you want your code to be displayed correctly in the forum you will have to tabulate/indent it correctly (check in Notepad++ 'View/Show Symbol/Show White Space and TAB').
If you need any explanation of any point do not hesitate to ask.  :wink:
 

Artam

Sergeant at Arms
M&BWBWF&SNWVC
Hello Dj_FRedy,

Thank you for your kind comments. If I understood you correctly, I've made adjustments to the code according to your advice.  Please see spoiler below.

Code:
## Start - Personal Kill Count
  ("killcount",prsntf_read_only,0,[
      (ti_on_presentation_load,
       [
		(assign, "$presentation_killcount_active", 1),
		(set_fixed_point_multiplier, 1000),
		(create_text_overlay, "$g_presentation_obj_1", s1),
		(overlay_set_color, "$g_presentation_obj_1", 0xFFFFFF),
		(position_set_x, pos1, 10),
		(position_set_y, pos1, 700),
		(overlay_set_position, "$g_presentation_obj_1", pos1),
		
		(presentation_set_duration, 999999),
       ]),
	   
      (ti_on_presentation_run,
       [
		(get_player_agent_no, ":player_agent"),
		(agent_get_kill_count, reg1, ":player_agent", 1),           #SupaNinjaMan
		(agent_get_kill_count, ":kill_count", ":player_agent"),     #SupaNinjaMan
		(agent_get_kill_count, ":wound_count", ":player_agent", 1), #SupaNinjaMan
		(store_add, reg1, ":kill_count", ":wound_count"),
		(str_store_string, s1, "@Kills: {reg1}"),
		(overlay_set_text, "$g_presentation_obj_1", s1),
		
		(try_begin),
		  (eq, "$presentation_killcount", 1),
		  (game_key_clicked, gk_view_orders),
		  (assign, "$presentation_killcount", 0),
		  (presentation_set_duration, 0),
		  (start_presentation, "prsnt_battle"),
		(try_end),
       ]),
     ]),
## End - Personal Kill Count

Where can I check the global variable? If you're talking about the process_global_variables.py, I couldn't find '$presentation_killcount_active' in there.

Also I tested first version and this version of the codes in field battle scene, before I post. It works. I'm assuming code will work in siege battle scene.

Kind Regards,
 

Dj_FRedy

Archduke
M&BWBNWVCWF&S
Now the code looks better... yet:
$presentation_killcount_active' != '$presentation_killcount' should have the same name.
In the trigger 'ti_on_presentation_load' we assign and in 'ti_on_presentation_run' we verify and assign again, but this time with a value of 0, so that the counter is not shown while we are in the presentation 'battle'.
You should also add the global variable to your 'variables.txt' file, at the end of the file it would be fine.
 

Artam

Sergeant at Arms
M&BWBWF&SNWVC
Dj_FRedy, I hope I don't bother you too much. So I updated the codes in main post. I copy presentation template from Rubik's Troop Ratio Bar. I checked variables.txt file and found presentation_killcount_active.

Also I updated main post and give you credit.  :grin:

Kind Regards,
 

Eärendil Ardamírë

Subforum Moderator
WBWF&SM&B
'it doesn't seem to work' is not really an useful information. Are you getting error messages? Is it compiling fine or with errors? Or is just nothing happening in-game?

Edit: You seem to have added the tuple at the mission templates just seven times, although the OP above counts 8 mission templates to which to add it. Could be that you tested it in the missed one.
 
Last edited:
I know the presentation is about where it is attached, if it is placed on a better line in the lead_charge mission the problem will disappear. yes you also need to add variables
'it doesn't seem to work' is not really an useful information. Are you getting error messages? Is it compiling fine or with errors? Or is just nothing happening in-game?
 
Last edited:

Mauromagno Patriota

Sergeant Knight
WBNWVC
there is a variable that is not used, I just commented and compiled it and it works fine, although with allies it doesn't work
# (assign, "$presentation_killcount"),
at the beginning of the presentation
 

KnowsCount

Regular
'it doesn't seem to work' is not really an useful information. Are you getting error messages? Is it compiling fine or with errors? Or is just nothing happening in-game?
It does not work in game. Compiling went well. Ah – I will find out that which I missed. Sorry!

if it is placed on a better line in the lead_charge mission the problem will disappear.
So.. I misplaced my presentation lines?

# (assign, "$presentation_killcount"),
Do I also comment this out?
 
Top Bottom