WML RESOURCES by enclave

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.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

WML RESOURCES by enclave

Post by enclave »

I often had and still have many questions on "how to" do something in WML...
So I decided that there may be some people who may want to know the results or just use some of codes I was coming across in my works and it may save tons of time I guess..
So I will be posting here codes of abilities and whatever else I may find interesting for others. I hope nobody minds. (You can find a lot more if you download my add-ons and go through them, but we all know it's usually a mess. Here will be separate codes.. no need to look for anything and trying to figure out what it does and why). I hope will be helpful to at least somebody.
Thank you!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Flank abilities.
I wanted to make a code where units surrounded by enemy units would become weaker and get more damage, depending on how many enemy units around.

1) Abilities to become weaker if surrounded by enemy units with ability id=cg_flank
Spoiler:
2) Effect that makes enemy units become stronger against surrounded unit. Similar to backstab or charge attack specials.
Spoiler:
Last edited by enclave on August 23rd, 2016, 1:39 am, edited 1 time in total.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Rage attack special (unit attacks 3 times in a row) - shortened berserk version

Need to put it into [unit] following these tags (need to know name of attack that you want to apply it to, also I assume it can go into [unit_type] tag same as in [unit], but I never tried):
Spoiler:
User avatar
Eagle_11
Posts: 759
Joined: November 20th, 2013, 12:20 pm

Re: WML RESOURCES by enclave

Post by Eagle_11 »

which version of wesnoth are you modding ? because it has been quite a while since [unit] transformed into [unit_type]
besides, you can simply just give the rage spec into the attack's [specials] without having to apply as you did, since you are already putting it into [unit_type]
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

hi Eagle_11. I'm on 1.12, but I must have mislead you and/or others wit unit and unit type.. I didn't mean to say that unit transforms into unit type :D was it ever like that? :D
and I don't know where you found that I put something into unit_type, because I don't use unit_type at all :) if you use unit_type in 1.12 then people will need to download your add-on to play. Which I don't want because then my mod will lose more than half players, or even 99.9%. So I'm only using [unit] tags, never [unit_type].
Maybe would be better if you could post the code on how to put rage into attack specials in [unit_type], otherwise your post doesn't look helpful to people, but thanks for trying.
User avatar
Eagle_11
Posts: 759
Joined: November 20th, 2013, 12:20 pm

Re: WML RESOURCES by enclave

Post by Eagle_11 »

Code: Select all

#define WEAPON_SPECIAL_RAGE
    [berserk]
        id=rage
        name=_ "rage"
        description= _ "Unit performs this attack 3 times. Similar to Berserk."
        value=3
    [/berserk]
#enddef

Code: Select all

[unit_type]
...
[attack]
name=club
...
[specials]
     {WEAPON_SPECIAL_RAGE}
