Damage Events

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Bilbo_Sacket
Posts: 37
Joined: February 28th, 2021, 4:27 am

Damage Events

Post by Bilbo_Sacket »

I've been working on making damage events where if someone is standing in a particular place at a particular time, they become liable targets to said damage. I have come over a couple of road bumps though. Firstly, I do not see a way to randomly hit one unit and not another in the defined locations, or to hit some people, but not everybody, the damage is supposed to be 20dmg, but it keeps going, hitting the same unit over and over until all of the units in the defined space is dead.

Code: Select all

[event]
	   name=moveto
	   first_time_only=yes
	   [filter]
	          x=40-50
		  y=14-50
		  side=2
	   [/filter]
	   
	   [if]
		  [variable]
			 name=unitCounter
			 value=6
		  [/variable]
			[then]
			   [set_variable]
					name=damageLimiter
					value=0
			   [/set_variable]
			   [message]
				  id=GeneralHancock
				  message="Now!"
			   [/message]
			   [scroll_to]
				  x,y=42,35
			   [/scroll_to]
			   {PLAY_SOUND "dragonstick.ogg"} 
			   [delay]
			      time=500
			   [/delay]
			   {PLAY_SOUND "dragonstick.ogg"} 
			   [delay]
			      time=500
			   [/delay]
			   {PLAY_SOUND "dragonstick.ogg"} 
			   [delay]
			      time=500
			   [/delay]
			   {PLAY_SOUND "dragonstick.ogg"} 
			   [delay]
				  time=1000
			   [/delay]
			   [scroll_to]
				  x,y=45,19
			   [/scroll_to]
			   {PLAY_SOUND "explosion.ogg"}
			   [delay]
			      time=500
			   [/delay]
			   {PLAY_SOUND "explosion.ogg"}
			   [delay]
			      time=500
			   [/delay]
			   {PLAY_SOUND "explosion.ogg"}
			   [delay]
			      time=500
			   [/delay]
			   {PLAY_SOUND "explosion.ogg"}
			   [delay]
			      time=500
			   [/delay]
			   [store_locations]
					[filter]
					[not]
					    side=1,3
						type=UnitedStatesMajor
					[/not]
						side=2
						[variable]
						   name=unitCounter
						   value=6
					    [/variable]
					[/filter]
					x=20-50
					y=19-50
					variable=cannonslayed
              [/store_locations]
			    [foreach]
					array=cannonslayed
						[do]
									[harm_unit]
										[filter]
											x=28-50
											y=14-50
											[variable]
											   name=unitCounter
											   value=6
											[/variable]
										[/filter]
										amount=20
										damage_type=impact
										slowed=yes
										animate=yes
										kill=yes
										fire_event=yes
									[/harm_unit]
						[/do]
				[/foreach]
				[clear_variable]
					name=cannonslayed
				[/clear_variable]
			   [message]
				  id=Custer
				  message="Wheeler’s artillery. It’s lovely."
			   [/message]
		   [/then]
		   [else]
			   [message]
				  id=GeneralHancock
				  message="Get ready..."
			   [/message]
			  [set_variable]
				 name=unitCounter
				 add=1
			  [/set_variable]
		   [/else]
	   [/if]
	[/event]
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Damage Events

Post by hermestrismi »

In my utils files, there is three kind of damages:
specific damage for random unit at random places at specific times,
random damage for random unit at specific places at random times,
random damage for random units (including yours) on random places at random times.
(their is also random resistance events for a specific unit)
note: random places doesn't return to normal so you need to add a clear_variable at your scenario if you want to limit the events to a predefined number of turns
everyone of them have its code.
all what you need is to change the setting or add/delet variables to maintain the frequency .
if you find what you need at you couldn't manipulate it correctly, you are free to ask
Attachments
utils.cfg
(42.73 KiB) Downloaded 25 times
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Damage Events

Post by hermestrismi »

try this one

Code: Select all

