Changing Alignment with a Trait

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
BedazzleHooves
Posts: 9
Joined: October 12th, 2014, 9:45 pm
Location: United States, Colorado

Changing Alignment with a Trait

Post by BedazzleHooves »

Howdy all... I'm trying to make my first add-on and I am pretty far along, but there is one thing I can't seem to figure out....

I want to add a trait that changes alignment. Like if a Loyalist_Spearman spawned with the trait "Darkheart", they would be Chaotic.

I've tried quite a few ways and this is what I have now... It doesn't crash, but it also doesn't work. All the rest of my traits work fine, but I just don't know what to do to fix this one. Any advice would be greatly appreciated.

Code: Select all

 

#define TRAIT_DARKHEART
	[trait]
		id=BH_Darkheart
		male_name=_"Darkheart"
		female_name=_"female^Darkheart"
		description=_"Is Chaotic."
                [effect]
			apply_to=alignment
                        replace=yes
			alignment=chaotic
		[/effect]
         [/trait]
#enddef

Co-Op for all!
User avatar
doofus-01
Art Director
Posts: 4122
Joined: January 6th, 2008, 9:27 pm
Location: USA

Re: Changing Alignment with a Trait

Post by doofus-01 »

Not something I've tried, but I think you could define a chaotic [variation], if this is a unit you are writing the code for, then use [trait]/[effect] to apply that variation.
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
User avatar
Ravana
Forum Moderator
Posts: 2952
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Changing Alignment with a Trait

Post by Ravana »

Havent tried this with trait, only ability, but +tag way might work here too.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: Changing Alignment with a Trait

Post by tekelili »

Other ways proposed can also work. I have changed aligments and my aproach would be write an event inside unit that fires for unit with trait "darkheart"

Code: Select all

[trait]
    id=darkheart
    male_name= "darkheart" 
    female_name= "femmale^darkheart"
    description= "bla bla bla"
[/trait]
[event]
    id=darkheart_aligment
    name=post advance,recruit
    first_time_only=no
    [filter]
        [filter_wml]
            [modifications]
                [trait]
                    id=darkheart
                [/trait]
            [/modifications]
        [/filter_wml]
    [/filter]
    [modify_unit]
        [filter]
            x,y=$x1,$y1
        [/filter]
        aligment=chaotic
    [/modify_unit]
[/event]
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
BedazzleHooves
Posts: 9
Joined: October 12th, 2014, 9:45 pm
Location: United States, Colorado

Re: Changing Alignment with a Trait

Post by BedazzleHooves »

Thank you all for your aid. But I am still quite the noob....

doofus-01 wrote:Not something I've tried, but I think you could define a chaotic [variation], if this is a unit you are writing the code for, then use [trait]/[effect] to apply that variation.
From what I'm seeing, that would work great... however, there will be a lot of different units I would like to have this trait, and putting [variation] in all of them would take a long time from what I am seeing. Though I might not understand the code right (Been using WML for less than a week).

Ravana wrote:Havent tried this with trait, only ability, but +tag way might work here too.
I have used a trait to give a unit an ability in my Add-On already. If you could just tell me which ability it is so I can go take a look at it, I would be very thankful.

tekelili wrote:Other ways proposed can also work. I have changed aligments and my aproach would be write an event inside unit that fires for unit with trait "darkheart"

This seems like it should work... however, it isn't working for me. I haven't ever put an event in a unit file before and am not quite sure where to put it... Does it go inside or outside the [unit_type] tags? Are there other tags that it needs embedded in? Any help with where to put it would be greatly appreciated.
Co-Op for all!
User avatar
Ravana
Forum Moderator
Posts: 2952
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Changing Alignment with a Trait

Post by Ravana »

I meant +tag like https://github.com/ProditorMagnus/Agele ... attack.cfg . Instead of attacks=2 you put what you want to change for each unit with that ability/trait. I believe with trait you just need to use different tags around code you want to change.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: Changing Alignment with a Trait

Post by tekelili »

BedazzleHooves wrote:
tekelili wrote:Other ways proposed can also work. I have changed aligments and my aproach would be write an event inside unit that fires for unit with trait "darkheart"
This seems like it should work... however, it isn't working for me. I haven't ever put an event in a unit file before and am not quite sure where to put it... Does it go inside or outside the [unit_type] tags? Are there other tags that it needs embedded in? Any help with where to put it would be greatly appreciated.
You can find an [event] inside [unit_type] looking ghoul. Anyway, that is more complicated than write events directly inside [scenario] and last one would work almost as well (I prefer it because assure load event in campaigns and keeps code near unit related). Use event is pretty straight forward but I guess is not the most clean solution for [era], because if you create a unit using [unit], it wouldn´t fire any event, so up to you if go for that solution.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Post Reply