An item that increase xp

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
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

An item that increase xp

Post by Dorimen »

Hello,
I'm working on a scenario where I want to put an item, that can give some experience points to the unit who take it.
But there is a problem... :hmm: I saw in the wiki, that I can only modify the unit max experience not add xp.
There is a way to create this type of function??? :geek:

...sorry for the bad english...
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Flameslash
Posts: 633
Joined: December 21st, 2008, 12:29 pm

Re: An item that increase xp

Post by Flameslash »

If it lets you edit the max experience, you could reduce it to simulate adding XP?
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: An item that increase xp

Post by Elvish_Hunter »

This piece of code taken from the test scenario should give you an idea about how to proceed:

Code: Select all

    [label]
        x,y=7,10
        text="Earn 100 XP!"
    [/label]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x=7
            y=10
        [/filter]
        {VARIABLE_OP unit.experience add 100}
        [unstore_unit]
            variable=unit
            text="100 XP"
            red,green,blue=200,200,50
        [/unstore_unit]
    [/event]
Since unit is automatically stored, there is no need in this case to use [store_unit]. If you want to do this for multiple units, you'll have also to iterate the variable using {FOREACH} and {NEXT}. A similar effect can be obtained by using [modify_unit] and [floating_text].
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: An item that increase xp

Post by Dorimen »

thanks Elvish_Hunter! :D
And if I want that the experience will add only to one unit I need to write "first_time_only=yes"?
But if I place two option, to choose if you want to take it or no, I need to write "first_time_only=no", right?
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: An item that increase xp

Post by Elvish_Hunter »

Dorimen wrote:thanks Elvish_Hunter!
:wink:
Dorimen wrote:And if I want that the experience will add only to one unit I need to write "first_time_only=yes"?
Just delete first_time_only=no. The default behaviour is to fire events just once.
Dorimen wrote:But if I place two option, to choose if you want to take it or no, I need to write "first_time_only=no", right?
Yes. You'll also need a variable to check if the item was already taken, and such a check can be performed either with an [if] [then] [else] structure, or with [filter_condition] (especially if the [else] tag is supposed to contain only [allow_undo]).
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: An item that increase xp

Post by Dorimen »

Ok, now I've created the macro, to recall it, but it doesn't work...
I have modified a bit the structure to recall on the macro the x y and value, but when I try to start the campaign it says that macro/file "ITEM" is missing..
This is the macro...

Code: Select all

#define ITEM_X_Y_EARN_VALUE_XP
    [label]
        x,y={X},{Y}
        text="Earn {VALUE} XP!"
    [/label]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x={X}
            y={Y}
        [/filter]
        {VARIABLE_OP unit.experience add {VALUE}}
        [unstore_unit]
            variable=unit
            text="{VALUE} XP"
            red,green,blue=232,232,103
        [/unstore_unit]
    [/event]
#enddef
I tried to use this on the scenario file to recall it

Code: Select all

        {ITEM 12 6 EARN 100 XP}
Do I need to use a tag? If yes, which??
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: An item that increase xp

Post by Dugi »

You should write #define ITEM X Y EARN VALUE XP instead of #define ITEM_X_Y_EARN_VALUE_XP. What you wrote, that is only a long macro name with no arguments, spaces separate the macro name from its arguments. Btw, the argument EARN is not used in the macro definition.
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: An item that increase xp

Post by Dorimen »

Thanks dugi! Now it works, but now there is another problem...
A unit level up only one time.
Example:
A unit can level up with 20 xp, after taken the item he level up one time and have 80/25 xp...
How can I solve this problem?
I tell you that I use a custom AMLA advancement that normally works
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: An item that increase xp

Post by Dugi »

If you modify a unit's exp or hp to weird values, they will remain like that until they enter combat. If you set a unit's hp to -20, it will not cause it to die. If you set an unit's exp to 999, it will not level-up. When you enter a combat, these things will be calculated.

In your case, it is quite a problem, because there is no real way to make it level-up, especially if you have a specific advancement.
Well, there might be a way, but I don't know about any.

I suggest you to make a workaround.

Instead of

Code: Select all

