WML questions: invalid wml

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
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

WML questions: invalid wml

Post by battlestar »

Is it possible to create a walking corpse unit with a specified variation with wml? thanks.
Last edited by battlestar on March 6th, 2014, 11:33 pm, edited 24 times in total.
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: walking corpse creation

Post by Elvish_Hunter »

Yes. In the [unit] tag, just add the variation= key, like stated at http://wiki.wesnoth.org/SingleUnitWML :
variation: the variation of itself the unit should be created as.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Alarantalara
Art Contributor
Posts: 786
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: walking corpse creation

Post by Alarantalara »

Yes, just include the variation key in the unit creation code.
e.g.

Code: Select all

{UNIT side (Walking Corpse) x y  (variation=swimmer)}
If you're asking about doing for recruiting, check out the code for Muff Malal's peninsula from Heir to the Throne.
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: walking corpse creation

Post by battlestar »

cool, missed it when reading that lol, thanks.
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Something strange between different directions

Post by battlestar »

Two problems with the following code I've found:
1. GET_ADJACENT_HEX here gets every direction but it leaves out "s" (south)... I've tried putting it at different places but south is always the one that gets tossed out.
2. Something's wrong... tested it a dozen times and more confused than ever because it doesn't consistently do what it's supposed to do...
???
These codes are supposed to do this: any unit that killed adjacent to the unit with id=Valia will be turned into a zombie.
But it sometimes doesn't happen.

Code: Select all

#define GET_ADJACENT_HEX ORIGIN_X ORIGIN_Y DIRECTION RESULT_STORE
[store_locations]
	[filter_adjacent_location]
		x={ORIGIN_X}
		y={ORIGIN_Y}
		adjacent="-{DIRECTION}"
	[/filter_adjacent_location]
	variable={RESULT_STORE}
[/store_locations]
#enddef
#define AURA_OF_REANIMATION_DYING
	[event]
		name=last breath
		first_time_only=yes
		[filter]
				x,y=$valia_aura_location[1].x,$valia_aura_location[1].y
			[or]
				x,y=$valia_aura_location[2].x,$valia_aura_location[2].y
			[/or]
			[or]
				x,y=$valia_aura_location[3].x,$valia_aura_location[3].y
			[/or]
			[or]
				x,y=$valia_aura_location[4].x,$valia_aura_location[4].y
			[/or]
			[or]
				x,y=$valia_aura_location[5].x,$valia_aura_location[5].y
			[/or]
			[or]
				x,y=$valia_aura_location[6].x,$valia_aura_location[6].y
			[/or]
		[not]
            race=undead
            [or]
                race=mechanical
            [/or]
        [/not]

		[/filter]
		[if]
			[variable]
				name=aura_of_reanimation
				numerical_equals=1
			[/variable]
			[then]
				{MESSAGE narrator () "caption" "message"}
				[store_unit]
					[filter]
						x,y=$x1,$y1
					[/filter]
					variable=valia_resurrection_storage
					kill=no
				[/store_unit]
				[kill]
					x,y=$x1,$y1
					animate=yes
					fire_event=yes
				[/kill]
				[unit]
					type=Walking Corpse
					side=1
					x,y=$valia_resurrection_storage.x,$valia_resurrection_storage.y
					variation=$valia_resurrection_storage.undead_variation
					name="$valia_resurrection_storage.name"
					facing=$valia_resurrection_storage.facing	
				[/unit]
			[/then]
		[/if]
	[/event]
#enddef
#define AURA_OF_REANIMATION
# need to allow undo movements?
	[event]
		name=moveto
		first_time_only=no
		[filter]
			id=Valia
			[filter_location]
			[/filter_location]
		[/filter]
		{GET_ADJACENT_HEX $x1 $y1 (n,nw,ne,sw,se,s) valia_aura_location}
	[/event]
	{AURA_OF_REANIMATION_DYING}
	[event]
		name=die
		first_time_only=no
		[filter]
				x,y=$valia_aura_location[0].x,$valia_aura_location[0].y
			[or]
				x,y=$valia_aura_location[1].x,$valia_aura_location[2].y
			[/or]
			[or]
				x,y=$valia_aura_location[2].x,$valia_aura_location[2].y
			[/or]
			[or]
				x,y=$valia_aura_location[3].x,$valia_aura_location[3].y
			[/or]
			[or]
				x,y=$valia_aura_location[4].x,$valia_aura_location[4].y
			[/or]
			[or]
				x,y=$valia_aura_location[5].x,$valia_aura_location[5].y
			[/or]
			[or]
				x,y=$valia_aura_location[6].x,$valia_aura_location[6].y
			[/or]
		[/filter]
		{AURA_OF_REANIMATION_DYING}
	[/event]
	
