OSP Code Combat HP Shields - Give troops thousands of HPs!

Users who are viewing this thread

Pumpkin Lord

Aye Forge,

I decided to release the codes of some of the features I once released in Vyrn OSP about a year ago or so.




HP shield works in giving agents 'hp shields' that makes the agents basicly immortal until their HP shield is broken. After that, agents will start to get hit as they should. You can give any NPC the whatever HP you want. The amount of HP shield a troop has is set in game_start scripts but you can make it dependant on STR attiribute too.

I wanted to control each NPC manually since it was an attempt on hardcore fantasy RPG. Feel free to use or edit any part you want as long as you give credits.

Having said that, I am no coder in IRL and code could use improvements. It is a WIP. Do whatever you want with it.

Happy modding!




1 - ) Firstly, add these two mission triggers on mission_templates.py and later on add the name of the triggers on any template you want.

vyrn_hp_shield - > Basicly converts the hp shield that is set in game_scripts to the relevant agents on the scene
vyrn_hp_shield1 - > Handles the hp shield in runtime. It will make the result of any damage that is done on an agent with a hp shield that is still not broken (Greater than 0) zero.
vyrn_hp_shield2 - > Somehow I needed this. I don't know, I am not a nitpicky coder. It just makes the damage default again.


Code:
vyrn_hp_shield = (
 ti_on_agent_spawn, 0, 0, [],
  [
		(store_trigger_param_1, ":spawned"),
  
		(agent_is_active, ":spawned"),
		(agent_is_alive, ":spawned"),
		(agent_is_human, ":spawned"),
		(agent_get_troop_id, ":spawnedtrp", ":spawned"),
		(troop_get_slot, ":hp_sh", ":spawnedtrp", slot_troop_hp_shield),
		(agent_set_slot, ":spawned", slot_agent_hp_shield, ":hp_sh"),
	 
		#(assign, reg2, ":hp_sh"),
		#(str_store_troop_name, s33, ":spawnedtrp"),
		#(display_message, "@{s33}: {reg2} set hp shield."), 	  
    ])

vyrn_hp_shield1 = (
 ti_on_agent_hit, 0, 0, [],
  [  
	(store_trigger_param_1, ":game1"),
	(store_trigger_param_3, ":damage1"),
  
		(agent_is_active, ":game1"),
		(agent_is_alive, ":game1"),
		(agent_is_human, ":game1"),
		(agent_get_slot, ":has_shield1", ":game1", slot_agent_hp_shield),
		(gt, ":has_shield1", 0),
		(agent_get_slot, ":current_hp_shield", ":game1", slot_agent_hp_shield),
		(val_sub, ":current_hp_shield", ":damage1"),
	        (agent_set_slot, ":game1", slot_agent_hp_shield, ":current_hp_shield"),	 
		(assign, reg3, ":current_hp_shield"),
	    # (display_message, "@Hp shield: {reg3} left."), 
		(try_begin),
			(ge, ":damage1", 5),
			(agent_set_animation, ":game1", "anim_vyrn_hit_effect"),
		(try_end),
		(set_trigger_result, 0),
    ])	

vyrn_hp_shield2 = (
  ti_on_agent_hit, 0, 0, [],
  [ 
		(store_trigger_param_1, ":game2"),
		(store_trigger_param_3, ":damage2"),
		(agent_is_active, ":game2"),
		(agent_is_alive, ":game2"),
		(agent_is_human, ":game2"),
		(agent_get_slot, ":has_shield2", ":game2", slot_agent_hp_shield),
		(eq, ":has_shield2", 0),
		(set_trigger_result, ":damage2"), 	  
    ])

2 - ) After that, add these to anywhere in module_constants.py

Code:
#VYRN Constants
slot_agent_hp_shield = 27
slot_troop_hp_shield = 28

3 - ) Then, we need to determine the amount of HPs each troop has. You can basicly do that in game_start in module_scripts.py. Here is an example of how I did:

