change unit statistics at the beginning of a scenario

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
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

change unit statistics at the beginning of a scenario

Post by ultimatux »

I am beginning to develop my first test campaign, although I know programming, I get lost sometimes in the examples by the theme of the different versions of Wesnoth ...

Bluntly, I need to change some statistics of my initial units, including the leader. step fragment of my code, thank you very much


In this case I managed to place the loyal trait in modification but when I wanted to assign to 8 the movements of this unit and that of the leader, it does not allow me

Code: Select all

[side]
        side=1
        controller=human
        team_name="good"
        user_team_name= _ "My Team"
        id=MyLeader
        name= _ "My Leader's Name"
        type="Elvish Ranger"
        unrenameable=yes
 	movement=8
        canrecruit=yes
        recruit="Elvish Fighter, Elvish Archer, Elvish Shaman,Lancero Orco"
        gold=100
{NAMED_LOYAL_UNIT 1 (Wolf) 2 20 (Blacky) (_ "Blacky")}

	[unit]
        type="Lancero Orco"
        side=1
       	x,y=4,21
      	name="Chiporchi"
       	canrecruit=yes
	[modifications]	
	movement=8
 	{TRAIT_LOYAL}
	[/modifications]
	
 	overlays="misc/loyal-icon.png"
	[/unit]
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: change unit statistics at the beginning of a scenario

Post by Pentarctagon »

Moved to the WML Workshop.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: change unit statistics at the beginning of a scenario

Post by WhiteWolf »

ultimatux wrote: September 20th, 2019, 3:06 am
In this case I managed to place the loyal trait in modification but when I wanted to assign to 8 the movements of this unit and that of the leader, it does not allow me
[modifications] has a little bit different meaning, it's not where you can "modify" a unit, it's the group where [traits], [objects], and possibly some other stuff I don't recall, go to. For example the {TRAIT_LOYAL} is correctly there. However, please note that canrecruit=yes in a unit will automatically assume 0 upkeep, so the loyal trait on Chiporchi won't have any actual effect, it'll just be there.
Similarly, movement is not an accepted key inside [side] or [unit] to set a unit current moves, see the unit wiki.

The way you can modify an initial unit's moves is to actualy modify the unit. One way to go is the [modify_unit] tag.

Code: Select all

[event]
    name=start # or wherever you want it done
    [modify_unit]
        [filter]
            id=MyLeader
        [/filter]
        max_moves=8 # it's important to set the maximumum moves to 8, otherwise it would just reset on the next turn.
        moves=8
    [/modify_unit]
[/event]
This effect however might not be permanent, because max_moves might be reset if you are adding or removing other objects later on. Therefore I recommend using the other and probably nicer way, to use an [object]. It's also tracked with an id, so you can remove it later. This can be done inside an event, or inside the unit, the way you probably wanted to:

Code: Select all

[side]
    ... your side stuff, leader stuff
    id=MyLeader
    [modifications]
        [object]
            id=leader_has_8_mp
            [effect]
                apply_to=movement # this means max moves here
                set=8
            [/effect]
         [/object]
     [/modifications]
    
    {NAMED_LOYAL_UNIT 1 (Wolf) 2 20 (Blacky) (_ "Blacky")}

    [unit]
        # tip: you might want to give this unit an id if he's important
        type="Lancero Orco"
        side=1
       	x,y=4,21
      	name="Chiporchi"
       	canrecruit=yes #*
	[modifications]	
            [object]
                id=this_unit_has_8_mp
                [effect]
                    apply_to=movement # this means max moves here
                    set=8
                 [/effect]
             [/object]
 	    #{TRAIT_LOYAL} as said, this is unecessary because of previous canrecruit=yes
	[/modifications]

 	overlays="misc/loyal-icon.png" # tip: check out the {IS_LOYAL} macro
    [/unit]
[/side]
For further reference, see the wiki on [object]'s. They are useful and reliable tools to equip modifications to units.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

Re: change unit statistics at the beginning of a scenario

Post by ultimatux »

thank you very much, the second code worked for me, the first one on the other hand didn't work
User avatar
Celtic_Minstrel
Developer
Posts: 2216
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: change unit statistics at the beginning of a scenario

Post by Celtic_Minstrel »

The only actual issue with your initial code is that movement=8 was placed inside the [modifications] tag. Move it up one line and your original code should be fine. There's no need to use [modify_unit] here. That said, Whitewolf is correct that the change could be lost on level-up, so use of an [object] is preferable. But, note that that would force the unit to always have 8 MP, even if it would have otherwise gained more MP from a level-up. If that's a problem (obviously not in the Elvish Range case, but I have no clue about the other), you can add a [filter] tag in the [effect] tag that limits the effect to level 2 units.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply