OSP Kit SP [Modmerger] Killer Regeneration

Users who are viewing this thread

Windyplains

Grandmaster Knight
Killer Regeneration (1.1):
    I've seen a number of scripts that involve adding health regeneration to the game as well as arguments about how much of a cheat people consider it to be.  A number of those scripts give a player, and sometimes only the player, health regeneration over time which I think rewards hiding.  My goal here is to accomplish a middle ground that sets the playing field even for all troops on the field.
    You are free to add this to or modify it for your mods as you wish.  I'm welcome to any suggestions for improvement or refinement.

Features:
  • All units regain a percentage of health each time they kill a unit.  This means enemies as well as allies which makes it a fairly level playing field.  Different ranks of troop (regular, companion, lord, king) will receive differing percentages of health returned.  As a player you will receive the lowest amount simply to balance the fact you should be the most active killer on the field.
  • Strength provides a small boost to this percentage.
  • Leadership provides a small boost to this percentage for units that are not the leader.  You will not gain any benefit from this for yourself, but your troops will if you run with a decent leadership skill.
  • Factors in difficulty setting to raise health regeneration of enemies and lower health regeneration of allies.  I use in my game to keep things interesting, but this feature can be disabled in the constants.py file by changing the "wp_hr_factor_difficulty" constant to 0.
  • (New in 1.1) Separate global variables have been added so that a player can control whether they and/or AI receive this benefit.

Additional Credits:
  • Cdvader – For his initial health regeneration script that gave me inspiration to make one like this.

Modmerger Kit Download:
Killer Regeneration 1.1 - Modmerger Kit

Manual Installation:
  • module_constants.py - You can add this section at the bottom of the associated file.