Code:
(try_begin),	  
   (troop_set_slot, "trp_player", slot_troop_hp_shield, 100),
   (troop_set_slot, "trp_blue_raven", slot_troop_hp_shield, 5000),
(try_end),

Cheers! :party:
 
Just a small hint.
Agents on agent-triggers, aswell as in try_for_agent loops, are allways active.
(on agent-triggers, they are also alive... except for the dealer agent on ti_on_agent_hit and ti_on_shield_hit in some cases)
No need to check for it.

Also... troop_set_slot can not fail, so there's no reason to put it inside a try-block.
 
Modified it a bit:

Code:
hp_shield_init = (ti_on_agent_spawn, 0, 0, [
  (store_trigger_param_1, ":agent"),
  (agent_is_human, ":agent"),
  (agent_get_troop_id, ":troop_id", ":agent"),
  (troop_get_slot, ":has_shield", ":troop_id", slot_troop_hp_shield),
  (gt, ":has_shield", 0)],
  
  [
    (store_trigger_param_1, ":agent"),
    (agent_is_human, ":agent"),
    (agent_get_troop_id, ":troop_id", ":agent"),
    (troop_get_slot, ":shield", ":troop_id", slot_troop_hp_shield),
    (agent_set_slot, ":agent", slot_agent_hp_shield_active, 1),
    (agent_set_slot, ":agent", slot_agent_hp_shield, ":shield"),

    (assign, reg2, ":shield"),
    (str_store_troop_name, s33, ":troop_id"),
    (display_message, "@{s33}: {reg2} set hp shield."),   

  ])

hp_shield_trigger = (ti_on_agent_hit, 0, 0, [
  (store_trigger_param_1, ":agent"),
  (agent_is_human, ":agent"),
  (agent_slot_eq, ":agent", slot_agent_hp_shield_active, 1)],
  
  [  
    (store_trigger_param_1, ":agent"),
    (store_trigger_param_3, ":damage"),
  
    (agent_is_human, ":agent"),
    (agent_get_slot, ":current_hp_shield", ":agent", slot_agent_hp_shield),
    (try_begin),
      (gt, ":current_hp_shield", 0),
      (val_sub, ":current_hp_shield", ":damage"),
      (val_max, ":current_hp_shield", 0),
      (agent_set_slot, ":agent", slot_agent_hp_shield, ":current_hp_shield"),  
    (else_try),
      (agent_set_slot, ":agent", slot_agent_hp_shield_active, 0),
    (try_end),
      (assign, reg3, ":current_hp_shield"),
      (display_message, "@Hp shield: {reg3} left."), 
    (set_trigger_result, 0),
  ]) 

Main changes are discarding the third trigger, moving some code to the condition block and adding another slot, "slot_agent_hp_shield_active", to make the initial check and use this for the condition block.

Only issue I have is that when the player hits someone with this HP shield, they will get a message saying, "Delivered 0 damage", which is not great.

I tried adding a condition at the end, but that doesnt seem to work:

Code:
    (agent_get_player_id, ":player", ":agent"),
    (try_begin),
      (eq, ":dealer", ":player"),
      (assign, reg19, ":damage"),
      (set_show_messages, 0),
      (set_trigger_result, 0),
      (set_show_messages, 1),
      (str_store_string, "@Delivered {reg19} damage."),
    (else_try),
      (set_trigger_result, 0),
    (try_end),

Anyone have ideas on how to go around this?
 
How about

Code:
 (agent_get_player_id, ":player", ":agent"),
    (try_begin),
      (eq, ":dealer", ":player"),
      (set_trigger_result, 0),
      (set_result_string, -1),
    (else_try),
      (set_trigger_result, 0),
    (try_end),
 
Unfortunately, that doesnt seem to work.



Made it to work. Need to change (agent_get_player_id, ":player", ":agent"), to (get_player_agent_no, ":player"),

I keep forgetting that the latter is for SP, while the former is for MP.

Thanks for this code!
 
Back
Top Bottom