#enddef
		[event]
		name=prestart 
			[set_variable]
				name=aura_of_reanimation
				value=1
			[/set_variable]
		[/event]
	{AURA_OF_REANIMATION}
Image
LUA: Llama Under Apprenticeship
Hell faction: completed
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Something strange between different directions

Post by mattsc »

Look at your indices. They should go from 0 to 5, not 1 to 6. There is also at least one line where you don't have the same index for the x and y coordinate.

You should also be able to do this entirely without indices, simply by using [filter_adjacent].
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Something strange between different directions

Post by battlestar »

Thanks, those two changes made it act like it's intended. Filter adjacent works great here.

Still interested to know why the following code ignores the south direction though :hmm:

Code: Select all

#define GET_ADJACENT_HEX ORIGIN_X ORIGIN_Y DIRECTION RESULT_STORE
[store_locations]
	[filter_adjacent_location]
		x={ORIGIN_X}
		y={ORIGIN_Y}
		adjacent="-{DIRECTION}"
	[/filter_adjacent_location]
	variable={RESULT_STORE}
[/store_locations]
#enddef
Wonder if it can be:

Code: Select all

[store_locations]
	x,y={X},{Y}

	radius=1
	variable={RESULT_STORE}
[/store_locations]
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Something strange between different directions

Post by Sapient »

That macro was only intended to handle a single direction, not a list of directions. It uses a minus sign to reverse the direction, thus when you supply a list only the first one gets reversed. Therefore "n,nw,ne,sw,se,s" becomes "-n,nw,ne,sw,se,s". As you can see the "s" or "-n" is duplicated but you have no "-s" or "n".

Another problem with that macro is that it will break when the supplied argument uses quotes.
Instead, I should have written adjacent="-"+{DIRECTION}
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Something strange between different directions

Post by mattsc »

battlestar: Since adjacent in [filter_adjacent_location] defaults to "n,ne,se,s,sw,nw", you can simply leave out the adjacent line from the macro if all you want to use it for is for getting all adjacent hexes (rather than it also to be used with different individual directions). [Or, of course, you could call the macro as is with some combination like (n,n,nw,ne,sw,se) for the reasons Sapient explained.]

The other example you give with the radius should work, except that you also get the center hex itself from it. If you just want the adjacent hexes, you'd need something like this:

Code: Select all

[store_locations]
    [and]
        x,y={X},{Y}
        radius=1
    [and]
    [not]
        x,y={X},{Y}
    [/not]
    variable={RESULT_STORE}
[/store_locations]
Note that the [and] is not optional in this case because of the way how radius works.
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Something strange between different directions

Post by battlestar »

Thanks for the explainations.

This is what I have now for the spell.

Code: Select all

#define AURA_OF_REANIMATION_DYING
	[event]
		name=last breath
		first_time_only=yes
		[filter]
			[filter_adjacent]
				id=Valia
			[/filter_adjacent]
		[not]
            race=undead
            [or]
                race=mechanical
            [/or]
        [/not]

		[/filter]
		[if]
			[variable]
				name=aura_of_reanimation
				numerical_equals=1
			[/variable]
			[then]

				[store_unit]
					[filter]
						x,y=$x1,$y1
					[/filter]
					variable=valia_reanimation_storage
					kill=no
				[/store_unit]
				[kill]
					x,y=$x1,$y1
					animate=yes
					fire_event=yes
				[/kill]
				[set_variable]
					name=success_valia_reanimation
					rand=1,1,0,0,0,0
					# 40%
				[/set_variable]
				[if]
					[variable]
						name=success_valia_reanimation
						numerical_equals=1
					[/variable]
					[then]
						[unit]
							type=Walking Corpse
							side=1
							x,y=$valia_reanimation_storage.x,$valia_reanimation_storage.y
							variation=$valia_reanimation_storage.undead_variation
							name="$valia_reanimation_storage.name"
							facing=$valia_reanimation_storage.facing	
							moves=0
						[/unit]
					[/then]
				[/if]
				[if]
					[variable]
						name=success_valia_reanimation
						numerical_equals=0
					[/variable]
					[then]
						[floating_text]
							x,y=$valia_reanimation_storage.x,$valia_reanimation_storage.y
							text= _ "failed"
						[/floating_text]
						
					[/then]
				[/if]
			[/then]
		[/if]
	[/event]
