help for add-ons

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.
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

Code: Select all

[modification]
    id=Loyalty_Mod
    name= _ "Units Loyal Mod"
    description= _ "If this mod is on, then all your units become loyal."
    require_modification=yes
	type=hybrid

    [event]
        name=recruit
		id=unit_loyal
		first_time_only=no
        [modify_unit]
            type=Dread Bat,Beelzebub,Akula_steel_finale,Dark Dragon,Dust Devil,Fire Dragon,Flower of Evil,Hatredshroom,Hellhound,Ice Dragon,Ice Spirit,Ixthala Demon,Kraken,Machine Vorpal,Sea Serpent,Spell Eater,Elvish Assassin,Elvish Gryphon Rider,Elvish Juggernaut,Elvish Nightprowler,Elvish Overlord,Elvish Seer,Elvish Sprite,Elvish Warlord,Faerie Incarnation,Snow Hunter,Corrupted Elvish Juggernaut,Corrupted Elvish Nightprowler,Corrupted Quenoth Elf,Divine Avatar,Siege Troll,Troll Boulderlobber,Armageddon Drake,Corrupted Armageddon Drake,Drake Enforcer,Corrupted Drake Enforcer,Corrupted Drake Warrior,Hurricane Drake,Corrupted Naga Myrmidon,Arch Necromancer,Blackguard,Demon Infiltrator Messenger,Champion,Chaos Rider,Dragon Rider,Exterminator,Lunatic Knight,Prophet,Scythemaster,Stormrider,Swordmaster,Ancient Warrior,Battle Princess,Dark Mage,Demonologist,Exi Grey Mage,Exi Javelin Master,Exi Magister,Exi Nature Mage,Exi Tempest Mage,Grand Knight,Grand Marshal,Grandmaster Bowman,Great Mage,Halberdier,Haldric II,Horse Lord,Noble Lord,Paladin,The Prince,Vampire Guard,Vampire Iron Mauler,Vampire Overlord,Warlock,Mermaid Diviner,Mermaid Siren,Merman Brawler,Merman Child King,Merman Entangler,Merman Hoplite,Merman Triton,Merman Javelineer,Merman Warrior King,Dune Ranger,Dune Apothecary,Dune Blademaster,Dune Cataphract,Dune Firetrooper,Dune Marauder,Dune Windrider,Great Ogre,Orcish Warmonger base,Corrupted Orcish Assassin,Orcish Nightblade loti,Orcish Strafer,Ancient Wose,Abomination,Ancient Lich,Dark Shade,Deathlord,Demilich,Grim Knight,Lich King,Reaper,Demon Soul,Dracolich,Lich Lord,Phantom,Spider Lich,Demon Despot,Celestial Messenger,Master Fabricator,Abomination,Tauroch Flagbearer,Tauroch Protector,Quenoth Champion,Quenoth Outrider,Quenoth Marksman,Quenoth Shyde,Quenoth Sun Sylph,Elder Mage,Elder Mage LotI,Infernal Knight,Zombie Rider,Knight of Oblivion,Knight of Pain,Knight of Annihilation,Destroyer,Mounted General,Eyestalk,Junior Commander,Horseman Commander,Infantry Commander,Infantry Lieutenant,Elvish Shyde,Elvish Marshal,Elvish Champion,Elvish Sylph
            [filter]
                is_enemy=no
            [/filter]               
            {TRAIT_LOYAL}
        [/modify_unit]
    [/event]
[/modification]
WhenI use this,the unit modified isn't the unit I recruited,but my leader,And it shows error:

Code: Select all

<Lua error>game_error:creating unit with an empty type found
                  stack traceback:
                    [C:]In field 'create_unit'
And something lua/wml/what what what......
User avatar
MoonyDragon
Posts: 149
Joined: November 29th, 2017, 5:46 pm

Re: help for add-ons

Post by MoonyDragon »

The event prerecruit is more fitting for modifications of newly recruited units.
It accepts the filters [filter] for the recruited and [filter_second] for the leader. I set the following code to apply to human-controlled leaders and all their recruits.
To make the recruited unit loyal, use [modify_unit] and restrict the filter to the coordinates of the primary (=recruited) unit, as specified here.

Code: Select all

[event]
    id=unit_loyal_event

    name=prerecruit
    first_time_only=no

    [filter]
        # if you want to restrict {TRAIT_LOYAL} to certain units...
    [/filter]

    [filter_second]
        [filter_side]
            controller=human
        [/filter_side]
    [/filter_second]

    [modify_unit]
        [filter]
            x,y=$x1,$y1
        [/filter]

        {TRAIT_LOYAL}
    [/modify_unit]
[/event]
Default L0 Era - Level 1 leaders with level 0 recruits!
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

I try to make a unit that increases resistance after every attack.But,it doesn't work.Is that any problem here?

Code: Select all

