Random turn

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.
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Random turn

Post by tommy2teeth »

I made a mod that selects a side randomly and applies an event to it( ie. poison, heal, petrify)depending on the turn. I was wondering if it was possible for an event to fire randomly so I never knew which event was going to happen at the beginning of the turn. Here is the code I made.

Code: Select all

#ifdef MULTIPLAYER

[modification]
	id=Random Events
	name=_"Random Events"
	description=_"Random events will affect units."

[event]
first_time_only=no
name=turn_12
	[message]
	speaker=narrator
	message= _ "Sickness is spreading!"
	sound=data/core/sounds/goblin-die-2.ogg
	image=data/core/images/items/bones.png
	[/message]
		[set_variable]
		name=random
		rand=1..9
		[/set_variable]
			[harm_unit]
				[filter]
				side=$random
				[/filter]
					amount=0
					poisoned=yes
					animate=yes
				[sound]
				name=data/core/sounds/poison.ogg
				[/sound]
				[message]
				side=$random
				canrecruit=no
				message="I don't feel so well.  I think someone poisoned our food supply!"
				[/message]
			[/harm_unit]
[/event]

[event]
first_time_only=no
name=turn_16
	[message]
	speaker=narrator
	message= _ "Health elixir!"
	sound=data/core/sounds/potion.ogg
	image=data/core/images/items/potion-green.png
	[/message]
		[set_variable]
		name=random
		rand=1..9
		[/set_variable]
			[heal_unit]
				[filter]
				side=$random
				[/filter]
				amount=full
				animate=yes
				[sound]
				name=data/core/sounds/heal.ogg
				[/sound]
			[/heal_unit]
		[message]
		side=$random
		canrecruit=no
		message= _ "I feel better already!"
		[/message]
[/event]

[event]
first_time_only=yes
name=turn_20
	[message]
	speaker=narrator
	message= _ "Fatigue!"
	sound=data/core/sounds/slowed.wav
	image=data/core/images/items/dummy.png
	[/message]
		[set_variable]
		name=random
		rand=1..9
		[/set_variable]
			[harm_unit]
				[filter]
				side=$random
				[/filter]
				amount=2
				slowed=yes
				animate=yes
				kill=yes
					[sound]
					name=data/core/sounds/slowed.ogg
					[/sound]
			[/harm_unit]
	[message]
	side=$random
	canrecruit=no
	message="I did not think this battle would last so long.  Our amry is exhuasted."
	[/message]
[/event]

[event]
first_time_only=no
name=turn_8
		[message]
		speaker=narrator
		message= _ "Gaze of MEDUSA!."
		sound=data/core/sounds/petrified.ogg
		image=data/core/images/items/dragonstatue.png
		[/message]
			[set_variable]
			name=random
			rand=1..9
			[/set_variable]
				[harm_unit]
					[filter]
					side=$random
					[/filter]
				amount=2
				petrified=yes
				animate=yes
				kill=yes
					[sound]
					name=data/core/sounds/petrified.ogg
					[/sound]
				[/harm_unit]
		[message]
		side=$random
		canrecruit=no
		message= _ "I..... can't.... move."
		[/message]
[/event]

[event]
first_time_only=no
name=turn_4
	[message]
	speaker=narrator
	message= _ "Strength of the YETI!"
	sound=data/core/sounds/yeti-hit.ogg
	image=data/core/images/items/hammer-runic.png
	[/message]
		[set_variable]
		name=random
		rand=1..9
		[/set_variable]
			[modify_unit]
				[filter]
				side=$random
				[/filter]
				[trait]
				name=strength
				[/trait]
			[/modify_unit]
	[message]
	side=$random
	canrecruit=no
	message= _ "All our units have gained strength!"
	sound=data/core/sounds/yeti-hit.ogg
	[/message]
[/event]

[event]
name=turn_end
first_time_only=no
	[unpetrify]
		[filter]
		side=1,2,3,4,5,6,7,8,9
		[/filter]
	[/unpetrify]
[/event]


[/modification]
#endif
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Random turn

Post by Ravana »

This can be done with nested events, in outer event select random, and inner assign new event to that turn. (name=turn_$random)

Also, I believe

Code: Select all

    [trait]
        name=strength
    [/trait]