#enddef
#define AURA_OF_REANIMATION
# need to allow undo movements?
#	[event]
#		name=moveto
#		first_time_only=no
#		[filter]
#			id=Valia
#			[filter_location]
#			[/filter_location]
#		[/filter]
#		{GET_ADJACENT_HEX $x1 $y1 1 valia_aura_location}
#	[/event]
	{AURA_OF_REANIMATION_DYING}
	[event]
		name=die
		first_time_only=no
		[filter]
			[filter_adjacent]
				id=Valia
			[/filter_adjacent]
		[/filter]
		{AURA_OF_REANIMATION_DYING}
	[/event]
	
#enddef
Works exactly like planned :)

But something's not working again when I try to convert it to an ability:

Code: Select all

	#define AURA_OF_REANIMATION_DYING_ABILITY
	[event]
		name=last breath
		first_time_only=yes
		[filter]
			[filter_adjacent]
				ability=aura_of_reanimation
			[/filter_adjacent]
		[not]
            race=undead
            [or]
                race=mechanical
            [/or]
        [/not]

		[/filter]

				[store_unit]
					[filter]
						x,y=$x1,$y1
					[/filter]
					variable=valia_reanimation_storage
					kill=no
				[/store_unit]
				[kill]
					x,y=$x1,$y1
					animate=yes
					fire_event=yes
				[/kill]
				[set_variable]
					name=success_valia_reanimation
					rand=1,1,0,0,0,0
					# 40%
				[/set_variable]
				[if]
					[variable]
						name=success_valia_reanimation
						numerical_equals=1
					[/variable]
					[then]
						[unit]
							type=Walking Corpse
							side=1
							x,y=$valia_reanimation_storage.x,$valia_reanimation_storage.y
							variation=$valia_reanimation_storage.undead_variation
							name="$valia_reanimation_storage.name"
							facing=$valia_reanimation_storage.facing	
							moves=0
						[/unit]
					[/then]
				[/if]
				[if]
					[variable]
						name=success_valia_reanimation
						numerical_equals=0
					[/variable]
					[then]
						[floating_text]
							x,y=$valia_reanimation_storage.x,$valia_reanimation_storage.y
							text= _ "failed"
						[/floating_text]
						
					[/then]
				[/if]
	[/event]
#enddef
#define AURA_OF_REANIMATION_ABILITY
	{AURA_OF_REANIMATION_DYING_ABILITY}
	[event]
		name=die
		first_time_only=no
		[filter]
			[filter_adjacent]
				ability=aura_of_reanimation
			[/filter_adjacent]
		[/filter]
		{AURA_OF_REANIMATION_DYING_ABILITY}
	[/event]
	
#enddef
[b][/b]



#define ABILITY_AURA_OF_REANIMATION
    [dummy]
        id=aura_of_reanimation
        name= _ "aura of reanimation"
        description= _ "Aura of reanimation:
this unit is covered by an aura, where all units killed will have a 40% chance to become a zombie."
    [/dummy] 
[/abilities]
{AURA_OF_REANIMATION_ABILITY}
[+abilities] 
#enddef

	[event]
		name=prestart
			[modify_unit]
				[filter]
					id=Valia,Terach
				[/filter]
				[abilities]
					{ABILITY_AURA_OF_REANIMATION}
				[/abilities]
			[/modify_unit]
	[/event]
I wonder if it's because ability= is not valid in filter_adjacent, this was the only change in first macro besides taking out a set of if-then which is pretty unlikely to cause the problem. Second macro only has its name changed, and third macro and the event seem to work fine.
LUA: Llama Under Apprenticeship
Hell faction: completed
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Something strange between different directions

Post by mattsc »

bs: [filter_adjacent] is a SUF and takes ability just fine. I think the problem is that the tags and macro calls in your code are somewhat strangely arranged. You have events defined inside [modify_unit] tags. I'm not sure that your units ever get the aura ability, the way it is set up. You also have a 'last_breath' event inside a 'die' event etc. Here's a somewhat cleaner version of your code that, I think, should work. (I've also renamed your macros, just to make it clearer to myself what they are, not because I'm saying that you should use them in this way.)

Code: Select all