#define ATTACK_RANDOM

	[event]
		name=side 1 turn
		first_time_only=no
				[if]
				    [variable]
					    name=Condition1
						equals=1
					[/variable]
					[then]
				[set_variable]
					name=Condition2
					rand="1,0"
				[/set_variable]
			[if]
				[variable]
					name=Condition2
					equals=1
				[/variable]
				 [then]
			
				[set_variable]
					name=Something_to_Test1
					rand="1..56"
					to_variable=WhereTheStorm
				[/set_variable]
				[set_variable]
					name=Something_to_Test2
					rand="1..38"
					to_variable=WhereTheStorm
				[/set_variable]
				[set_variables]
					mode=replace
					name=WhereTheStorm
						[value]
							x=$Something_to_Test1
							y=$Something_to_Test2
						[/value]
				[/set_variables]
				
				[store_unit]
					[filter]
						[filter_location]
							x,y=$WhereTheStorm.x,$WhereTheStorm.y
							radius=2
						[/filter_location]
					[/filter]
					variable=ForTheFloatingText
					kill=no
				[/store_unit]
				
				[fire_event]
					name=chaotic damage
					[primary_unit]
						find_in=WhereTheStorm
					[/primary_unit]
				[/fire_event]
				[/then]
			[/if]
					[/then]
					[/if]
	[/event]
	[event]
		name=chaotic damage
		first_time_only=no
		    [set_variable]
                name=attack_event_i
                rand=fire_storm,cold_storm,dark_shadow_storm,meteor_storm
			[/set_variable]
				[if]
					[variable]
						name=attack_event_i
						equals=fire_storm
				    [/variable]
						[then]	
							[scroll_to]
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/scroll_to]
							[delay]
							    time=3000
							[/delay]	
                            [sound]
                                name=fire.wav
                            [/sound]								
				            [item]
				                halo="halo/fire-aura.png"
				                x,y=$WhereTheStorm.x,$WhereTheStorm.y
				            [/item]					
				            [item]
				                halo="halo/burning-1.png~O(80%):100,halo/burning-2.png~O(80%):100,halo/burning-3.png~O(80%):100,halo/burning-4.png~O(80%):100,halo/burning-5.png~O(80%):100,halo/burning-6.png~O(80%):100"
				                x,y=$WhereTheStorm.x,$WhereTheStorm.y
				            [/item]
					        [harm_unit]
                                [filter]
						        [filter_location]
							        find_in=WhereTheStorm
									radius=2
						        [/filter_location]
								[/filter]
						            amount=5
				                    damage_type=fire
									fire_event=yes
	                                experience=no
			                        kill=no
							[/harm_unit]
                            [sound]
                                name=lightning-miss.ogg
                            [/sound]
							[floating_text]
						        x,y=$ForTheFloatingText.x,$ForTheFloatingText.y
						        text="<span color='#EA210D'>" + _ "It burn" + "</span>"
						    [/floating_text]
				            [delay]
				                time=2000
				            [/delay]
				            [remove_item]
                                [filter_location]
                                     x,y=$WhereTheStorm.x,$WhereTheStorm.y
                                [/filter_location]
                                 halo="halo/burning-1.png~O(80%):100,halo/burning-2.png~O(80%):100,halo/burning-3.png~O(80%):100,halo/burning-4.png~O(80%):100,halo/burning-5.png~O(80%):100,halo/burning-6.png~O(80%):100"
                            [/remove_item]
				            [remove_item]
                                [filter_location]
                                     x,y=$WhereTheStorm.x,$WhereTheStorm.y
                                [/filter_location]
                                 halo="halo/fire-aura.png"
                            [/remove_item]
						[/then]
				[/if]  
				[if]
					[variable]
						name=attack_event_i
						equals=cold_storm
					[/variable]
						[then]	
							[scroll_to]
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/scroll_to]
							[delay]
							    time=3000
							[/delay]	
                            [sound]
                                name=petrified.ogg
                            [/sound]				
							[item]
							    halo="halo/blizzard-1.png~O(80%):100,halo/blizzard-2.png~O(80%):100,halo/blizzard-3.png~O(80%):100"
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/item]
					        [harm_unit]
                                [filter]
						        [filter_location]
							        find_in=WhereTheStorm
									radius=2
						        [/filter_location]
								[/filter]
						            amount=5
						            damage_type=cold
						            fire_event=yes
						            experience=no
					                kill=no
									slowed=yes
							[/harm_unit] 
                            [sound]
                                name=slowed.wav
                            [/sound]
							[floating_text]
						        x,y=$ForTheFloatingText.x,$ForTheFloatingText.y
						        text="<span color='#0D5DEA'>" + _ "It is cold" + "</span>"
						    [/floating_text]
				            [delay]
				                time=2000
				            [/delay]
				            [remove_item]
                                [filter_location]
                                    x,y=$WhereTheStorm.x,$WhereTheStorm.y
                                [/filter_location]
                                halo="halo/blizzard-1.png~O(80%):100,halo/blizzard-2.png~O(80%):100,halo/blizzard-3.png~O(80%):100"
                            [/remove_item]
						[/then]
					[/if]  
					[if]
						[variable]
							name=attack_event_i
							equals=dark_shadow_storm
						[/variable]
						    [then]	
							[scroll_to]
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/scroll_to]
							[delay]
							    time=3000
							[/delay]	
                            [sound]
                                name=magic-dark-big.ogg
                            [/sound]				
							[item]
							    halo="halo/darkens-aura.png"
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/item]					
							[item]
							    halo="halo/corruption-aura-1.png~O(80%):100,halo/corruption-aura-2.png~O(80%):100,halo/corruption-aura-3.png~O(80%):100"
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/item]
					            [harm_unit]
                                [filter]
						        [filter_location]
							        find_in=WhereTheStorm
									radius=2
						        [/filter_location]
								[/filter]
						                amount=5
						                damage_type=arcane
						                fire_event=yes
						                experience=no
					                    kill=no
										poisoned=yes
							    [/harm_unit]
							[floating_text]
						        x,y=$ForTheFloatingText.x,$ForTheFloatingText.y
						        text="<span color='#E3D5F3'>" + _ "My soul" + "</span>"
						    [/floating_text]
                            [sound]
                                name=explosion.ogg
                            [/sound]	
				            [delay]
				                time=2000
				            [/delay]
				            [remove_item]
                                [filter_location]
                                    x,y=$WhereTheStorm.x,$WhereTheStorm.y
                                [/filter_location]
							    halo="halo/corruption-aura-1.png~O(80%):100,halo/corruption-aura-2.png~O(80%):100,halo/corruption-aura-3.png~O(80%):100"
                            [/remove_item]				
							[remove_item]
							    halo="halo/darkens-aura.png"
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/remove_item]	
							[/then]
					[/if]  
					[if]
						[variable]
							name=attack_event_i
							equals=meteor_storm
						[/variable]
						    [then]	
							[scroll_to]
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/scroll_to]
							[delay]
							    time=3000
							[/delay]	
                            [sound]
                                name=sling-big.ogg
                            [/sound]							
							[item]
							    halo="halo/meteor-1.png~O(80%):100,halo/meteor-2.png~O(80%):100,halo/meteor-3.png~O(80%):100,halo/meteor-4.png~O(80%):100,halo/meteor-5.png~O(80%):100,halo/meteor-6.png~O(80%):100,halo/meteor-7.png~O(80%):100,halo/meteor-8.png~O(80%):100,halo/meteor-9.png~O(80%):100"
							    x,y=$WhereTheStorm.x,$WhereTheStorm.y
							[/item]
					            [harm_unit]
                                [filter]
						        [filter_location]
							        find_in=WhereTheStorm
									radius=2
						        [/filter_location]
								[/filter]
						                amount=5
						                damage_type=impact
						                fire_event=yes
						                experience=no
					                    kill=no
							    [/harm_unit]
								[sound]
								    name=sling-big-miss.ogg
								[/sound]
							[floating_text]
						        x,y=$ForTheFloatingText.x,$ForTheFloatingText.y
						        text="<span color='#B10D2B'>" + _ "What an explosion" + "</span>"
						    [/floating_text]
				            [delay]
				                time=2000
				            [/delay]
				            [remove_item]
                                [filter_location]
                                    x,y=$WhereTheStorm.x,$WhereTheStorm.y
                                [/filter_location]
							    halo="halo/meteor-1.png~O(80%):100,halo/meteor-2.png~O(80%):100,halo/meteor-3.png~O(80%):100,halo/meteor-4.png~O(80%):100,halo/meteor-5.png~O(80%):100,halo/meteor-6.png~O(80%):100,halo/meteor-7.png~O(80%):100,halo/meteor-8.png~O(80%):100,halo/meteor-9.png~O(80%):100"
                            [/remove_item]
							[/then]
					[/if]
		{CLEAR_VARIABLE WhereTheStorm,Something_to_Test1,Something_to_Test2,attack_event_i,ForTheFloatingText}
	[/event]
#enddef
note:
condition1 on prestart
condition 2 to control the frequency or to stop the event at a specific moment
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Damage Events

Post by beetlenaut »

Read this if you want to write it yourself.
Bilbo_Sacket wrote: June 18th, 2022, 5:28 pm it keeps going, hitting the same unit over and over
You stored the locations that contain units, then for each of those locations, you harm every unit.

What you needed to do in the [foreach] loop was to go through each location and harm the unit at that location only. Get that working first (because it's important to do things one step at a time). Then, set a random variable each time through the loop. Use another [if] to harm the unit only if the random number is in a certain range.

Also: You will need to have "first_time_only" set to "no" or the main [if] statement will only run one time. Another thing: I don't know what you intended [variable] to do inside [filter], but it's not valid there, so it's not doing anything.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Post Reply