Items help

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
FokaCream
Posts: 1
Joined: January 25th, 2019, 10:09 pm

Items help

Post by FokaCream » February 12th, 2019, 1:07 pm

I just spent days trying to create "collectable items" like a sword, bow or a item to enchant an attack with Magical
I was thinking of something like the Artifact Mod, i searched the entire wiki but can't unferstand how items work
I tried Using effects, events etc and even all together, but it doesn't do anything



(Preset WMLs are Welcome, also forums and sites for help)
{Yup i'm a Noob}

User avatar
Ravana
Moderator
Posts: 1963
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Items help

Post by Ravana » February 12th, 2019, 1:10 pm

Most commonly items are implemented as [object][effect]. Effect can also be added as trait https://github.com/ProditorMagnus/Oroci ... #L263-L277

User avatar
James_The_Invisible
Posts: 495
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: Items help

Post by James_The_Invisible » February 12th, 2019, 3:03 pm

You can find some examples in mainline. Look at data/core/macros/items.cfg. Several mainline campaigns also make use of them so you can check them out. (User-made campaign Legend of the Invincibles also makes heavy use of them but it might be too complicated for someone who is new to WML.)

User avatar
beetlenaut
Developer
Posts: 2271
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Items help

Post by beetlenaut » February 12th, 2019, 11:19 pm

Here are two examples from UtBS with a lot of irrelevant code removed. The first gives the unit a ring of speed when it enters the hex. This is about the bare minimum code required to add an object to a unit. The second example shows how it is usually done in a game. It enchants a weapon, but it has a message and options to allow the player to choose what to do. You probably want to do all that eventually. (I don't think I introduced an error, but I didn't test the code, so I can't be sure.)

Code: Select all

[event]
    name=moveto

    [filter]
        x=10, y=10
    [/filter]

    [object]
        name= _ "Ring of Speed"
        description= _ "This ring will increase your maximum speed by 1."
        [filter]
            x=10, y=10
        [/filter]

        [effect]
            apply_to=movement
            increase=1
        [/effect]
    [/object]
[/event]

Code: Select all

[event]
    name=moveto
    first_time_only=no

    [filter]
        x=10, y=10
        side=1
    [/filter]

    [message]
        speaker=unit
        message= _ "Should I use this enchantment?"
        [option]
            label= _ "Yes, I’ll take it."

            [command]
                [object]
                    # An object with an ID can only be taken once:
                    id=enchantment
                    [filter]
                        x=10, y=10
                        side=1
                    [/filter]

                    [effect]
                        apply_to=attack
                        range=melee
                        [set_specials]
                            {WEAPON_SPECIAL_MAGICAL}
                        [/set_specials]
                    [/effect]
                [/object]
                
                # This part removes the IMAGE from the map:
                [remove_item]  
                    x=10, y=10
                [/remove_item]
            [/command]
        [/option]

        [option]
            label= _ "No, I think someone else should use it."
            # Without this, the player couldn't undo if they chose "no":
            [command]
                [allow_undo]
                [/allow_undo]
            [/command]
        [/option]
    [/message]
[/event]
EDIT: Welcome to the forum!
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide

Post Reply