does nothing useful currently.
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

OK, I probably misunderstood. I tried this and nothing fired.

Code: Select all

#ifdef MULTIPLAYER

[modification]
	id=Random Occurences
	name=_"Random Occurences"
	description=_"Random events will affect units."
	
[event]
name=$turn_random
first_time_only=no
[event]
name=turn_$random
first_time_only=no
	[message]
	speaker=narrator
	message= _ "Sickness is spreading!"
	sound=data/core/sounds/goblin-die-2.ogg
	image=data/core/images/items/bones.png
	[/message]
		[set_variable]
		name=random
		rand=1..6
		[/set_variable]
			[harm_unit]
				[filter]
				side=$random
				[/filter]
					amount=1
					poisoned=yes
					animate=yes
					kill=yes
				[sound]
				name=data/core/sounds/poison.ogg
				[/sound]
			[message]
			side=$random
			canrecruit=no
			message="I don't feel so well.  I think someone poisoned our food supply!"
	[/message]
			[/harm_unit]

[event]
name=turn_$random
first_time_only=no
	[message]
	speaker=narrator
	message= _ "Health elixir!"
	sound=data/core/sounds/potion.ogg
	image=data/core/images/items/potion-green.png
	[/message]
		[set_variable]
		name=random
		rand=1..6
		[/set_variable]
			[heal_unit]
				[filter]
				side=$random
				[/filter]
				amount=full
				animate=yes
				[sound]
				name=data/core/sounds/heal.ogg
				[/sound]
			[/heal_unit]
		[message]
		side=$random
		canrecruit=no
		message= _ "I feel better already!"
		[/message]				


[event]
name=turn_$random
first_time_only=no
	[message]
	speaker=narrator
	message= _ "Fatigue!"
	sound=data/core/sounds/slowed.wav
	image=data/core/images/items/dummy.png
	[/message]
		[set_variable]
		name=random
		rand=1..6
		[/set_variable]
			[harm_unit]
				[filter]
				side=$random
				[/filter]
				amount=2
				slowed=yes
				animate=yes
				kill=yes
				[sound]
				name=data/core/sounds/slowed.ogg
				[/sound]
			[/harm_unit]
	[message]
	side=$random
	canrecruit=no
	message="I did not think this battle would last so long.  Our army is exhuasted."
	[/message]	


[event]
name=turn_$random
first_time_only=no
	[message]
	speaker=narrator
	message= _ "Gaze of MEDUSA!."
	sound=data/core/sounds/petrified.ogg
	image=data/core/images/items/dragonstatue.png
	[/message]
		[set_variable]
		name=random
		rand=1..6
		[/set_variable]
			[harm_unit]
				[filter]
				side=$random
				[/filter]
				amount=4
				petrified=yes
				animate=yes
				kill=yes
					[sound]
					name=data/core/sounds/petrified.ogg
					[/sound]
			[/harm_unit]
		[message]
		side=$random
		canrecruit=no
		message= _ "I..... can't.... move."
		[/message]	

[event]
name=turn_$random
first_time_only=no
	[message]
	speaker=narrator
	message= _ "Strength of the YETI!"
	sound=data/core/sounds/yeti-hit.ogg
	image=data/core/images/items/hammer-runic.png
	[/message]
		[set_variable]
		name=random
		rand=1..6
		[/set_variable]
			[modify_unit]
				[filter]
				side=$random
				[/filter]
				[trait]
				name=strength
				[/trait]
			[/modify_unit]
	[message]
	side=$random
	canrecruit=no
	message= _ "All our units have gained strength!"
	sound=data/core/sounds/yeti-hit.ogg
	[/message]
	[/event]
	[/event]
	[/event]
	[/event]
	[/event]
	[/event]

[event]
name=turn_end
first_time_only=no
	[unpetrify]
		[filter]
		side=1,2,3,4,5,6,7,8,9
		[/filter]
	[/unpetrify]
[/event]


[/modification]
#endif
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Random turn

Post by Ravana »

Yes, outer event name needs to be predefined still, and you need to calculate random in it. Also, I meant [event][event][/event][event][/event][/event] not [event][event][event][/event][/event][/event].

[fire_event] might also help.
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