[/specials]
...
[/attack]
...
[/unit_type]
You dont need to use [modification] or apply it with an [object] since you already are modifying the unit's .cfg and can tell it directly so.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Some ways to apply image overlays to your units
1) using [unit_overlay] (keep in mind this way image will not rotate depending on where your unit is facing)
Spoiler:
2) same idea (image will not rotate with unit).. different way.. by using {VARIABLE stored_unit.overlays
Spoiler:
3) using [object] and image_mod... the image will rotate with your unit. but it may be more complicated to remove the overlay if you later decide to do so.
Spoiler:
4) same idea, different way.. by using {VARIABLE and image_mod
Spoiler:
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

count down the array.. instead of counting up like "{FOREACH" macro does..
The pure code would be like this:
Spoiler:
Or you could write the following code somewhere to your cfgs:
Spoiler:
And then you could just use {FOREACH_COUNTDOWN your_array_name i} and {NEXT_COUNTDOWN i} same way like you normally use {FOREACH} macro..

PS. it may be helpful if you are clearing the variables from array.. like in this example:
Spoiler:
Last edited by enclave on September 9th, 2016, 5:37 pm, edited 2 times in total.
User avatar
Astoria
Inactive Developer
Posts: 1007
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Re: WML RESOURCES by enclave

Post by Astoria »

Since arrays start at index 0, setting the iterator to the length of the array will cause the first iteration to be out of bounds. The maximum index of an array is array.length - 1.
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

bumbadadabum wrote:Since arrays start at index 0, setting the iterator to the length of the array will cause the first iteration to be out of bounds. The maximum index of an array is array.length - 1.
it sounds very much like you are right, I mean you are definitely at least half right..
for some reason it worked for me without any error messages (out of bounds), so I guess for Wesnoth it just looks like the first index ($array[array.length]) is empty or equals nothing.. or nil or whatever.
but the truth is that the first index will be outside the boundaries.. quite sure about that now.. well spotted. Thanks very much bumbadadabum!

I have corrected the code, so I believe it should be working perfectly fine now.. Thanks!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Adding some ability to some unit at coordinates x,y=5,3
Here we will try to add LEADERSHIP LVL2

To find some existing abilities just go to your wesnoth folder (Win7 for example C:\Program Files (x86)\Battle for Wesnoth 1.12.1\data\core\macros\) and open the abilities.cfg file using any text editor like word pad or notepad++

So the code follows:
Spoiler:

Macro way also just in case..:
Spoiler:
I hope I didn't do any mistakes while was typing it here.. The code was tested and it worked for me. But I can't guarantee its bug free.. but it should be. Any questions just ask. Hope it helped anyone :D
Last edited by enclave on September 9th, 2016, 5:47 pm, edited 2 times in total.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Now a funny thing..
Lets say you would like:
a unit that (1) has leadership ability
(2) does NOT have skirmisher ability (replace with whatever ability you like.. eg "cg_need_wake_up")
and (3) spotted an enemy
to (a) say something... (b) remove his leadership ability and (c) destroy spotted unit from map? :D
I spent lots of time to do it.. I believe there is more simple way, but I found my way.. and who cares.. it works!


The Code:
Spoiler:
I may have done mistakes while I was changing the working code into this dummy code.. But I hope I didn't..
If it doesn't work.. ask questions.. My code obviously wasn't removing leadership.. wasnt making unit kill somebody and didn't have a unit say anything.. My code was used for something completely different and I used 7 as a radius because I think it was sufficient in my case.. Have fun!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: WML RESOURCES by enclave

Post by zookeeper »

enclave wrote:(b) remove his leadership ability
Surely you should just use [object] [effect] apply_to=remove_ability to do that?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

zookeeper wrote:
enclave wrote:(b) remove his leadership ability
Surely you should just use [object] [effect] apply_to=remove_ability to do that?
it may be a nice way..
I personally think that 1 line looks and works much better..
{CLEAR_VARIABLE temp_armaggedon_units[$counter_u].abilities.leadership}

but maybe you could write full example for somebody who is interested in [object] version?
How would you remove leadership ability via object from unit at x=5, y=3 ?

Thank you!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: WML RESOURCES by enclave

Post by zookeeper »

enclave wrote:it may be a nice way..
I personally think that 1 line looks and works much better..
{CLEAR_VARIABLE temp_armaggedon_units[$counter_u].abilities.leadership}

but maybe you could write full example for somebody who is interested in [object] version?
How would you remove leadership ability via object from unit at x=5, y=3 ?

Thank you!

Code: Select all

[object]
    silent=yes
    
    [filter]
        x,y=5,3
    [/filter]
    
    [effect]
        apply_to=remove_ability
        
        [abilities]
            [leadership]
                id=leadership
            [/leadership]
        [/abilities]
    [/effect]
[/object]
You can remove abilities via direct variable manipulation like you did, but I think then they might suddenly re-appear when the unit gets unexpectedly rebuilt in some situation. You should generally do things like that with an [object] unless there's a specific reason not to.
Post Reply