OSP Code SP [WB] Sprint and Health Regen

Users who are viewing this thread

Ikaguia

Grandmaster Knight
Hey guys, here is my sprint code for anybody who wants, it's OSP:

Code:
slot_agent_energy				= 9991
slot_agent_original_agi			= 9992
Code:
common_sprint1 = (0, 1, 0, [(game_key_is_down, <sprint_key>),
						   (get_player_agent_no, ":player"),
						   (agent_slot_ge, ":player", slot_agent_energy, 0),
						   (neg|agent_slot_eq, ":player", slot_agent_energy, 0)],
	[(get_player_agent_no, ":player_agent"),
	 (agent_get_troop_id,":player", ":player_agent"),
	 (agent_get_slot, ":old_agi", ":player_agent", slot_agent_original_agi),
	 (store_attribute_level,":new_agi",":player",ca_agility),
	 (store_sub, ":change", ":old_agi", ":new_agi"),
	 (troop_raise_attribute,":player",ca_agility,":change"),#back to normal speed
	 (troop_raise_attribute,":player",ca_agility,":old_agi"),#double speed
	 (agent_get_slot, ":energy", ":player_agent", slot_agent_energy),
	 (val_sub, ":energy", 30),
	 (agent_set_slot, ":player_agent", slot_agent_energy, ":energy")])
common_sprint2 = (1, 0, 0, [],
	[(try_for_agents,":agent"),#agi restore to original
	 (agent_get_slot, ":old_agi", ":agent", slot_agent_original_agi),
	 (agent_get_troop_id,":troop", ":agent"),
	 (store_attribute_level,":new_agi",":troop",ca_agility),
	 (store_sub, ":change", ":old_agi", ":new_agi"),
	 (troop_raise_attribute,":troop",ca_agility,":change"),
	 #endurance restore
	 (agent_get_slot, ":staminna", ":agent", slot_agent_energy),
	 (store_skill_level,":skill",":troop","skl_endurance"),
	 (val_add, ":staminna", ":skill"),
	 (store_mul, ":energy", ":skill", 50),
	 (val_max, ":energy", 100),
	 (val_min, ":staminna", ":energy"),
	 (agent_set_slot, ":agent", slot_agent_energy, ":staminna"),
	 (try_end),])
common_sprint3 = (ti_on_agent_spawn, 0, 0, [],
	[(try_for_agents,":agent"),
	 (agent_get_troop_id,":troop", ":agent"),
	 (store_attribute_level,":agi",":troop",ca_agility),
	 (agent_set_slot, ":agent", slot_agent_original_agi, ":agi"),
	 (store_skill_level,":skill",":troop","skl_endurance"),
	 (store_mul, ":energy", ":skill", 50),
	 (val_max, ":energy", 100),
	 (agent_set_slot, ":agent", slot_agent_energy, ":energy"),
	 (try_end),])
common_sprint= [
	common_sprint1,
	common_sprint2,
	common_sprint3,
  ]

you need to make the skill "endurance" and you have to change the <sprint_key> for the key you want

you'll need to call it like this:

Code:
      ]),
    ]+ common_sprint,
  ),