Code:
## KILLER REGENERATION (1.1) begin
#  Rates listed below are per kill, not based on duration.  They are also % of health, not exact values.
wp_hr_player_rate                  = 5
wp_hr_strength_factor              = 4   # This is the value STR is divided by.  So 4 = .25% per point of Strength.
wp_hr_leadership_factor            = 2   # This is the value Leadership is divided by.  Only non-heroes gain this.
wp_hr_lord_rate                    = 15
wp_hr_companion_rate               = 10
wp_hr_king_rate                    = 20
wp_hr_common_rate                  = 5
wp_hr_elite_rate                   = 15  # Currently unused.
wp_hr_factor_difficulty            = 0   # This turns ON (1) or OFF (0) any code changes based on difficulty.
wp_hr_diff_enemy_bonus             = 4   # Amount the health regeneration of enemies is boosted by per difficulty rank.
wp_hr_diff_ally_penalty            = -3  # Amount the health regeneration of allies is reduced by per difficulty rank.
wp_hr_debug                        = 0   # This turns ON (1) or OFF (0) all of the debug messages.
## KILLER REGENERATION end
[*]module_mission_templates.py - The following trigger needs to be added to every mission template you want it to be included in.  If you're using a mod like the custom commander one with a "common triggers" definition you can likely just add it to that.
Code:
## KILLER REGENERATION (1.1) Begin - Windyplains
(ti_on_agent_killed_or_wounded, 0, 0, [],
    [
		(store_trigger_param_1, ":agent_victim"),
		(store_trigger_param_2, ":agent_killer"),
      
		# Is this a valid kill worth gaining morale?
		(agent_is_human, ":agent_victim"),
	  
		# Determine health amount to regenerate
		(try_begin), # Is it the player?
			(get_player_agent_no, ":agent_player"),
			(eq, ":agent_killer", ":agent_player"),
			(assign, ":health_regeneration", wp_hr_player_rate),
		(else_try), # Is it a companion?
			(is_between, ":agent_killer", companions_begin, companions_end),
			(assign, ":health_regeneration", wp_hr_companion_rate),
		(else_try), # Is it a lord?
			(is_between, ":agent_killer", lords_begin, lords_end),
			(assign, ":health_regeneration", wp_hr_lord_rate),
		(else_try), # Is it a king?
			(is_between, ":agent_killer", kings_begin, kings_end),
			(assign, ":health_regeneration", wp_hr_king_rate),
		(else_try), # This should catch all common soldiers, horses, etc.
			# This section commented out because it is designed for use with "elite units" which most mods do not use.
			# (try_begin),  
				# (agent_get_troop_id, ":troop_no", ":agent_killer"), # Is this an elite unit?
				# (troop_slot_eq, ":troop_no", slot_troop_is_elite, 1),
				# (assign, ":health_regeneration", wp_hr_elite_rate),
			# (else_try),
				# (assign, ":health_regeneration", wp_hr_common_rate),
			# (try_end),
			(assign, ":health_regeneration", wp_hr_common_rate),
			# This adds a small bonus to all non-heroes based on the leadership of their owner.
			(agent_get_team, ":team_killer", ":agent_killer"),
			(team_get_leader, ":agent_leader", ":team_killer"),
			(agent_get_troop_id, ":troop_leader", ":agent_leader"),
			(store_skill_level, ":leadership", "skl_leadership", ":troop_leader"),
			(assign, reg4, ":leadership"), # stored for debug display purposes.
			(val_div, ":leadership", wp_hr_leadership_factor),
			(val_add, ":health_regeneration", ":leadership"),
		(try_end),
	  
		# Adds in Strength as a bonus or penalty.  (STR - 10) / wp_hr_strength_factor
		(agent_get_troop_id, ":troop_killer", ":agent_killer"),
		(store_attribute_level, ":strength", ":troop_killer", ca_strength),
		(val_sub, ":strength", 10),
		(val_div, ":strength", wp_hr_strength_factor),
		(val_add, ":health_regeneration", ":strength"),
	  
		# Changes health regeneration based on this factor.
		(try_begin),
			(eq, wp_hr_factor_difficulty, 1),  # Is this difficulty script even being used.
			(assign, ":bonus_difficulty", "$g_wp_difficulty"),
			(try_begin),
				(agent_is_ally, ":agent_killer"),
				(val_mul, ":bonus_difficulty", wp_hr_diff_ally_penalty),
			(else_try),
				(val_mul, ":bonus_difficulty", wp_hr_diff_enemy_bonus),
			(try_end),
			(val_add, ":health_regeneration", ":bonus_difficulty"),
		(try_end),
	  
		(val_max, ":health_regeneration", 0), # We don't want a negative health regeneration.
	  
		# Remove regeneration value if option not enabled for this unit type.
		(try_begin),  # Check if this is the player and regeneration is disabled.
			(eq, ":agent_killer", ":agent_player"),
			(eq, "$g_wp_player_hr_active", 0),
			(assign, ":health_regeneration", 0),
		(else_try),   # If not player assume AI troop and check if AI regen is disabled.
			(neq, ":agent_killer", ":agent_player"),  # To prevent player enabled, AI disabled conflicts.
			(eq, "$g_wp_ai_hr_active", 0),
			(assign, ":health_regeneration", 0),
		(try_end),
	  
		# Displays debug messages if turned on.
		(try_begin), 
			(eq, wp_hr_debug, 1),
			(str_store_troop_name, s1, ":troop_killer"),
			(assign, reg0, ":health_regeneration"),
			(assign, reg1, ":strength"),
			(try_begin), (ge, ":leadership", 10), (assign, ":leadership", -1), (try_end), # If no leadership bonus exists put in a default value.
			(assign, reg2, ":leadership"),
			(display_message, "@DEBUG (Health Regen): Agent leadership skill is {reg4}."),
			(try_begin), (eq, wp_hr_factor_difficulty, 1),(assign, reg3, ":bonus_difficulty"), (else_try), (assign, reg3, 0), (try_end),  # Get difficulty bonus OR use 0.
			(display_message, "@DEBUG (Health Regen): {s1} regains {reg0}% health.  = +{reg1}% STR +{reg2}% Lead + {reg3}% Difficulty."),
		(try_end),
	  
		# Regenerates the given health amount.
		(ge, ":health_regeneration", 1),
		(store_agent_hit_points, ":current_health", ":agent_killer", 0),
		(val_add, ":current_health", ":health_regeneration"),
		(agent_set_hit_points, ":agent_killer", ":current_health", 0),
    ])
