How to make unit slowed when it is carrying a ball?

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.
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

How to make unit slowed when it is carrying a ball?

Post by savagust »

Hi,
I am working on a scenario that is similar to Wesbowl,
but I'm stuck with two problems:

1.How to make "unit gets slowed when it is carrying a ball"?
2.How to make "when unit transfers the ball to another unit,
the first unit becomes normal and the second unit gets slowed"?

May anyone tell me how to make them work?

Any help is appreciated :)
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

I think this is what you look for:
http://www.wesnoth.org/wiki/EffectWML
First read, then think. Read again, think again. And then post!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to make unit slowed when it is carrying a ball?

Post by zookeeper »

savagust wrote:1.How to make "unit gets slowed when it is carrying a ball"?
2.How to make "when unit transfers the ball to another unit,
the first unit becomes normal and the second unit gets slowed"?

May anyone tell me how to make them work?
First of all, you should tell what Wesnoth version you intend this to work on, but I'll assume 1.1.7 and higher for now.

To slow a unit, you must set the unit variable unit.status.slowed to on. You can do this simply by using:

Code: Select all

{MODIFY_UNIT x,y=$x1,$y1 status.slowed on}
I assume for now that you know how to adapt that line to your particular scenario...

To revert the slowed status, just do the same but either clear the variable or set it to off, for example.

EDIT: The game seems to use slowed=yes by default, so it might be safer to use yes instead of on, even though it might very well work with both.
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

Thank you for your patience! :D

Yes, I am using 1.1.7.
I am sorry for my indiscretion :oops:

I have used {MODIFY_UNIT x,y=$x1,$y1 status.slowed on} but that unit is only slowed for one turn.
That is not what I want :cry:

My aim is:
Make "ball-carrying" unit get slowed EVERY TURN until it has passed the ball to another unit.
Then, the second unit is carrying the ball now and gets slowed.

After I have checked the wiki, it says:
"...When the controller of the unit's turn is over, slowed is set to 'off'..."

It seems that slow can only be activated for one turn.
I don't know how to get rid of that...

If there is no way to solve it, please tell me how to write a code that has the same effect of slow but remains every turn until the ball is off.

Thanks a lot :)
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

You can slow him again every turn if you have the ball-carrying unit sored in a variable.
First read, then think. Read again, think again. And then post!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

savagust wrote:Thank you for your patience! :D

Yes, I am using 1.1.7.
I am sorry for my indiscretion :oops:

I have used {MODIFY_UNIT x,y=$x1,$y1 status.slowed on} but that unit is only slowed for one turn.
That is not what I want :cry:
Oops, that's true, slow only stays active for one turn.

So, you need to do something more complicated. In addition to setting status.slowed=yes when a unit gets the ball, also set variables.has_ball=yes (or however you like to name the variable, it's basically just a flag we're using here). Then, make a name=side turn event that stores every unit of the side that's about to take it's turn, iterates through all of them and checks their variables.has_ball unit variable. When a unit with variables.has_ball=yes is found, slow it again by using the same MODIFY_UNIT way as before. That way, the unit with the ball should stay slowed indefinitely.

Note that obviously you must take care to set variables.has_ball=no when a unit passes the ball to another unit, so units that transfer the ball to another unit won't stay slowed.
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

I have a trouble again...

I have added a side event but it doesn't work.I don't know what's missing or wrong.Please have a look...

Thanks again :oops:

Code: Select all

[event]
   name=side turn
   first_time_only=no

		[store_unit]
		variable=unit
			[filter]
side=1,2
			x,y=$x1,$y1
			[/filter]
		[/store_unit]
		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]

{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes}

				[message]
				speaker=unit
				message= _ "It is heavy!"
				[/message]

				[unstore_unit]
				variable=unit
				[/unstore_unit]
			[/then]
		[/if]
[/event] 

Here is the rest of code if necessary

Code: Select all

[event]
name=prestart
 [objectives]
 side=1
  [objective]
   description= _ "Defeat Enemy Leader"
   condition=win
  [/objective]
  [objective]
   description= _ "Death of Konrad"
   condition=lose
  [/objective]
 [/objectives]
[/event]

	[side]
	type=Swordsman
	description=Konrad
	user_description= _ "Konrad"
	unrenamable=yes
	side=1
	canrecruit=1
	recruit=Elvish Scout,Elvish Fighter,Elvish Archer
	team_name=elves
	controller=human
		{GOLD 9991 9995 9999}
		{INCOME 10 5 0}
	[/side]

	[side]
	type=Grand Knight
	description=Sir Kaylan
	user_description= _ "Sir Kaylan"
	{IS_HERO}
	side=2
	canrecruit=1
	team_name=elves
	recruit=Horseman,Knight

	controller=human

		{GOLD 9991 9995 9999}
	[/side]


	[side]
	type=Orcish Warrior
	description=Mokolo Qimur
	user_description= _ "Mokolo Qimur"
	side=3
	canrecruit=1
	team_name=orcs
	recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Troll Whelp
		[ai]
		{ATTACK_DEPTH 1 3 5}
		[/ai]
		{GOLD 100 160 220}
		{INCOME 8 16 20}
	[/side]


	[event]
	name=prestart

	{VARIABLE b1x 15}
	{VARIABLE b1y 12}
	{VARIABLE b1down yes}

		[item]
		image=items/ball.png
		x,y=$b1x,$b1y
		[/item]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
