Problem: randomly applying an effect to trops in a party

Users who are viewing this thread

Cromcrom

Hi all,

I would like th have the possibility to have troops in a party randomly die or be wounded (as a result of disease, traps, ambushes....)
This basic code doesn't work:
Code:
("rigale_random_troop_death_or_wounded",
 [ 
  (store_script_param, ":chance_to_die",1),
  (store_script_param, ":chance_to_be_wounded",2),
  (store_script_param, ":party_no",3),
 
       (party_get_num_companion_stacks, ":num_stacks",":party_no"), 
       (try_for_range, ":i_stack", 0, ":num_stacks"),   
			(party_stack_get_size, ":stack_size",":party_no",":i_stack"),
			(party_stack_get_troop_id, ":troop_id", ":party_no", ":i_stack"),
			(store_random_in_range,":random_check",1,101),
			(str_store_troop_name,s1,":troop_id"),
		(try_for_range,":j_troop",0,":stack_size"),
			(neg|troop_is_hero,":troop_id"),
			(try_begin),
				(le,":random_check",":chance_to_die"),
				(remove_member_from_party,":troop_id",":party_no"),
				(display_message,"@A {s1} dies"),
			(else_try),
				(le,":random_check",":chance_to_be_wounded"),
				(troop_set_health,":troop_id",30),
				(display_message,"@A {s1} is wounded"),		
			(try_end),
		(val_add,":j_troop",1),
        (try_end),
	  (try_end),
	(str_clear,s1), 
	]),

Any hints or tips or advices would be greatly appreciated.

Thanks in advance and take care all :smile:
 
Your loop structure is essentially correct (indentation could use some work), but the operations used to remove/wound troops is incorrect - the ones you're using apply to heroes. Use party_remove_members and party_wound_members to achieve what you want. I have no idea why you're incrementing j_troop at the end though. To optimize your code, tabulate the number of troops to kill/wound first, and then use those operations.
 
Here is the final code, for anybody to use, giving credits please:
Code:
("rigale_random_troop_death_or_wounded",
 [ 
  (store_script_param, ":chance_to_die",1),
  (store_script_param, ":chance_to_be_wounded",2),
  (store_script_param, ":party_no",3),
 
       (party_get_num_companion_stacks, ":num_stacks",":party_no"), 
	   
       (try_for_range, ":i_stack", 0, ":num_stacks"),   
			(party_stack_get_size, ":stack_size",":party_no",":i_stack"),
			(party_stack_get_troop_id, ":troop_id", ":party_no", ":i_stack"),

			(str_store_troop_name,s1,":troop_id"),
			(try_for_range,":j_troop",0,":stack_size"),
				(neg|troop_is_hero,":troop_id"),
				(store_random_in_range,":random_check",1,101),				
				(try_begin),
					(le,":random_check",":chance_to_die"),
					(party_remove_members,":party_no",":troop_id",1),
					(display_message,"@A {s1} dies"),
				(else_try),
					(le,":random_check",":chance_to_be_wounded"),
					(party_wound_members,":party_no",":troop_id",1),
					#(troop_set_health,":troop_id",30),
					(display_message,"@A {s1} is wounded"),		
				(try_end),
			(try_end),
	  (try_end),
	(str_clear,s1), 
	]),

Thank you so much for your tips, Somebody, this bit of code is a real breakthrough for rigale, as it will allow me to make a great quantity of mean effects, like traps, ambushes, disease, and so on...

Take care all.
 
Back
Top Bottom