[*]variables.txt - The following global variables need to be added.
Code:
   g_wp_player_hr_active      # Set to 0 to prevent player regeneration.  1 to activate.
   g_wp_ai_hr_active          # Set to 0 to prevent AI regeneration.  1 to activate.
   g_wp_difficulty            # Changes whether the regeneration is better or worse.
 
Factors in difficulty setting to raise health regeneration of enemies and lower health regeneration of allies.  I use in my game to keep things interesting, but this feature can be disabled in the constants.py file by changing the "wp_hr_factor_difficulty" constant to 0.

Can this help to balance battle? Generally, player troop have high superiority. Maybe, this can same terms...
 
Idibil said:
Factors in difficulty setting to raise health regeneration of enemies and lower health regeneration of allies.  I use in my game to keep things interesting, but this feature can be disabled in the constants.py file by changing the "wp_hr_factor_difficulty" constant to 0.

Can this help to balance battle? Generally, player troop have high superiority. Maybe, this can same terms...
That seemed to be the case for me.  Usually I was changing that difficulty factor between -1 (easy - which actually helps you out) to 2 (very hard - which almost negates your benefits while enhancing the enemies).  I was looking to have something that wouldn't be overpowered and considering it helps everyone I think it isn't. 

It also tends to keep lords and companions in fights a bit longer as long as they aren't dumb enough to charge into the middle of a mob.  This uses a % of your health vs. an absolute so as not to penalize players who built themselves around being a Strength/Ironflesh character.
 
Faunus said:
If an unit is mounted and he kills someone, why not add health to his horse as well?
That could easily be added.  At the moment it does not, but if your horse tramples someone to death it should gain the health (instead of you).
 
Woah, i will certainly use it. Thanks for the contribution...
 
Version 1.1 released

Changes:
  • Converted to Modmerger format for easier installation and updating.
  • Seperate global variables added to control if this benefit applies to player and/or AI for player control.

Original post updated with download information.  Manual instructions kept since this is easy enough to add manually, but I changed this to modmerger format while trying to figure out how to use that system and thought others may prefer it this way.

Oh, and this should probably move to the OSP scripts forum when a mod has a chance.
 
Make it so every hit will restore health of the hitting character by 50% of the damage delivered, but not higher than full health.

Damage delivered with ranged weapons does not count.

And make it a multiplayer battle mode - Battle of Vampires. :smile:
 
Probably way too late...but I can't get modmerger to work (at all vscode says it's full of errors so python doesn't read it)

so My actual question is : which missions am I supposed to add the triggers to ?
 
Probably way too late...but I can't get modmerger to work (at all vscode says it's full of errors so python doesn't read it)

so My actual question is : which missions am I supposed to add the triggers to ?
You will need to add the triggers to every mission you want the triggers to work inside of. Basically every single combat mission.
The easiest way is to name the trigger, and then add that name to the list of triggers.