Is it possible to add sound into [harm_unit] animate=yes. I want to add a lightning.ogg sound every time a unit is harmed. I tried to add sound= but nothing happened. My guess is that the animate=yes might be my problem because it plays the units defense anim and sound. Is there a workaround for this?

Code: Select all

[event]
name=turn_2
first_time_only=no
	[message]
	speaker=narrator
	message= _ "Feel the wrath of ZUES!!!"
	sound=data/core/sounds/lightning.ogg
	image=data/core/images/items/hammer-runic.png
	[/message]
		[set_variable]
		name=random
		rand=1..6
		[/set_variable]
			[harm_unit]
				[filter]
				side=$random
				[/filter]
				amount=12
				kill=yes
				animate=yes
				sound=data/core/sounds/lightning.ogg
				[/harm_unit]
		[message]
		side=$random
		canrecruit=no
		message= _ "I beg of you Zues, forgive us!"
		[/message]	
[/event]
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Random turn

Post by beetlenaut »

You can play a sound with the [sound] tag.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

It doesn't make the noise exactly as it hits a unit, but I repeated the sound and shortened the sound to 2 seconds, it's passable. Any chance you know how to make lightning bolts from the sky hit each unit?
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

I would like to ask someone to test this mod for me. I have not noticed any errors yet, but a fresh set of eyes and feedback couldn't hurt. The mod is set up for a free for all 6 player game. Events happen to a random side on turns 4-30 (ie, Alien abduction to a random side on turn 30). Turns 1,2,3,7,12,18, and 24 do not have events yet.
Attachments
Trials_and_Tribulations.zip
Includes a few images and sounds
(1.51 MiB) Downloaded 206 times
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

I just copied and pasted and kept switching the turn number but the code is rather long

Code: Select all

[event]
name=turn 3
first_time_only=yes
<random event>
[/event]

[event]
name=turn 6
first_time_only=yes
<random event>
[/event]

#and so on 
Is there a code for having events happen at set turns such as....

Code: Select all

[event]
name=turn 3, 6, 9, 12, 15, 18, ect
first_time_only=yes
<random event>
[/event]
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Random turn

Post by Ravana »

[filter_condition] with some calculations with $turn_number.
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

With the above mod I made an event where a monster will appear at a random turn; problem is he just sits there. I'm trying it on a random map with 6 teams. Is there a way to get the monster (using a random map) to move around the board and attack. If I put monster on team 7 he works, but the problem is, there will also be another team/faction on the board (team 7) and the monster helps them/ is on their team.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Random turn

Post by beetlenaut »

I he doesn't have a side, he doesn't get a turn. That's why he sits there. You need a side (with no leader) for the monster to be on. It can be side 8.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

Do I add no leader to the random map, the mod, or the unit itself?
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Random turn

Post by Ravana »

Certainly not unit.

Adding to mod wouldnt work either.

That only leaves scenario, but that means it would be difficult to support it only by modification.
User avatar
tommy2teeth
Posts: 46
Joined: February 28th, 2015, 8:30 pm

Re: Random turn

Post by tommy2teeth »

I was thinking of adding an event where a side would be randomly chosen and be given shroud. Is this possible if you have shroud off in the lobby settings? The [place_shroud] code says "places some shroud on the map for a certain side (only relevant for sides that have shroud=yes)." So does that mean only if you have shroud "yes" on each side in the scenario cfg? Will the following code work?

Code: Select all

#define RANDOM_EVENT_14
[event]
name=new turn
first_time_only=yes
	[message]
	speaker=narrator
	message= _ "Voodoo curse prevents you from seeing enemies."
	sound=data/core/sounds/dwarf-laugh.wav
	image=userdata/data/add-ons/Trials_and_TribulationsA/images/samedi.png
	[/message]
			{COLOR_ADJUST -100 -100 -100}
		[set_variable]
		name=random
		rand=1..6
		[/set_variable]
			[place_shroud]
				[filter]
				side=$random
				[/filter]
			[/place_shroud]	
			{COLOR_ADJUST 0 0 0}	
				[message]
				side=$random
				canrecruit=no
				message= _ "Voodoo isn't real.....is it?"
				sound=data/core/sounds/dwarf-laugh.wav
				[/message]	
[/event]
#enddef
Post Reply