Ability for replacing a killed unit with another

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
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Ability for replacing a killed unit with another

Post by Dorimen »

Hi, I want to create an ability (probably it was already done) to a unit that when is killed will be replaced with a new one. What i can do? Do I need a "dummy" tag?

Thanks for the help you can give me :)
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Ability for replacing a killed unit with another

Post by Dugi »

You are greatly unspecific. You can just use plague, maybe a custom one (check the ABILITY_PLAGUE_TYPE macro in core/macros/abilities.cfg). But I suppose that you want something different, but I can't tell what from your vague question.
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: Ability for replacing a killed unit with another

Post by Dorimen »

Sorry, I'll try to explain.
I want the unit who have the ability, when defeated will create another differnet unit on the hex where it died. It's not a special attack.

Hope I explained well this time :)
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Ability for replacing a killed unit with another

Post by ChaosRider »

event with name die, filter dead unit (cause if im not wrong this dead unit still exist), kill it and on same place create other one unit which you want.
event names

Something close to this what you have in labirynth of champions, where when you have to fight with 3 lvl mage, after his death are created 2 second lvl mages, after kiling one of them are creating 2 first lvl mages.
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: Ability for replacing a killed unit with another

Post by Dorimen »

Thanks for the help! I've found the code! I'll try to adapt it to my needs.
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: Ability for replacing a killed unit with another

Post by Dorimen »

This is the result:

Code: Select all

#define ABILITY_POSSESSION
    # When this unit die, another unit will appear in the same place.
    [event]
     name=die
     [unit]
      side=$side_number
      type=......
      x=$x
      y=$y
     [/unit]
    [/event]
#enddef
Is this right? Anyway I will test it in some days. Before I must create other things to try it
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
Velensk
Multiplayer Contributor
Posts: 4002
Joined: January 24th, 2007, 12:56 am

Re: Ability for replacing a killed unit with another

Post by Velensk »

The problem is that you can't put an event directly into an [abilities] tag and still have it be read. You will need code to have it be effectively inserted. It would look something like this special:

Code: Select all

#define WEAPON_SPECIAL_TRAMPLE
[attacks]
	id=weapon_special_trample
	name= _ "Trample"
        description= _ "On offense units with trample will gain two extra strikes and if they kill they will move into the hex of the unit they killed."
        apply_to=self
        active_on=offense
        add=2
    [/attacks]
[/specials]
[/attack]

[event]
     name=attacker hits
     first_time_only=no
     [filter_attack]
          special=weapon_special_trample
     [/filter_attack]
     [if]
        [not]
          [have_unit]
               x,y=$x2,$y2
          [/have_unit]
        [/not]
        [then]
        	[set_variable]
        		name=experience_earned
        		value=8
        	[/set_variable]
        	[if]
        		[variable]
        			name=second_unit.level
        			not_equals=0
        		[/variable]
        		[then]
		        	[set_variable]
		        		name=experience_earned
		        		multiply=$second_unit.level
		        	[/set_variable]
		        [/then]
		        [else]
		        	[set_variable]
		        		name=experience_earned
		        		value=4
		        	[/set_variable]
		        [/else]
        	[/if]
           [kill]
               x,y=$x2,$y2
               fire_event=yes
               [secondary_unit]
                   x,y=$x1,$y1
               [/secondary_unit]
           [/kill]
           [store_unit]
               [filter]
                   x,y=$x1,$y1
               [/filter]
               kill=yes
               variable=trampler
           [/store_unit]
           {VARIABLE_OP trampler.experience add $experience_earned}
           [unstore_unit]
                 variable=trampler
                 x,y=$x2,$y2
           [/unstore_unit]
           [capture_village]
                 x,y=$x2,$y2
                 side=$trampler.side
           [/capture_village]
           {CLEAR_VARIABLE experience_earned}
        [/then]
     [/if]
[/event]
[+attack]
[+specials]

#enddef

note the [+attack] and [+specials] at the end, that puts the processor back where it was when it started reading the ability. Also, you should probably create a dummy ability just so that those playing can see that you have this capability.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Ability for replacing a killed unit with another

Post by pyrophorus »

Hi !
This is a solution where no special nor ability is needed (but you can define one):

Code: Select all

#define ABILITY_IMMORTAL UNIT
# context: unit type or scenarios. Units are immediately replaced if killed.
# UNIT is a SUF (without [filter] tag) defining the able unit (ex: id=Lestiviel or type=Elvish Archer)
	[event]
		name=die
		first_time_only=no
		[filter]
			{UNIT}
		[/filter]
		
		# the kill action is necessary to free the unit position before creating a new one.
		# else, the new unit would be created on an adjacent hex.
		[store_unit]
			[filter]
				id=$unit.id
			[/filter]
			variable=tmp
			kill=yes
			animate=no
		[/store_unit]
		# this creates a new unit with no experience
		[unit]
			type=$tmp.type
			side=$tmp.side
			x,y=$tmp.x,$tmp.y
		[/unit]
		
		{CLEAR_VARIABLE tmp}
	[/event]
#enddef
or, if you prefer to keep the same unit:

Code: Select all

#define ABILITY_IMMORTAL UNIT
# context: unit type or scenarios. Units are immediately healed if killed.
# UNIT is a SUF (without [filter] tag) defining the able unit (ex: id=Lestiviel or type=Elvish Archer)
	[event]
		name=last breath
		first_time_only=no
		[filter]
			{UNIT}
		[/filter]		

		[heal_unit]
			[filter]
				id=$unit.id
			[/filter]
			amount=full
		[/heal_unit]
	[/event]
#enddef
Hope this helps !
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: Ability for replacing a killed unit with another

Post by Dorimen »

Thanks! :D

@pyrophorus: it seems more similar to what I want the first solution! Only a question. What is for "tmp"? I thought it was just this way "$x".
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
SkyOne
Posts: 1310
Joined: January 3rd, 2009, 7:23 pm

Re: Ability for replacing a killed unit with another

Post by SkyOne »

Dorimen wrote:Only a question. What is for "tmp"? I thought it was just this way "$x".
It is just a name of the variable. tmp --> temporary stored. I usually go with "temp" or "temp_store_unit-name" etc, but those are all the same.
pyrophorus probably used short one for you not to make a mistake.:)
Fate of a Princess/feedback thread: "What is in own heart that is the most important, not who you are."
Drake Campaign: Brave Wings/feedback thread, Naga Campaign: Return of the Monster, Saurian Campaign: Across the Ocean
Northern Forces - now on 1.12 server
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: Ability for replacing a killed unit with another

Post by Dorimen »

Ok! Thanks :D
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
Post Reply