#textdomain wesnoth-units
[unit_type]
    id=Iron Protector
    name= _ "Iron Protector"
    race=human
    {TRAIT_FEARLESS}
    image="units/human-loyalists/siegetrooper.png"
    profile="portraits/humans/iron-mauler.png~RIGHT()"
    hitpoints=64
    movement_type=fly
    movement=10
    experience=150
    level=3
    alignment=lawful
    advances_to=null
    {AMLA_DEFAULT}
    cost=50
    description= _ "Iron Protector is some Shocktrooper that focus on defend but not attack.So that their resistance is more stronger that else,their movement is also more quickier."
    die_sound={SOUND_LIST:HUMAN_DIE}
    usage=fighter
    {DEFENSE_ANIM "units/human-loyalists/siegetrooper-defend-1.png" "units/human-loyalists/siegetrooper-defend-2.png" {SOUND_LIST:HUMAN_HIT} }
    [attack]
        name=Armor protect
        description=_"Armor protect"
        icon=attacks/rectangular-shield.png
        type=impact
        range=melee
        damage=10
        number=2
        [effect]
            apply_to=resistance
			replace=false
			[resistance]
				fire=-15
				cold=-15
				blade=-15
				impact=-15
                arcane=-15
                pierce=-15
			[/resistance]
        [/effect]
    [/attack]
    [attack_anim]
		start_time=-260
		[frame]
			image="units/human-loyalists/siegetrooper-defend-[1~2].png:[160,200]"
		[/frame]
		{SOUND:HIT_AND_MISS mace.wav {SOUND_LIST:MISS} -100}
		[frame]
			image="units/human-loyalists/siegetrooper.png:100"
		[/frame]
    [/attack_anim]
[/unit_type]
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: help for add-ons

Post by Ravana »

[effect] does nothing inside [attack].
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: help for add-ons

Post by lhybrideur »

Maybe you can create an attack special that does that with an event
something like

Code: Select all

 [event]
        name=attack end
        first_time_only=no

        [filter_attack]
            special=armor protect
        [/filter_attack]
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

lhybrideur wrote: February 20th, 2020, 1:39 pm Maybe you can create an attack special that does that with an event
something like

Code: Select all

 [event]
        name=attack end
        first_time_only=no

        [filter_attack]
            special=armor protect
        [/filter_attack]
It does nothing,either.But still thanks.
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

I just can't make that only human player can recruit this.[filter_side]doesn't work,no one can get it.Here is the code:

Code: Select all

	#part for giving units if was on
	[event]
		name=determine_recruits
		first_time_only=yes
			[event]
				name=prestart
			    [allow_recruit]
                    side=1,2,3,4,5,6,7,8,9
					type="Dread Bat,Beelzebub,Akula_steel_finale,Dark Dragon,Dust Devil,Fire Dragon,Flower of Evil,Hatredshroom,Hellhound,Ice Dragon,Ice Spirit,Ixthala Demon,Kraken,Machine Vorpal,Sea Serpent,Spell Eater,Elvish Assassin,Elvish Gryphon Rider,Elvish Juggernaut,Elvish Nightprowler,Elvish Overlord,Elvish Seer,Elvish Sprite,Elvish Warlord,Faerie Incarnation,Snow Hunter,Corrupted Elvish Juggernaut,Corrupted Elvish Nightprowler,Corrupted Quenoth Elf,Divine Avatar,Siege Troll,Troll Boulderlobber,Armageddon Drake,Corrupted Armageddon Drake,Drake Enforcer,Corrupted Drake Enforcer,Corrupted Drake Warrior,Hurricane Drake,Corrupted Naga Myrmidon,Arch Necromancer,Blackguard,Demon Infiltrator Messenger,Champion,Chaos Rider,Dragon Rider,Exterminator,Lunatic Knight,Prophet,Scythemaster,Stormrider,Swordmaster,Ancient Warrior,Battle Princess,Dark Mage,Demonologist,Exi Grey Mage,Exi Javelin Master,Exi Magister,Exi Nature Mage,Exi Tempest Mage,Grand Knight,Grand Marshal,Grandmaster Bowman,Great Mage,Halberdier,Haldric II,Horse Lord,Noble Lord,Paladin,The Prince,Vampire Guard,Vampire Iron Mauler,Vampire Overlord,Warlock,Mermaid Diviner,Mermaid Siren,Merman Brawler,Merman Child King,Merman Entangler,Merman Hoplite,Merman Triton,Merman Javelineer,Merman Warrior King,Dune Ranger,Dune Apothecary,Dune Blademaster,Dune Cataphract,Dune Firetrooper,Dune Marauder,Dune Windrider,Great Ogre,Orcish Warmonger base,Corrupted Orcish Assassin,Orcish Nightblade loti,Orcish Strafer,Ancient Wose,Abomination,Ancient Lich,Dark Shade,Deathlord,Demilich,Grim Knight,Lich King,Reaper,Demon Soul,Dracolich,Lich Lord,Phantom,Spider Lich,Demon Despot,Celestial Messenger,Master Fabricator,Abomination,Tauroch Flagbearer,Tauroch Protector,Quenoth Champion,Quenoth Outrider,Quenoth Marksman,Quenoth Shyde,Quenoth Sun Sylph,Elder Mage,Elder Mage LotI,Infernal Knight,Zombie Rider,Knight of Oblivion,Knight of Pain,Knight of Annihilation,Destroyer,Mounted General,Eyestalk,Junior Commander,Horseman Commander,Infantry Commander,Infantry Lieutenant,Elvish Shyde,Elvish Marshal,Elvish Champion,Elvish Sylph,Dwarvish Loremaster,Dwarvish Technocrat,Dwarvish Hero,Dwarvish Protector,Dwarvish Battlerager,Skeletal Dragon,acp_Evil_Eye,acp_Black_Dragon,acp_Hydraa_3,acp_Goliath,acp_Cosmic_Eye,acp_Ancient_vase,acp_Magic_Breaker,acp_Battle_Hammer,acp_knife,acp_necklace_Acorn,acp_Air,acp_Earth,acp_Fire,acp_Water,