{VARIABLE_OP unit.experience add {VALUE}
use this:

Code: Select all

[unit]
       type=harmer_dummy_60
       id=exp_harmer
        x,y={X},{Y}
        side=1
[unit]
[harm_unit]
[filter]
        x,y={X},{Y}
[/filter]
[filter_second]
       id=exp_harmer
[/filter_second]
amount=0
experience=yes
animate=no
fire_event=no
[/harm_unit]
[kill]
  id=exp_harmer
  fire_event=no
  animate=no
[/kill]
and define a few harmer_dummies with levels equal to the amounts of exp you want to give.

Btw, the map you have on DeviantArt has an error, the mountains at the north are named 'Mistery Mountains' instead of 'Mystery Mountains', and I don't think it was intended to be related to a mist of some kind.
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: An item that increase xp

Post by Elvish_Hunter »

Dorimen wrote:A unit can level up with 20 xp, after taken the item he level up one time and have 80/25 xp...How can I solve this problem?
dugi wrote:If you modify a unit's exp or hp to weird values, they will remain like that until they enter combat. If you set a unit's hp to -20, it will not cause it to die. If you set an unit's exp to 999, it will not level-up. When you enter a combat, these things will be calculated.In your case, it is quite a problem, because there is no real way to make it level-up, especially if you have a specific advancement.Well, there might be a way, but I don't know about any.I suggest you to make a workaround.
No need for a workaround. That clashes with what's written on the wiki at http://wiki.wesnoth.org/DirectActionsWM ... re_unit.5D :
[unstore_unit]
...
advance: (default=true) if true the unit is advanced if it has enough XP. When modifying XP make sure to do it from inside a synchronized event or it may lead to OOS errors especially when several advancement paths exist. Note that advance and post advance events are called, so infinite loops can happen.
fire_event: (boolean yes|no, default no) Whether any advance/post advance events shall be fired if an advancement takes place, no effect otherwise.
This means that modifying the [unstore_unit] tag like this should work, and if it doesn't then it's a bug and should be reported:

Code: Select all

        [unstore_unit]
            variable=unit
            text="{VALUE} XP"
            red,green,blue=232,232,103
            advance=yes
            fire_event=yes
        [/unstore_unit]
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: An item that increase xp

Post by Dorimen »

I fear it doesn't work :doh:
If it's a bug, I've tried to report it to gna.org, but I don't know how to do it... I don't see a button to add a report :hmm:
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: An item that increase xp

Post by Dugi »

Well, maybe I was not right with my previous statement, all I remember is that this kind of thing could cause some maximum stat violations. If he encountered a bug, he apparently needs a workaround. But a workaround storing and unstoring him twice after unstoring him the first time should be an easier way.
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: An item that increase xp

Post by Dorimen »

dugi wrote:Btw, the map you have on DeviantArt has an error, the mountains at the north are named 'Mistery Mountains' instead of 'Mystery Mountains', and I don't think it was intended to be related to a mist of some kind.
Oops :mrgreen:
dugi wrote:Well, maybe I was not right with my previous statement, all I remember is that this kind of thing could cause some maximum stat violations. If he encountered a bug, he apparently needs a workaround. But a workaround storing and unstoring him twice after unstoring him the first time should be an easier way.
Something like that?

Code: Select all

#define ITEM X Y VALUE XP
    [label]
        x,y={X},{Y}
        text="Earn {VALUE} XP!"
    [/label]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            x={X}
            y={Y}
        [/filter]
        {VARIABLE_OP unit.experience add {VALUE}}
        [unstore_unit]
            variable=unit
            text="{VALUE} XP"
            red,green,blue=232,232,103
            advance=yes
            fire_event=yes
        [/unstore_unit]
        [store_unit]
            variable=unit
            advances=yes
            fire_event=yes
        [/store_unit]
        [unstore_unit]
            variable=unit
            advances=yes
            fire_event=yes
        [/unstore_unit]
        [store_unit]
            variable=unit
            advances=yes
            fire_event=yes
        [/store_unit]
        [unstore_unit]
            variable=unit
            advances=yes
            fire_event=yes
        [/unstore_unit]
    [/event]
#enddef
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: An item that increase xp

Post by Dugi »

Yeah, try to give it a try.
User avatar
Dorimen
Posts: 55
Joined: March 23rd, 2011, 8:26 am
Location: Italy

Re: An item that increase xp

Post by Dorimen »

dugi wrote:Yeah, try to give it a try.
Well, it says when I place the unit on the tile:

Code: Select all

<invalid WML found> [store_unit] missing required [filter] tag
and the xp works as before :|
DeviantArt Profile
My project: Stickmen Era
Coming soon project: The Chaos Lord- a campaign with the Stickmen Era
--The measure of a man is what he does with power--
Post Reply