side=1,2
		x,y=$b1x,$b1y
		[/filter]
		[store_unit]
		variable=unit
			[filter]
			x,y=$b1x,$b1y
			[/filter]
		[/store_unit]
		[if]
			[variable]
			name=b1down
			equals=yes
			[/variable]
			[then]
				[removeitem]
				x,y=$b1x,$b1y
				[/removeitem]
				{VARIABLE b1down no}
				{VARIABLE unit.variables.has_ball1 yes}

				[unstore_unit]
				variable=unit
				[/unstore_unit]

{MODIFY_UNIT x,y=$b1x,$b1y status.slowed yes}

				[unit_overlay]
				x,y=$b1x,$b1y
				image=items/ball.png
				[/unit_overlay]
			[/then]
		[/if]
	[/event]


	[event]
	name=die
	first_time_only=no

		[store_unit]
		variable=unit
			[filter]
			x,y=$x1,$y1
			[/filter]
		[/store_unit]

		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]

				[item]
				x,y=$x1,$y1
				image=items/ball.png
				[/item]
				{VARIABLE b1x $x1}
				{VARIABLE b1y $y1}
				{VARIABLE unit.variables.has_ball1 no}
				{VARIABLE b1down yes}
				[unstore_unit]
				variable=unit
				[/unstore_unit]

{MODIFY_UNIT x,y=$x1,$y1 status.slowed no}

				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]

				[message]
				speaker=unit
				message= _ "I can't make it!"
				[/message]

			[/then]
		[/if]
	[/event]


	[event]
	name=moveto
	first_time_only=yes
		[filter]
side=1,2
		x=10
		y=10
		[/filter]
		[store_unit]
		variable=unit
			[filter]
			x,y=$x1,$y1
			[/filter]
		[/store_unit]
		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]
				[message]
				speaker=unit
				message= _ "She is alive!"
				[/message]

				{VARIABLE passed no}
				{VARIABLE unit.variables.has_ball1 no}
				{VARIABLE passto.variables.has_ball1 no}

				[unstore_unit]
				variable=unit
				[/unstore_unit]

{MODIFY_UNIT x,y=$x1,$y1 status.slowed no}

				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]
	[unit]
	x=12
	y=12
	type=Great Mage
	side=1
	[/unit]

{CLEAR_VARIABLE b1x}
{CLEAR_VARIABLE b1y}
{CLEAR_VARIABLE b1down}
{CLEAR_VARIABLE unit.variables.has_ball1}
{CLEAR_VARIABLE x1}
{CLEAR_VARIABLE y1}
{CLEAR_VARIABLE unit}
{CLEAR_VARIABLE locs}
{CLEAR_VARIABLE xloc}
{CLEAR_VARIABLE yloc}
{CLEAR_VARIABLE passed}
{CLEAR_VARIABLE passto}
{CLEAR_VARIABLE passto.variables.has_ball1}

			[/then]
		[/if]
	[/event]


	#event to transfer control of the ball by passing, after movement
	[event]
	name=moveto
	first_time_only=no
		[store_unit]
		variable=unit
			[filter]
side=1,2
			x,y=$x1,$y1
			[/filter]
		[/store_unit]
		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]
				[store_locations]
				variable=locs
				x,y,radius=$x1,$y1,1
				[/store_locations]
				{VARIABLE passed no}
				{FOREACH locs i}
					{VARIABLE_OP xloc to_variable locs[$i].x}
					{VARIABLE_OP yloc to_variable locs[$i].y}
					[if]
						[or]
							[variable]
							name=xloc
							not_equals=$x1
							[/variable]
							[variable]
							name=passed
							equals=no
							[/variable]
							[have_unit]
							x,y=$xloc,$yloc
side=1,2
							[/have_unit]
						[/or]
						[or]
							[variable]
							name=yloc
							not_equals=$y1
							[/variable]
							[variable]
							name=passed
							equals=no
							[/variable]
							[have_unit]
							x,y=$xloc,$yloc