acp_Armageddon_Imp,acp_myriapod,acp_dragonfly_nymph"
				[/allow_recruit]
	        [/event]
    [/event]
User avatar
MoonyDragon
Posts: 149
Joined: November 29th, 2017, 5:46 pm

Re: help for add-ons

Post by MoonyDragon »

Almost. The second [event] tag is unnecessary, and at last time I checked, [filter_side] does work.

Code: Select all

[event]
    id=determine_human_recruits
    name=prestart

    [allow_recruit]
        [filter_side]
            controller=human
        [/filter_side]

        type= # insert the human-specific recruits here
    [/allow_recruit]
[/event]
Default L0 Era - Level 1 leaders with level 0 recruits!
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

MoonyDragon wrote: February 24th, 2020, 4:52 pm Almost. The second [event] tag is unnecessary, and at last time I checked, [filter_side] does work.

Code: Select all

[event]
    id=determine_human_recruits
    name=prestart

    [allow_recruit]
        [filter_side]
            controller=human
        [/filter_side]

        type= # insert the human-specific recruits here
    [/allow_recruit]
[/event]
But this one make ai can recruit them.
User avatar
MoonyDragon
Posts: 149
Joined: November 29th, 2017, 5:46 pm

Re: help for add-ons

Post by MoonyDragon »

zijing wrote: February 24th, 2020, 9:34 pm But this one make ai can recruit them.
Reviewing my (admittedly tested only superficially...) code after your reply, I discovered that side filter keys have to be inserted without a [filter_side] parent.
This should work...

Code: Select all

[allow_recruit]
	controller=human
	type= # insert the human-specific recruits here
[/allow_recruit]
Default L0 Era - Level 1 leaders with level 0 recruits!
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

Thanks And I would like to ask,how should I use this filter to make it only effected on enemy but not with allie?

Code: Select all

			[filter]
				[filter_adjacent]
					x,y=$x2,$y2
				[/filter_adjacent]
				[not]
					x,y=$x2,$y2
				[/not]
				[not]
					x,y=$x1,$y1
				[/not]
			[/filter]
			[filter_second]
				x,y=$x1,$y1
			[/filter_second]
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: help for add-ons

Post by EarthCake »

Use:

Code: Select all

[filter_adjacent]
    x,y=$x2,$y2
    is_enemy=yes
[/filter_adjacent] 
One remark: when you use [filter_adjacent] tag, don't put it inside [filter] tag.
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

EarthCake wrote: February 26th, 2020, 11:21 am Use:

Code: Select all

[filter_adjacent]
    x,y=$x2,$y2
    is_enemy=yes
[/filter_adjacent] 
One remark: when you use [filter_adjacent] tag, don't put it inside [filter] tag.

Code: Select all

		[harm_unit]
            [filter]
			    [filter_adjacent]
				    x,y=$x2,$y2
                    is_enemy=yes
			    [/filter_adjacent]
			    [not]
			        x,y=$x2,$y2
			    [/not]
			    [not]
				    x,y=$x1,$y1
			    [/not]
            [/filter]
			[filter_second]
				x,y=$x1,$y1
			[/filter_second]
			amount=$($($damage*3)/4-4)
			damage_type=$weapon.type
			fire_event=yes
			experience=no
		[/harm_unit]
Actually it also harm my ally.
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: help for add-ons

Post by EarthCake »

Sorry, I had to be more clear.

Code: Select all

[filter_adjacent]
    x,y=$x2,$y2
    is_enemy=yes
[/filter_adjacent]
[filter]
    [not]
        x,y=$x2,$y2
    [/not]
    [not]
        x,y=$x1,$y1
    [/not]
[/filter]
If it still doesn't work, look at this wiki page and search for [filter_adjacent] there.
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

EarthCake wrote: February 27th, 2020, 11:35 pm Sorry, I had to be more clear.

Code: Select all

[filter_adjacent]
    x,y=$x2,$y2
    is_enemy=yes
[/filter_adjacent]
[filter]
    [not]
        x,y=$x2,$y2
    [/not]
    [not]
        x,y=$x1,$y1
    [/not]
[/filter]
If it still doesn't work, look at this wiki page and search for [filter_adjacent] there.
It works,but it harms all the unit on the map,not whether it is enemy or ally,and my game crashes
Post Reply