# This template is used in party encounters and such.
# 
  (
    "conversation_encounter",0,-1,
    "Conversation_encounter",
    [( 0,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 1,mtef_visitor_source,af_override_fullhelm,0,1,[]),
     ( 2,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 3,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 4,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 5,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 6,mtef_visitor_source,af_override_fullhelm,0,1,[]),
     ( 7,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 8,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 9,mtef_visitor_source,af_override_fullhelm,0,1,[]),(10,mtef_visitor_source,af_override_fullhelm,0,1,[]),(11,mtef_visitor_source,af_override_fullhelm,0,1,[]),





Here is my Health Regen code, with credits to HokieBT for the original code:

Code:
common_regeneration = (1, 0, 0, [], [
	(get_player_agent_no,":player_agent"),
    (try_for_agents, ":agent"),
		(agent_is_active, ":agent"),
		(agent_is_alive, ":agent"),
		(agent_is_human, ":agent"),
		(neg|agent_is_routed, ":agent"),
		(agent_get_troop_id, ":troop", ":agent"),
		(try_begin),#player
			(eq, ":agent", ":player_agent"),
			(assign, ":regen_rate", "$player_regen_rate"),
		(else_try),#heroes
			(troop_is_hero,":troop"),
			(eq, "$hero_health_regen", 1),
			(try_begin),#kings
				(this_or_next|is_between, ":troop", kings_begin, kings_end),
				(is_between, ":troop", pretenders_begin, pretenders_end),
				(assign, ":regen_rate", 5),
			(else_try),#lords
				(is_between, ":troop", lords_begin, lords_end),
				(assign, ":regen_rate", 3),
			(else_try),#other heroes
				(assign, ":regen_rate", 2),
			(try_end),
		(else_try),#regulars
			(eq, "$regular_health_regen", 1),
			(assign, ":regen_rate", 1),
			(val_div, ":regen_rate", 2),
		(try_end),
		(gt, ":regen_rate", 0),
		(store_agent_hit_points, ":agent_health", ":agent", 0),
		(val_add, ":agent_health", ":regen_rate"),
		(agent_set_hit_points, ":agent", ":agent_health", 0),
    (try_end),
  ])
Code:
	  (assign, "$hero_health_regen", 0),
	  (assign, "$regular_health_regen", 0),
	  (assign, "$player_regen_rate", 0),

credits to Floris Mod Pack team for this options presentation:
Code:
  ("mod_option", 0, mesh_load_window, [
    (ti_on_presentation_load,
      [
        (presentation_set_duration, 999999),
        (set_fixed_point_multiplier, 1000),

        (str_clear, s0),
        (create_text_overlay, reg0, s0, tf_scrollable),
        (position_set_x, pos1, 50),
        (position_set_y, pos1, 50),
        (overlay_set_position, reg0, pos1),
        (position_set_x, pos1, 550),
        (position_set_y, pos1, 630),
        (overlay_set_area_size, reg0, pos1),
        (set_container_overlay, reg0),
		
		(assign, ":num_options", 3), #
		(val_add, ":num_options", 2), #For extra space for headings
		(assign, ":cur_y_shift", 50),
		(store_div, ":line_y_shift", ":cur_y_shift", 2),
		(store_mul, ":headings_y", ":cur_y_shift", ":num_options"),
		(store_sub, ":inputs_y", ":headings_y", 5),
		

        ## Headings
		(position_set_x, pos1, 50),
        
		(create_text_overlay, reg0, "@Enable Health regen for Heroes:", tf_vertical_align_center),
        (position_set_y, pos1, ":headings_y"),
        (overlay_set_position, reg0, pos1),
		(val_sub, ":headings_y", ":cur_y_shift"),

		(create_text_overlay, reg0, "@Enable Health regen for Regulars:", tf_vertical_align_center),
        (position_set_y, pos1, ":headings_y"),
        (overlay_set_position, reg0, pos1),
		(val_sub, ":headings_y", ":cur_y_shift"),

		(create_text_overlay, reg0, "@Health regen rate for Player:", tf_vertical_align_center),
        (position_set_y, pos1, ":headings_y"),
        (overlay_set_position, reg0, pos1),
		(val_sub, ":headings_y", ":cur_y_shift"),
		
        ## Inputs
        (position_set_x, pos1, 450),

		(val_sub, ":inputs_y", 9),	
		(create_check_box_overlay, reg0, "mesh_checkbox_off", "mesh_checkbox_on"),
        (position_set_y, pos1, ":inputs_y"),
        (overlay_set_position, reg0, pos1),
        (overlay_set_val, reg0, "$hero_health_regen"),
		(val_sub, ":inputs_y", ":cur_y_shift"),
		(val_sub, ":inputs_y", ":cur_y_shift"),
		(val_sub, ":inputs_y", 41),

        (create_check_box_overlay, reg0, "mesh_checkbox_off", "mesh_checkbox_on"),
        (position_set_y, pos1, ":inputs_y"),
        (overlay_set_position, reg0, pos1),
        (overlay_set_val, reg0, "$regular_health_regen"),   
        (val_sub, ":inputs_y", ":cur_y_shift"),	

        (create_number_box_overlay, reg0, 0, 51),
        (position_set_y, pos1, ":inputs_y"),
        (overlay_set_position, reg0, pos1),
        (overlay_set_val, reg0, "$player_regen_rate"),
        (val_sub, ":inputs_y", ":cur_y_shift"),
		
        (set_container_overlay, -1),

		(create_text_overlay, reg1, "@Health Regen^Options", tf_center_justify|tf_with_outline),
		(overlay_set_color, reg1, 0xFFFFFFFF),
		(position_set_x, pos1, 800),
        (position_set_y, pos1, 600),
        (overlay_set_position, reg1, pos1),
        (position_set_x, pos1, 2000),
        (position_set_y, pos1, 2000),
        (overlay_set_size, reg1, pos1),
		
        ## Buttons
        (create_game_button_overlay, "$g_presentation_obj_2", "@Done"),
        (position_set_x, pos1, 900),
        (position_set_y, pos1, 25),
        (overlay_set_position, "$g_presentation_obj_2", pos1),  

		(create_game_button_overlay, reg0, "@Restore Defaults"),
        (position_set_x, pos1, 735),
        (position_set_y, pos1, 25),
        (overlay_set_position, reg0, pos1),	
      ]),
    (ti_on_presentation_event_state_change,
      [
        (store_trigger_param_1, ":object"),
        (store_trigger_param_2, ":value"),		
		(try_begin),
          (eq, ":object", "$g_presentation_obj_2"), #Done
          (presentation_set_duration, 0),	  
		(else_try),
		  (store_add, ":overlay", "$g_presentation_obj_2", 1), #Restore Defaults
		  (eq, ":object", ":overlay"),
		  (assign, "$player_regen_rate", 0),
		  (assign, "$hero_health_regen", 0),
		  (assign, "$regular_health_regen", 0),
		  (start_presentation, "prsnt_mod_option"),
		(else_try),
		  (val_add, ":overlay", 1),
		  (eq, ":object", ":overlay"),
          (assign, "$hero_health_regen", ":value"),	   
        (else_try),
		  (val_add, ":overlay", 1),
		  (eq, ":object", ":overlay"),
          (assign, "$regular_health_regen", ":value"),	   
        (else_try),
		  (val_add, ":overlay", 1),
		  (eq, ":object", ":overlay"),
          (assign, "$player_regen_rate", ":value"),	   
        (try_end),
      ]),
    ]),


the only thing I haven't tested is the options presentation, this one is basically the same from FEMP but I removed all other options.
 
I don't know how multiplayer works, so, no, I can't do it, but somebody else could change it.

edit: also, anybody knows how to make a energy bar just like the health bar?
 
Make a custom read_only presentation.
Not sure how your code works - firstly because you're using negative slot indices, and secondly by using attribute/skill operations with agents rather than the troop templates which contain the actual stats.
 
Code:
(get_player_agent_no, ":player"),
						   (agent_slot_ge, ":player", slot_agent_energy, 0),
						   (neg|agent_slot_eq, ":player", slot_agent_energy, 0)],
	[(get_player_agent_no, ":player"),

You could simply use
Code:
(agent_slot_gt, ":player", slot_agent_energy, 0),

and you don't need to repeat the get_player_agent_no operation. :grin:
 
agent_slot_gt doesn't exist - use 1 as the comparison for ge instead.
And yes, (get_player_agent_no, ":player"), needs to be repeated in the conditions - otherwise it's out of scope.
 
I didn't know this doesn't existed, we can use agent_slot_ge 1 :grin:
and i completely forgot about the operations/conditions block, i haven't coded anything for a while so forgive me :razz:
 
well, I use the agent_slot_ge, 0 because it could be 0,5 eich isn't greater than 1 but is greater than 0
and yes it is tested but not in this version. last time I tested it was very buggy and it screwed up with the agi of companions.
Somebody said:
Make a custom read_only presentation.
I need to know how to do it, I've never handled with presentations on missions

Somebody said:
Not sure how your code works - firstly because you're using negative slot indices
ok, then use 9991 and 9992 instead of -1 and -2 xD

Somebody said:
and secondly by using attribute/skill operations with agents rather than the troop templates which contain the actual stats.
ups, I haven't thought of that, fixing now.

edit: ok, fixed first post

edit2: added explanation how to add
 
Do changes to troop templates affect agents once they are spawned? My understanding was that once the agents are spawned from the troop template, it wasn't referred to? For instance, other places I've seen mods edit troop attributes/skills happened before_mission_start or in "script_game_get_skill_modifier_for_troop"

I guess this is yet another way to ask, has the been tested? Is it proven to work?

 
last time I tested it didn't worked but I found the bug.

it is just like this: http://forums.taleworlds.com/index.php/topic,62230.0.html

ok, if you think it's better, change all try for agents for get_player_agent_no
 
cmpxchg8b said:
Caba`drin said:
Do changes to troop templates affect agents once they are spawned?
They do, yes. Agents don't have individual copies of attributes/skills/proficiencies... when those are needed, they are taken from the troop template.
Thanks for the clarification...I was somehow under the mistaken impression they were "set" in some way on spawn, based on the template at that time.

Ikaguia said:
last time I tested it didn't worked but I found the bug.

it is just like this: http://forums.taleworlds.com/index.php/topic,62230.0.html

ok, if you think it's better, change all try for agents for get_player_agent_no
Very good then! And yes, it does seem like there is no need for an agents loop, since this is player-specific.
 
Back
Top Bottom