Code:
# Notice this is inside the module_mission_templates.py file but BEFORE the mission_templates = [] range
# A native example would be multiplayer_server_check_belfry_movement
## KILLER REGENERATION (1.1) Begin - Windyplains
k_regen = (ti_on_agent_killed_or_wounded, 0, 0, [],
    [
        (store_trigger_param_1, ":agent_victim"),
        (store_trigger_param_2, ":agent_killer"),
  
        # Is this a valid kill worth gaining morale?
        (agent_is_human, ":agent_victim"),
  
        # Determine health amount to regenerate
        (try_begin), # Is it the player?
            (get_player_agent_no, ":agent_player"),
            (eq, ":agent_killer", ":agent_player"),
            (assign, ":health_regeneration", wp_hr_player_rate),
        (else_try), # Is it a companion?
            (is_between, ":agent_killer", companions_begin, companions_end),
            (assign, ":health_regeneration", wp_hr_companion_rate),
        (else_try), # Is it a lord?
            (is_between, ":agent_killer", lords_begin, lords_end),
            (assign, ":health_regeneration", wp_hr_lord_rate),
        (else_try), # Is it a king?
            (is_between, ":agent_killer", kings_begin, kings_end),
            (assign, ":health_regeneration", wp_hr_king_rate),
        (else_try), # This should catch all common soldiers, horses, etc.
            # This section commented out because it is designed for use with "elite units" which most mods do not use.
            # (try_begin),
                # (agent_get_troop_id, ":troop_no", ":agent_killer"), # Is this an elite unit?
                # (troop_slot_eq, ":troop_no", slot_troop_is_elite, 1),
                # (assign, ":health_regeneration", wp_hr_elite_rate),
            # (else_try),
                # (assign, ":health_regeneration", wp_hr_common_rate),
            # (try_end),
            (assign, ":health_regeneration", wp_hr_common_rate),
            # This adds a small bonus to all non-heroes based on the leadership of their owner.
            (agent_get_team, ":team_killer", ":agent_killer"),
            (team_get_leader, ":agent_leader", ":team_killer"),
            (agent_get_troop_id, ":troop_leader", ":agent_leader"),
            (store_skill_level, ":leadership", "skl_leadership", ":troop_leader"),
            (assign, reg4, ":leadership"), # stored for debug display purposes.
            (val_div, ":leadership", wp_hr_leadership_factor),
            (val_add, ":health_regeneration", ":leadership"),
        (try_end),
  
        # Adds in Strength as a bonus or penalty.  (STR - 10) / wp_hr_strength_factor
        (agent_get_troop_id, ":troop_killer", ":agent_killer"),
        (store_attribute_level, ":strength", ":troop_killer", ca_strength),
        (val_sub, ":strength", 10),
        (val_div, ":strength", wp_hr_strength_factor),
        (val_add, ":health_regeneration", ":strength"),
  
        # Changes health regeneration based on this factor.
        (try_begin),
            (eq, wp_hr_factor_difficulty, 1),  # Is this difficulty script even being used.
            (assign, ":bonus_difficulty", "$g_wp_difficulty"),
            (try_begin),
                (agent_is_ally, ":agent_killer"),
                (val_mul, ":bonus_difficulty", wp_hr_diff_ally_penalty),
            (else_try),
                (val_mul, ":bonus_difficulty", wp_hr_diff_enemy_bonus),
            (try_end),
            (val_add, ":health_regeneration", ":bonus_difficulty"),
        (try_end),
  
        (val_max, ":health_regeneration", 0), # We don't want a negative health regeneration.
  
        # Remove regeneration value if option not enabled for this unit type.
        (try_begin),  # Check if this is the player and regeneration is disabled.
            (eq, ":agent_killer", ":agent_player"),
            (eq, "$g_wp_player_hr_active", 0),
            (assign, ":health_regeneration", 0),
        (else_try),   # If not player assume AI troop and check if AI regen is disabled.
            (neq, ":agent_killer", ":agent_player"),  # To prevent player enabled, AI disabled conflicts.
            (eq, "$g_wp_ai_hr_active", 0),
            (assign, ":health_regeneration", 0),
        (try_end),
  
        # Displays debug messages if turned on.
        (try_begin),
            (eq, wp_hr_debug, 1),
            (str_store_troop_name, s1, ":troop_killer"),
            (assign, reg0, ":health_regeneration"),
            (assign, reg1, ":strength"),
            (try_begin), (ge, ":leadership", 10), (assign, ":leadership", -1), (try_end), # If no leadership bonus exists put in a default value.
            (assign, reg2, ":leadership"),
            (display_message, "@DEBUG (Health Regen): Agent leadership skill is {reg4}."),
            (try_begin), (eq, wp_hr_factor_difficulty, 1),(assign, reg3, ":bonus_difficulty"), (else_try), (assign, reg3, 0), (try_end),  # Get difficulty bonus OR use 0.
            (display_message, "@DEBUG (Health Regen): {s1} regains {reg0}% health.  = +{reg1}% STR +{reg2}% Lead + {reg3}% Difficulty."),
        (try_end),
  
        # Regenerates the given health amount.
        (ge, ":health_regeneration", 1),
        (store_agent_hit_points, ":current_health", ":agent_killer", 0),
        (val_add, ":current_health", ":health_regeneration"),
        (agent_set_hit_points, ":agent_killer", ":current_health", 0),
    ])

