Creating a new ability?

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
Mmetafour
Posts: 7
Joined: May 4th, 2017, 9:49 am

Creating a new ability?

Post by Mmetafour »

Let me start by saying, this is my first post here, and I'm not even really sure if this is the right forum to post for this kind of question, but I love wesnoth, and it seems like the supporting players are so cool! making new stuff and adding units, factions and all that jazz to the game.

I finally decided to put my skills with pixel art and coding to the test and make another faction....(after my last one was lost with my crashed laptop....)

Things have been going smoothly, but ive hit a bump in development while trying to create a unit that adds one gold to the player's total every time it kills another unit. This is a unit ability not a weapon special, more akin to the "FEEDING" ability rather than something like "BERSERK" or "POISON"

Thanks in advance for any help!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Creating a new ability?

Post by zookeeper »

Basically when you need something that isn't directly supported by AbilitiesWML, what you need is to use dummy ability tags to make it look like a normal ability to the player, but then write the actual logic as an event. If you're making a faction, then that means you're making an era, in which case you can just put [event]s directly inside your [era] tag to have them always be inserted into any scenario played using that era.

In this case, what you probably want is something like this:

Code: Select all

[event]
    name=die
    first_time_only=no

    [filter_second]
        ability=the_ability_id
    [/filter_second]

    [gold]
        side=$second_unit.side
        amount=1
    [/gold]

    [floating_text]
        x,y=$x2,$y2
        text= _ "+1 gold"
    [/floating_text]
[/event]
User avatar
Bitron
Developer
Posts: 453
Joined: October 19th, 2015, 9:23 am
Location: Germany

Re: Creating a new ability?

Post by Bitron »

Welcome to the forum then!

Maybe this Link: https://wiki.wesnoth.org/WML_Abilities#Pickpocket is useful to you.
There is some code for a "pickpocket" weapon special. There are a couple of more examples, also custom abilities so you might be able to rewrite it as you wish.

Curious to see a new faction arriving in Wesnoth! (:
User avatar
ForestDragon
Posts: 1771
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: Creating a new ability?

Post by ForestDragon »

well, something like this (not tested though, but it should theoretically work):

Code: Select all

#define ABILITY_INSERTNAMEHERE
    # Canned definition of the Feeding ability to be included in an
    # [abilities] clause.  Note: this is deliberately unbalanced WML,
    # in order to close the abilities clause then insert the event
    # then reopen the abilities clause.
    [dummy]
        id=insertnamehere
        name= _ "insertnamehere"
        female_name= _ "female^insertnamehere"
        description=_ "This unit's side gains 1 gold whenever this unit kills another unit."
    [/dummy]
    # wmlxgettext: [abilities]
[/abilities]
[event]
    id=ability_insertnamehere_die
    name=die
    first_time_only=no

    [filter_second]
        ability=insertnamehere
    [/filter_second]

    [unstore_unit]
        variable=second_unit
        text= _ "<span color='#cccc33'>" + _ "+1 gold" + "</span>"
        find_vacant=no
    [/unstore_unit]
    [gold]
      side=$second_unit.side
      amount=1
    [/gold]
[/event]
[+abilities]
    # wmlxgettext: [/abilities]
#enddef
# wmllint: unbalanced-off
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Mmetafour
Posts: 7
Joined: May 4th, 2017, 9:49 am

Re: Creating a new ability?

Post by Mmetafour »

Thanks for all the quick replies guys!

Honestly the last time I made a faction, I was in high school, my pixel art skills were horrid, and I had no internet, so I had absolutely no intention of sharing the faction I created with anyone else, because of that, my experience with "making a new faction" involved diving into the games core code and changing things directly for my OWN wesnoth files.

Which is technically what I'm doing now too....

I assume if I wanted to share the faction I'm creating now, I should be creating these tags in a different folder?

Forestdragon's ability looks like I can copy and paste it directly into the abilities.cfg, but zookeeper's looks like it belongs in a different file : O
User avatar
Bitron
Developer
Posts: 453
Joined: October 19th, 2015, 9:23 am
Location: Germany

Re: Creating a new ability?

Post by Bitron »

Well, there is a "Create" Section here: https://wiki.wesnoth.org/BuildingFactions
This should be exactly what you need to create an own era.

What you also could do is to download some UMC add-ons and look into those files to see how others made them.

EDIT: By default, the folder you are looking for is <<C:\Users\*yourName*\Documents\My Games\Wesnoth1.XX\data\add-ons>>
User avatar
ForestDragon
Posts: 1771
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: Creating a new ability?

Post by ForestDragon »

Mmetafour wrote:Forestdragon's ability looks like I can copy and paste it directly into the abilities.cfg, but zookeeper's looks like it belongs in a different file : O
you don't need to put it into the mainline file. that would be it only work for you. you should make a file like that for your add-on specifically.
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Mmetafour
Posts: 7
Joined: May 4th, 2017, 9:49 am

Re: Creating a new ability?

Post by Mmetafour »

Thanks again for the quick replies guys!
Forest, that strip of code worked out perfectly : D

Heres a little something I've been working on today, Image for one of the base units in the faction
Image
User avatar
ForestDragon
Posts: 1771
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: Creating a new ability?

Post by ForestDragon »

I suggest posting these images in the Art Workshop thread (that way it'll be easier for people to notice them, and you'll be able get some feedback/praise about them.). Looks very good, btw. Feeling quite hyped for the faction itself.
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Post Reply