An item that increase xp

The place to post your WML questions and answers.

Moderators: Developers, 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.

An item that increase xp

Postby Dorimen » March 4th, 2012, 6:47 pm

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

Re: An item that increase xp

Postby Flameslash » March 4th, 2012, 7:19 pm

If it lets you edit the max experience, you could reduce it to simulate adding XP?
User avatar
Flameslash
 
Posts: 520
Joined: December 21st, 2008, 12:29 pm

Re: An item that increase xp

Postby Elvish_Hunter » March 4th, 2012, 7:24 pm

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].
For bug report purpose: I'm playing Wesnoth 1.11.11 on Windows 7 and trunk on Linux Xubuntu 13.04.
Current maintainer of The Sojournings of Grog , Children of Dragons , A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
User avatar
Elvish_Hunter
Developer
 
Posts: 1127
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: An item that increase xp

Postby Dorimen » March 5th, 2012, 10:18 am

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

Re: An item that increase xp

Postby Elvish_Hunter » March 5th, 2012, 10:57 am

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]).
For bug report purpose: I'm playing Wesnoth 1.11.11 on Windows 7 and trunk on Linux Xubuntu 13.04.
Current maintainer of The Sojournings of Grog , Children of Dragons , A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
User avatar
Elvish_Hunter
Developer
 
Posts: 1127
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: An item that increase xp

Postby Dorimen » March 5th, 2012, 12:40 pm

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

Re: An item that increase xp

Postby Dugi » March 5th, 2012, 12:55 pm

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.
Legend of the Invincibles - single player campaign, trying to be an expansion to regular Wesnoth, where units can advance indefinitely, gear becomes an important factor and tons of new abilities increase the game's variety.
User avatar
Dugi
 
Posts: 3156
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains

Re: An item that increase xp

Postby Dorimen » March 5th, 2012, 1:15 pm

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

Re: An item that increase xp

Postby Dugi » March 5th, 2012, 2:10 pm

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.
Legend of the Invincibles - single player campaign, trying to be an expansion to regular Wesnoth, where units can advance indefinitely, gear becomes an important factor and tons of new abilities increase the game's variety.
User avatar
Dugi
 
Posts: 3156
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains

Re: An item that increase xp

Postby Elvish_Hunter » March 5th, 2012, 2:22 pm

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]
For bug report purpose: I'm playing Wesnoth 1.11.11 on Windows 7 and trunk on Linux Xubuntu 13.04.
Current maintainer of The Sojournings of Grog , Children of Dragons , A Rough Life and Wesnoth Lua Pack
Co-author of The White Troll
User avatar
Elvish_Hunter
Developer
 
Posts: 1127
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: An item that increase xp

Postby Dorimen » March 5th, 2012, 2:47 pm

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

Re: An item that increase xp

Postby Dugi » March 5th, 2012, 2:49 pm

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.
Legend of the Invincibles - single player campaign, trying to be an expansion to regular Wesnoth, where units can advance indefinitely, gear becomes an important factor and tons of new abilities increase the game's variety.
User avatar
Dugi
 
Posts: 3156
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains

Re: An item that increase xp

Postby Dorimen » March 5th, 2012, 3:01 pm

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

Re: An item that increase xp

Postby Dugi » March 5th, 2012, 3:07 pm

Yeah, try to give it a try.
Legend of the Invincibles - single player campaign, trying to be an expansion to regular Wesnoth, where units can advance indefinitely, gear becomes an important factor and tons of new abilities increase the game's variety.
User avatar
Dugi
 
Posts: 3156
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains

Re: An item that increase xp

Postby Dorimen » March 5th, 2012, 3:15 pm

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

Next

Return to WML Workshop

Who is online

Users browsing this forum: No registered users and 1 guest