side=1,2
							[/have_unit]
						[/or]
						[then]
							[store_unit]
								variable=passto
								[filter]
								x,y=$xloc,$yloc
								[/filter]
							[/store_unit]

									[message]
									speaker=unit
									message= _ "Should I pass the ball to $passto.type ($xloc,$yloc)?"
										[option]
										message= _ "Yes!"
											[command]
											{VARIABLE passed yes}
											{VARIABLE unit.variables.has_ball1 no}
											{VARIABLE passto.variables.has_ball1 yes}

												[unstore_unit]
												variable=passto
												[/unstore_unit]
												[unstore_unit]
												variable=unit
												[/unstore_unit]

{MODIFY_UNIT x,y=$x1,$y1 status.slowed no}

												[remove_unit_overlay]
												x,y=$x1,$y1
												image=items/ball.png
												[/remove_unit_overlay]

{MODIFY_UNIT x,y=$xloc,$yloc status.slowed yes}

												[unit_overlay]
												x,y=$xloc,$yloc
												image=items/ball.png
												[/unit_overlay]
											[/command]
										[/option]
										[option]
										message= _ "No"
										[/option]
									[/message]
						[/then]
					[/if]
				{NEXT i}
			[/then]
		[/if]
	[/event]
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Code: Select all

...
      [store_unit] 
      variable=unit 
         [filter] 
side=1,2 
         x,y=$x1,$y1 
         [/filter] 
      [/store_unit] 
      [if] 
         [variable] 
         name=unit.variables.has_ball1 
         equals=yes 
         [/variable] 
         [then] 
{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes} 
         ...
         [/then] 
      [/if] 
[/event]
I think you meant this:

Code: Select all

      [store_unit] 
      variable=unit 
         [filter] 
side=1,2 
         x,y=$x1,$y1 
         [/filter] 
      [/store_unit] 
      {FOREACH unit j}
      [if] 
         [variable] 
         name=unit[$j].variables.has_ball1 
         equals=yes 
         [/variable] 
         [then]
{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes} 
...
         [/then]
        [/if]
        {NEXT j}
First read, then think. Read again, think again. And then post!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

How much sense do $x1 and $y1 make in a side turn event? None.

Also, you probably can't use variables in an event [filter].
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

Sorry toms, it seems that your code doesn't work for me.

Anyway, thanks zookeeper and toms :)

May anyone teach me how to code that side event??or post an example here??

I'm just a newcomer for WML.I really don't know how to code that.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Now I see it.
Your code:
[event]
name=side turn
first_time_only=no

[store_unit]
variable=unit
[filter]
side=1,2
x,y=$x1,$y1
[/filter]
[/store_unit]
[if]
[variable]
name=unit.variables.has_ball1
equals=yes
[/variable]
[then]

{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes}

[message]
speaker=unit
message= _ "It is heavy!"
[/message]

[unstore_unit]
variable=unit
[/unstore_unit]
[/then]
[/if]
[/event]
Right it should be:

Code: Select all

[event] 
   name=side turn 
   first_time_only=no 

      [store_unit] 
      variable=unit 
         [filter] 
side=1,2 
         [/filter] 
      [/store_unit] 
      {FOREACH unit j}
      [if] 
         [variable] 
         name=unit.variables.has_ball1 
         equals=yes 
         [/variable] 
         [then] 
{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes} 
            [message] 
            speaker=unit 
            message= _ "It is heavy!" 
            [/message] 
            [unstore_unit] 
            variable=unit 
            [/unstore_unit] 
         [/then] 
      [/if] 
      {NEXT j}
[/event]
As zookeeper said, $x1 and $y1 do not make sense in side turn. I just removed x,y=$x1,$y1 and added the FOREACH loop to find the ball unit. I hope it works now.
First read, then think. Read again, think again. And then post!
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

It doesn't work for me but thanks again, toms :)

In my scenario, several units cooperate with each other for saving an injured unit who can't move itself.
One of them put the injured unit on the back. As a result, that unit is slowed.Then, bring that injured unit to a temple for cure. Then, the injured unit will join the team.

However, I can't get rid of the problem of the side event.

I hope someone will show me how to do that.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Try to stuff the event full of debug msgs.
like this:

[event]
name=side turn
{DEBUG_MSG (_"Side turn event)}
(store unit tag)
(add an if to check if the length of the store variable is > 0)
{DEBUG_MSG (_"Units stored")}
(end if)
(foreach loop)
{DEBUG_MSG (_"|$unit[$j]|")}
(if the unit has the ball)
{DEBUG_MSG (_"...")}
(tags close)

With this you see how far the computer gets before the bug.
And it just could be that the flag for the unit who has the ball doesn't work.
First read, then think. Read again, think again. And then post!
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

Sorry toms

I'm not sure how to add those debug messages.I have tried to add them to the code but error has occured.

May you show me how in detail, please? :oops:
Swordy
Posts: 110
Joined: June 10th, 2005, 8:38 am

Post by Swordy »

umm hello...

Code: Select all

{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes}
it's 'on', not 'yes' ;)
Post Reply