#define AURA_OF_REANIMATION_DEATH_EVENT
    [event]
       name=die
       first_time_only=no
       [filter]
          [filter_adjacent]
             ability=aura_of_reanimation
          [/filter_adjacent]
          [not]
             race=undead
             [or]
                 race=mechanical
             [/or]
          [/not]
       [/filter]

       [store_unit]
          [filter]
             x,y=$x1,$y1
          [/filter]
          variable=valia_reanimation_storage
          kill=no
       [/store_unit]
       [kill]
          x,y=$x1,$y1
          animate=yes
       [/kill]
       [set_variable]
          name=success_valia_reanimation
          rand=1,1,0,0,0,0
          # 40%
       [/set_variable]
       [if]
          [variable]
             name=success_valia_reanimation
             numerical_equals=1
          [/variable]
          [then]
             [unit]
                type=Walking Corpse
                side=1
                x,y=$valia_reanimation_storage.x,$valia_reanimation_storage.y
                variation=$valia_reanimation_storage.undead_variation
                name="$valia_reanimation_storage.name"
                facing=$valia_reanimation_storage.facing   
                moves=0
             [/unit]
          [/then]
       [/if]
       [if]
          [variable]
             name=success_valia_reanimation
             numerical_equals=0
          [/variable]
          [then]
             [floating_text]
                x,y=$valia_reanimation_storage.x,$valia_reanimation_storage.y
                text= _ "failed"
             [/floating_text]
             
          [/then]
       [/if]
    [/event]
#enddef

#define ABILITY_AURA_OF_REANIMATION
        [dummy]
            id=aura_of_reanimation
            name= _ "aura of reanimation"
            description= _ "Aura of reanimation:
    this unit is covered by an aura, where all units killed will have a 40% chance to become a zombie."
        [/dummy]
#enddef

    {AURA_OF_REANIMATION_DEATH_EVENT}
    [event]
       name=prestart
          [modify_unit]
             [filter]
                id=Valia,Terach
             [/filter]
             [abilities]
                {ABILITY_AURA_OF_REANIMATION}
             [/abilities]
          [/modify_unit]
    [/event]
Also note that the way you have coded it, the chance of this event is 33%, not 40%
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Ability: morphing- gryphon form

Post by battlestar »

reply to above posts
Originally I thought it needed the fire_event=yes to allow other events fire, so the nesting events stopped it from looping out of control. Turns out fire_event=yes wasn't necessary since other name=die events fires properly with what you have here. Thanks mattsc.
New stuff:

Ability: When a unit with this ability is selected, right click menu displays option of "transform", and that unit will become a gryphon to prowl the sky. It allows a unit to change to a gryphon and cross mountains before changing back to original form to strike its enemies, or strike in gryphon's form. Note: if there are abilities or items added onto the unit by wml, transforming will revert them back to basic units without them.

ImageIs there a way to save a unit's list of abilities and attacks into an array?
Gryphon From Ability

Code: Select all

#define ABILITY_GRYPHON_FORM ORIGINAL_FORM
        [dummy]
            id=gryphon_form
            name= _ "Gryphon Form"
            description= _ "Gryphon Form:
    this unit can morph shape between " + {ORIGINAL_FORM} + " and Gryphon, at the cost of 1 move."
        [/dummy]