# This _inside_ the list of missions
mission_templates =[
    (
    "some_mission",0,-1,
    "a Mission.",
    [
#     (0,mtef_attackers,0,aif_start_alarmed,5,[]),
     ],
    [
    (1, 0, 0, [(mission_cam_set_mode, 1),
        (entry_point_get_position, pos3, 3),
        (mission_cam_set_position, pos3)], []
    ),
    k_regen, # just add the named trigger constant followed by a comma
      (ti_tab_pressed, 0, 0, [],
       [(finish_mission,0)]),
    ],
  ),
]
 
You will need to add the triggers to every mission you want the triggers to work inside of. Basically every single combat mission.
The easiest way is to name the trigger, and then add that name to the list of triggers.

Code:
# Notice this is inside the module_mission_templates.py file but BEFORE the mission_templates = [] range
# A native example would be multiplayer_server_check_belfry_movement
## KILLER REGENERATION (1.1) Begin - Windyplains
k_regen = (ti_on_agent_killed_or_wounded, 0, 0, [],
    [
        (store_trigger_param_1, ":agent_victim"),
        (store_trigger_param_2, ":agent_killer"),
 
        # Is this a valid kill worth gaining morale?
        (agent_is_human, ":agent_victim"),
 
        # Determine health amount to regenerate
        (try_begin), # Is it the player?
            (get_player_agent_no, ":agent_player"),
            (eq, ":agent_killer", ":agent_player"),
            (assign, ":health_regeneration", wp_hr_player_rate),
        (else_try), # Is it a companion?
            (is_between, ":agent_killer", companions_begin, companions_end),
            (assign, ":health_regeneration", wp_hr_companion_rate),
        (else_try), # Is it a lord?
            (is_between, ":agent_killer", lords_begin, lords_end),
            (assign, ":health_regeneration", wp_hr_lord_rate),
        (else_try), # Is it a king?
            (is_between, ":agent_killer", kings_begin, kings_end),
            (assign, ":health_regeneration", wp_hr_king_rate),
        (else_try), # This should catch all common soldiers, horses, etc.
            # This section commented out because it is designed for use with "elite units" which most mods do not use.
            # (try_begin),
                # (agent_get_troop_id, ":troop_no", ":agent_killer"), # Is this an elite unit?
                # (troop_slot_eq, ":troop_no", slot_troop_is_elite, 1),
                # (assign, ":health_regeneration", wp_hr_elite_rate),
            # (else_try),
                # (assign, ":health_regeneration", wp_hr_common_rate),
            # (try_end),
            (assign, ":health_regeneration", wp_hr_common_rate),
            # This adds a small bonus to all non-heroes based on the leadership of their owner.
            (agent_get_team, ":team_killer", ":agent_killer"),
            (team_get_leader, ":agent_leader", ":team_killer"),
            (agent_get_troop_id, ":troop_leader", ":agent_leader"),
            (store_skill_level, ":leadership", "skl_leadership", ":troop_leader"),
            (assign, reg4, ":leadership"), # stored for debug display purposes.
            (val_div, ":leadership", wp_hr_leadership_factor),
            (val_add, ":health_regeneration", ":leadership"),
        (try_end),
 
        # Adds in Strength as a bonus or penalty.  (STR - 10) / wp_hr_strength_factor
        (agent_get_troop_id, ":troop_killer", ":agent_killer"),
        (store_attribute_level, ":strength", ":troop_killer", ca_strength),
        (val_sub, ":strength", 10),
        (val_div, ":strength", wp_hr_strength_factor),
        (val_add, ":health_regeneration", ":strength"),
 
        # Changes health regeneration based on this factor.
        (try_begin),
            (eq, wp_hr_factor_difficulty, 1),  # Is this difficulty script even being used.
            (assign, ":bonus_difficulty", "$g_wp_difficulty"),
            (try_begin),
                (agent_is_ally, ":agent_killer"),
                (val_mul, ":bonus_difficulty", wp_hr_diff_ally_penalty),
            (else_try),
                (val_mul, ":bonus_difficulty", wp_hr_diff_enemy_bonus),
            (try_end),
            (val_add, ":health_regeneration", ":bonus_difficulty"),
        (try_end),
 
        (val_max, ":health_regeneration", 0), # We don't want a negative health regeneration.
 
        # Remove regeneration value if option not enabled for this unit type.
        (try_begin),  # Check if this is the player and regeneration is disabled.
            (eq, ":agent_killer", ":agent_player"),
            (eq, "$g_wp_player_hr_active", 0),
            (assign, ":health_regeneration", 0),
        (else_try),   # If not player assume AI troop and check if AI regen is disabled.
            (neq, ":agent_killer", ":agent_player"),  # To prevent player enabled, AI disabled conflicts.
            (eq, "$g_wp_ai_hr_active", 0),
            (assign, ":health_regeneration", 0),
        (try_end),
 
        # Displays debug messages if turned on.
        (try_begin),
            (eq, wp_hr_debug, 1),
            (str_store_troop_name, s1, ":troop_killer"),
            (assign, reg0, ":health_regeneration"),
            (assign, reg1, ":strength"),
            (try_begin), (ge, ":leadership", 10), (assign, ":leadership", -1), (try_end), # If no leadership bonus exists put in a default value.
            (assign, reg2, ":leadership"),
            (display_message, "@DEBUG (Health Regen): Agent leadership skill is {reg4}."),
            (try_begin), (eq, wp_hr_factor_difficulty, 1),(assign, reg3, ":bonus_difficulty"), (else_try), (assign, reg3, 0), (try_end),  # Get difficulty bonus OR use 0.
            (display_message, "@DEBUG (Health Regen): {s1} regains {reg0}% health.  = +{reg1}% STR +{reg2}% Lead + {reg3}% Difficulty."),
        (try_end),
 
        # Regenerates the given health amount.
        (ge, ":health_regeneration", 1),
        (store_agent_hit_points, ":current_health", ":agent_killer", 0),
        (val_add, ":current_health", ":health_regeneration"),
        (agent_set_hit_points, ":agent_killer", ":current_health", 0),
    ])

# This _inside_ the list of missions
mission_templates =[
    (
    "some_mission",0,-1,
    "a Mission.",
    [
#     (0,mtef_attackers,0,aif_start_alarmed,5,[]),
     ],
    [
    (1, 0, 0, [(mission_cam_set_mode, 1),
        (entry_point_get_position, pos3, 3),
        (mission_cam_set_position, pos3)], []
    ),
    k_regen, # just add the named trigger constant followed by a comma
      (ti_tab_pressed, 0, 0, [],
       [(finish_mission,0)]),
    ],
  ),
]
thanks for the reply...but I can't figure out why I can't build modules so I'll have to figure that one out first I swear trying anything custom in this game is more pain then getting jackhammered in the stomack.
 
thanks for the reply...but I can't figure out why I can't build modules so I'll have to figure that one out first I swear trying anything custom in this game is more pain then getting jackhammered in the stomack.
Make sure you follow the tutorials for setting up and getting started with the module system. Once you get used to it, it's easy-peasy.



https://earendil_ardamire.gitlab.io/modding-guide/
 
Back
Top Bottom