#enddef
#define TRANSFORM_MENU_REPEATS EVENT_NAME FILTER_WML FILTER_SECOND VAR_STORE 
    [event]
        name={EVENT_NAME}

        first_time_only=no

        [filter]
            side=$side_number
			{FILTER_WML}
        [/filter]
		{FILTER_SECOND}

        [store_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            variable={VAR_STORE}
        [/store_unit]
    [/event]
#enddef
#define TRANSFORM_MENU_ITEM ABILITY_ID ORIGINAL_TYPE NEW_TYPE ABILITY_NAME
    {TRANSFORM_MENU_REPEATS select (ability={ABILITY_ID}) () last_transformer_unit}
	{TRANSFORM_MENU_REPEATS moveto (
	ability={ABILITY_ID}
	[filter_location]
	[/filter_location]
	) () last_transformer_unit}
	{TRANSFORM_MENU_REPEATS moveto (
	[filter_location]
	[/filter_location]
	) () last_selected_unit}
	{TRANSFORM_MENU_REPEATS (attack end) () (
	[filter_second]
	[/filter_second]
	) last_selected_unit}
	{TRANSFORM_MENU_REPEATS (attack end) (ability={ABILITY_ID}) (
	[filter_second]
	[/filter_second]
	) last_transformer_unit}
	
	[event]
        name=select

        first_time_only=no

        [filter]
            side=$side_number
        [/filter]

        [store_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            variable=last_selected_unit
        [/store_unit]
		[set_menu_item]
			id=valia_transformation_menu
			description= _ "Transform"
			[show_if]
				[variable]
					name=last_transformer_unit.underlying_id
					numerical_equals=$last_selected_unit.underlying_id
				[/variable]
				[and]
					[variable]
						name=last_transformer_unit.moves
						greater_than_equal_to=1
					[/variable]
				[/and]
				[and]
					[variable]
						name=last_transformer_unit.attacks_left
						greater_than_equal_to=1
					[/variable]
				[/and]
			[/show_if]
			[command]
				
				[if]
					[have_unit]
						x,y=$last_transformer_unit.x,$last_transformer_unit.y
						type={NEW_TYPE}
					[/have_unit]
						
						# ### need to fix if items are owned?
					[then]
						
						[modify_unit]
							[filter]
								x,y=$last_transformer_unit.x,$last_transformer_unit.y
							[/filter]
							type={ORIGINAL_TYPE}
						[/modify_unit]
						[store_unit]
							[filter]
								x,y=$last_transformer_unit.x,$last_transformer_unit.y
							[/filter]
							variable=new_transformer_unit
						[/store_unit]
						[modify_unit]
							[filter]
								x,y=$last_transformer_unit.x,$last_transformer_unit.y
							[/filter]
							hitpoints=$($last_transformer_unit.hitpoints/1)
							max_hitpoints=$($last_transformer_unit.max_hitpoints/1)	
							moves=$($($new_transformer_unit.max_moves-$($last_transformer_unit.max_moves-$last_transformer_unit.moves))-1)
							experience=$last_transformer_unit.experience
							max_experience=$last_transformer_unit.max_experience
								[abilities]
									{{ABILITY_NAME} "{ORIGINAL_TYPE}"}
								 [/abilities]
								 [status]
									poisoned=$last_transformer_unit.status.poisoned
									petrified=$last_transformer_unit.status.petrified
									slowed=$last_transformer_unit.status.slowed
								 [/status]
						[/modify_unit]
					[/then]
					[else]
						
						[modify_unit]
							[filter]
								x,y=$last_transformer_unit.x,$last_transformer_unit.y
							[/filter]
							type={NEW_TYPE}
						[/modify_unit]
						[store_unit]
							[filter]
								x,y=$last_transformer_unit.x,$last_transformer_unit.y
							[/filter]
							variable=new_transformer_unit
						[/store_unit]
						[modify_unit]
							[filter]
								x,y=$last_transformer_unit.x,$last_transformer_unit.y
							[/filter]
							hitpoints=$($last_transformer_unit.hitpoints/1)
							max_hitpoints=$($last_transformer_unit.max_hitpoints/1)	
							moves=$($($new_transformer_unit.max_moves-$($last_transformer_unit.max_moves-$last_transformer_unit.moves))-1)
							experience=$last_transformer_unit.experience
							max_experience=$last_transformer_unit.max_experience
								 [abilities]
									{{ABILITY_NAME} "{ORIGINAL_TYPE}"}
								 [/abilities]
								 [status]
									poisoned=$last_transformer_unit.status.poisoned
									petrified=$last_transformer_unit.status.petrified
									slowed=$last_transformer_unit.status.slowed
								 [/status]
						[/modify_unit]
						[set_variable]
							name=last_transformer_speech
							rand=1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
						[/set_variable]
						[switch]
							variable=last_transformer_speech
							[case]
								value="1"
								{MESSAGE $last_transformer_unit.id () ("") ("My old self was fine, but now I'm 20% more feathery!")}
							[/case]
							[else]
							[/else]
						[/switch]
					[/else]
				[/if]
			[/command]
		[/set_menu_item]
    [/event]

#enddef
{TRANSFORM_MENU_ITEM gryphon_form Ghoul Gryphon ABILITY_GRYPHON_FORM}

    [event]
       name=prestart
          [modify_unit]
             [filter]
                id=Terach
             [/filter]
             [abilities]
                {ABILITY_GRYPHON_FORM "Ghoul"}
             [/abilities]
          [/modify_unit]
    [/event]
Ability: This ability allows the summoning of 3 rats every 6 turns, and each summoned rat would disappear 3 turns after summoning (if they aren't dead by then). Try it out with multiple units on the map with this ability ;)
Call of the Wild

Code: Select all

#define ABILITY_CALL_OF_THE_WILD
        [dummy]
            id=call_of_the_wild
            name= _ "Call of the Wild"
            description= _ "Call of the Wild:
    this unit will be able to summon three wild rats to aid in battle for three turns. This spell recharges every six turns."
        [/dummy]
#enddef

#define CALL_OF_THE_WILD_ABILITY_MENU TYPE_OF_SUMMON NAME_OF_SUMMON
		# {MESSAGE narrator () "summoner_cotw_last_selected.underlying_id" "$summoner_cotw_last_selected.underlying_id"}
		# {MESSAGE narrator () "summoner_cotw_store[$i].underlying_id" "$summoner_cotw_store[$i].underlying_id"}
		# {MESSAGE narrator () "summoner_cotw_store[$i].cool_down" "$summoner_cotw_store[$i].cool_down"}
		[set_menu_item]
			id=valia_cotw_ability_menu
			description= _ "Call of the Wild"
			[show_if]
				[variable]
					name=cotw_ability_menu
					numerical_equals=1
				[/variable]
			[/show_if]
			[command]
					
				[set_variable]
					name=summoner_cotw_store[$current_summoner_cotw.index].creature_1_id
					value="cotw_summon_" + "$summoned_cotw_index"
				[/set_variable]
				[set_variable]
					name=summoned_cotw_index
					add=1
				[/set_variable]
				[unit]
					type={TYPE_OF_SUMMON}
					side=$current_summoner_cotw.side
					x,y=$current_summoner_cotw.x,$current_summoner_cotw.y
					name="{NAME_OF_SUMMON}"
					id=$summoner_cotw_store[$current_summoner_cotw.index].creature_1_id
				[/unit]
				
				[set_variable]
					name=summoner_cotw_store[$current_summoner_cotw.index].creature_2_id
					value="cotw_summon_" + "$summoned_cotw_index"
				[/set_variable]
				[set_variable]
					name=summoned_cotw_index
					add=1
				[/set_variable]
				[unit]
					type={TYPE_OF_SUMMON}
					side=$current_summoner_cotw.side
					x,y=$current_summoner_cotw.x,$current_summoner_cotw.y
					name="{NAME_OF_SUMMON}"
					id=$summoner_cotw_store[$current_summoner_cotw.index].creature_2_id
				[/unit]
				
				[set_variable]
					name=summoner_cotw_store[$current_summoner_cotw.index].creature_3_id
					value="cotw_summon_" + "$summoned_cotw_index"
				[/set_variable]
				[set_variable]
					name=summoned_cotw_index
					add=1
				[/set_variable]
				[unit]
					type={TYPE_OF_SUMMON}
					side=$current_summoner_cotw.side
					x,y=$current_summoner_cotw.x,$current_summoner_cotw.y
					name="{NAME_OF_SUMMON}"
					id=$summoner_cotw_store[$current_summoner_cotw.index].creature_3_id
				[/unit]
				
				[modify_unit]
					[filter]
						id=$summoner_cotw_last_selected.id
					[/filter]
					moves=0
					attacks_left=0
				[/modify_unit]
				[set_variable]
					name=summoner_cotw_store[$current_summoner_cotw.index].cool_down
					value=6
				[/set_variable]
				[set_variable]
					name=cotw_ability_menu
					value=0
				[/set_variable]
			[/command]
		[/set_menu_item]
#enddef

#define CALL_OF_THE_WILD_ABILITY TYPE_OF_SUMMON NAME_OF_SUMMON
	[event]
		name=prestart
		[set_variable]
			name=summoned_cotw_index
			value=0
		[/set_variable]
		[set_variable]
			name=summoner_cotw_index
			value=0
		[/set_variable]
		[store_unit]
			[filter]
				ability=call_of_the_wild
			[/filter]
			variable=summoner_cotw_raw_store 
		[/store_unit]
		{FOREACH summoner_cotw_raw_store i}
			[set_variable]
				name=summoner_cotw_store[$i].underlying_id
				value=$summoner_cotw_raw_store[$i].underlying_id
			[/set_variable]
			[set_variable]
				name=summoner_cotw_store[$i].cool_down
				value=0
			[/set_variable]
			
			[set_variable]
				name=summoner_cotw_index
				add=1
			[/set_variable]
			
		{NEXT i}
		{CLEAR_VARIABLE summoner_cotw_raw_store}
	[/event]
	[event]
		name=recruit
		first_time_only=no # ?
		[filter]
			ability=call_of_the_wild
		[/filter]
		[set_variable]
			name=summoner_cotw_store[$summoner_cotw_index].underlying_id
			value=$summoner_cotw_raw_store[$summoner_cotw_index].underlying_id
		[/set_variable]
		[set_variable]
			name=summoner_cotw_store[$summoner_cotw_index].cool_down
			value=0
		[/set_variable]
		[set_variable]
			name=summoner_cotw_index
			add=1
		[/set_variable]
	[/event]

	[event]
		name=post_advance
		first_time_only=no # ?
		[filter]
			ability=call_of_the_wild
		[/filter]
		[set_variable]
			name=summoner_cotw_store[$summoner_cotw_index].underlying_id
			value=$summoner_cotw_raw_store[$summoner_cotw_index].underlying_id
		[/set_variable]
		[set_variable]
			name=summoner_cotw_store[$summoner_cotw_index].cool_down
			value=0
		[/set_variable]
		[set_variable]
			name=summoner_cotw_index
			add=1
		[/set_variable]
	[/event]
	[event]
		name=select
		first_time_only=no
		[filter]
			side=$side_number
		[/filter]
		[store_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            variable=last_selected_unit
        [/store_unit]
	[/event]
	
	[event]
		name=select
		first_time_only=no
		[filter]
			ability=call_of_the_wild
			side=$side_number
		[/filter]
		[store_unit]
			[filter]
				x,y=$x1,$y1
			[/filter]
			variable=summoner_cotw_last_selected
		[/store_unit]
		# FOREACH modified
		{VARIABLE i 0}
		[while]
			[variable]
			name=i
			less_than=$summoner_cotw_store.length
			[/variable]
			[not]
			[variable]
				name=summoner_cotw_last_selected.underlying_id
				numerical_equals=$summoner_cotw_store[$($i-1)].underlying_id
			[/variable]
			[/not]
			[do]
						
				[if]
					[variable]
						name=summoner_cotw_last_selected.underlying_id
						numerical_equals=$summoner_cotw_store[$i].underlying_id
					[/variable] 
					[and]
					[variable]
						name=summoner_cotw_store[$i].cool_down
						numerical_equals=0
					[/variable]
					[/and]
					[and]
					[variable]
						name=summoner_cotw_last_selected.moves
						numerical_equals=$summoner_cotw_last_selected.max_moves
					[/variable]
					[/and]
					[then]
						[set_variable]
							name=current_summoner_cotw.index
							value=$i
						[/set_variable]
						[set_variable]
							name=current_summoner_cotw.x
							value=$x1
						[/set_variable]
						[set_variable]
							name=current_summoner_cotw.y
							value=$y1
						[/set_variable]
						[set_variable]
							name=current_summoner_cotw.side
							value=$side_number
						[/set_variable]
						[set_variable]
							name=cotw_ability_menu
							value=1
						[/set_variable]
						# {MESSAGE narrator () "" "turn on $i"}
					{CALL_OF_THE_WILD_ABILITY_MENU {TYPE_OF_SUMMON} {NAME_OF_SUMMON}}
					[/then]
					[else]
						# {MESSAGE narrator () "" "shut off $i"}
						[set_variable]
							name=cotw_ability_menu
							value=0
						[/set_variable]
					[/else]
				[/if]
		{NEXT i}
	[/event]

	[event]
		name=new turn
		first_time_only=no
		# {MESSAGE narrator () "" "what"}
		{FOREACH summoner_cotw_store i}
			[if]
				[variable]
					name=summoner_cotw_store[$i].cool_down
					greater_than_equal_to=1
				[/variable]
				[then]
					[set_variable]
						name=summoner_cotw_store[$i].cool_down
						sub=1
					[/set_variable]
				[/then]
			[/if]
			
			[if]
				[variable]
					name=summoner_cotw_store[$i].cool_down
					numerical_equals=3
				[/variable]
				[then]
					[kill]
						id=$summoner_cotw_store[$i].creature_1_id,$summoner_cotw_store[$i].creature_2_id,$summoner_cotw_store[$i].creature_3_id
					[/kill]
				[/then]
			[/if]
		{NEXT i}
	[/event]
#enddef

    [event]
       name=prestart
          [modify_unit]
             [filter]
                id=Terach,Valia
             [/filter]
             [abilities]
                {ABILITY_CALL_OF_THE_WILD}
	             [/abilities]
          [/modify_unit]
    [/event]
	{CALL_OF_THE_WILD_ABILITY (Giant Rat) (wild rat)}
If anyone finds any bugs that I missed, please let me know, thanks.
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Ability: temporary summons- call of the wild

Post by Sapient »

Did you add the new attacks and abilities via objects or by using direct modification of the unit's variable?
They should be preserved if added via objects.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Ability: temporary summons- call of the wild

Post by battlestar »

The original problem that prompted me to ask was this:
I directly modified a unit's variable to add the Gryphon form ability, during testing I reallized whenever [modify_unit] changes the unit type, it looses the added ability and reverts back to the basic unit without the ability. I added the gryphon form ability back to the unit every time after transforming, but any other abilities or attacks this unit picked up during the course of an imaginary campaign would be lost at this point.

What you said reminded me about another "spell" I was writing, for that one an ability is added then removed later automatically, by the look of how Objects use effectWML... an ability could be removed by using EffectWML (remove_ability) right? Where do I find an example of this?
Spoiler:

Weapon special: Petrification
Weapons with this special ability turns its victim into a stone for the remainder of the turn. The attack defend retaliation sequence of the current attack still plays out like normal.
Petrification weaponry

Code: Select all

#define WEAPON_SPECIAL_PETRIFICATION
    [dummy]
        id=valia_petrification
        name= _ "petrification"
        description=_ "Petrification: When a weapon with this ability hits its target, the victim turns into stone for one turn"
    [/dummy] 
#enddef

#define WEAPON_SPECIAL_PETRIFICATION_EVENT
[event]
	name=attacker hits
	first_time_only=no
	[filter_attack]
		id=valia_petrification
	[/filter_attack]
	[store_unit]
		[filter]
			x,y=$x2,$y2
		[/filter]
		variable=petrified_temp_save
	[/store_unit]
	[modify_unit]
		[filter]
			x,y=$x2,$y2
		[/filter]
		[status]
			petrified=yes
		[/status]
	[/modify_unit]
	[set_variables]
		name=petrified_by_weapon_list[0]
		mode=insert
		[value]
			save_id=$petrified_temp_save.id
		[/value]
	[/set_variables]
	[set_variable]
		name=petrified_by_weapon_list[0].cool_down
		value=1 # 1 turn cool down
	[/set_variable]
	[set_variable]
		name=petrified_by_weapon_list[0].poisoned
		value=$petrified_temp_save.status.poisoned
	[/set_variable]
	[set_variable]
		name=petrified_by_weapon_list[0].slowed
		value=$petrified_temp_save.status.slowed
	[/set_variable]
[/event]
[event]
	name=new turn
	first_time_only=no
	{FOREACH petrified_by_weapon_list i}
	# {MESSAGE narrator () "petrified_by_weapon_list[$i].cool_down" "$petrified_by_weapon_list[$i].cool_down"}
		[if]
			[variable]
				name=petrified_by_weapon_list[$i].cool_down
				greater_than_equal_to=1
			[/variable]
			[then]
				[set_variable]
					name=petrified_by_weapon_list[$i].cool_down
					sub=1
				[/set_variable]
				# {MESSAGE narrator () "petrified_by_weapon_list[$i].cool_down" "$petrified_by_weapon_list[$i].cool_down"}
			
				[if]
					[variable]
						name=petrified_by_weapon_list[$i].cool_down
						numerical_equals=0
					[/variable]
					[then]
						# {MESSAGE narrator () "petrified_by_weapon_list[$i].save_id" "$petrified_by_weapon_list[$i].id"}
						[modify_unit]
							[filter]
								id=$petrified_by_weapon_list[$i].save_id
							[/filter]
							[status]
								petrified=no
								slowed=$petrified_by_weapon_list[$i].slowed
								poisoned=$petrified_by_weapon_list[$i].poisoned
							[/status]
						[/modify_unit]
						{CLEAR_VARIABLE petrified_by_weapon_list[$i]}
					[/then]
				[/if]
			[/then]
		[/if]	
	{NEXT i}
[/event]
#enddef
{WEAPON_SPECIAL_PETRIFICATION_EVENT}
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Ability: temporary summons- call of the wild

Post by pyrophorus »

battlestar wrote: Weapon special: Petrification
Weapons with this special ability turns its victim into a stone for the remainder of the turn. The attack defend retaliation sequence of the current attack still plays out like normal.
attacks_left=0 should do the trick. See here where to insert it in your code:

Code: Select all

#define WEAPON_SPECIAL_PETRIFICATION_EVENT
[event]
	name=attacker hits
	first_time_only=no
	[filter_attack]
		id=valia_petrification
	[/filter_attack]
	[store_unit]
		[filter]
			x,y=$x2,$y2
		[/filter]
		variable=petrified_temp_save
	[/store_unit]
	[modify_unit]
		[filter]
			x,y=$x2,$y2
		[/filter]
		[status]
			petrified=yes
		[/status]
# --- this should avoid new attacks
		attacks_left=0
	[/modify_unit]
Hope this helps...

LS
Post Reply