ghype's Coding Problems - Modify Xp Reward

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.
User avatar
ghype
Posts: 401
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

ghype's Coding Problems - Modify Xp Reward

Post by ghype » October 17th, 2018, 1:28 pm

This thread will contain smaller questions on how to code certain things since I am still at the beginning. Technically I have someone to ask about such things but I don't want to bother him always and figured the best way to handle this is to make these public.





modify xp rewards:


Solved: hide life & exp bar and more:
Solved: REMOVE_IMAGE has 2 arguments, but reads 3:
Last edited by ghype on October 19th, 2018, 9:19 am, edited 9 times in total.
post sprites & stuff every day: ghype's Daily Art
destroying enemy castle here: Orcish Castle - Destroyed - work in progress

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

Re: ghype's Coding Problems

Post by James_The_Invisible » October 17th, 2018, 1:44 pm

Well, arguments in macro calls are separated by space so you used 3. And actually macro REMOVE_IMAGE takes just X and Y as arguments:

Code: Select all

#define REMOVE_IMAGE X Y
    # Removes a previously set image from a tile.
    #
    # Example:
    #! {REMOVE_IMAGE 14 5}
    [remove_item]
        x,y={X},{Y}
    [/remove_item]
#enddef
.
To your other question: you do not have to provide an id for event unless you want to avoid adding the same event (I mean content, not type) multiple times or remove the event at some point.

User avatar
ghype
Posts: 401
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Coding Problems

Post by ghype » October 17th, 2018, 10:00 pm

yeeah. thanks a lot. I checked the tutorial again and it really has only 2 arguments. guess I was not paying as much attention as i should have.

but this works now.
post sprites & stuff every day: ghype's Daily Art
destroying enemy castle here: Orcish Castle - Destroyed - work in progress

User avatar
ghype
Posts: 401
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Coding Problems - Modify Xp Reward / Hide Exp Bar

Post by ghype » October 18th, 2018, 11:02 am

This is the picture for my question regarding: hiding life & exp bar and more

As you can see it would look so much better without those visual aspects
Attachments
Screen Shot 2018-10-18 at 11.13.57.png
Screen Shot 2018-10-18 at 11.13.57.png (34.95 KiB) Viewed 511 times
post sprites & stuff every day: ghype's Daily Art
destroying enemy castle here: Orcish Castle - Destroyed - work in progress

Shiki
Developer
Posts: 231
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: ghype's Coding Problems - Modify Xp Reward / Hide Exp Bar

Post by Shiki » October 18th, 2018, 2:16 pm

I would recommend to use the impassable overlay, ^Xo, instead of an invisible unit to block the terrain. ( -> full list )
Also note that when you want to remove it later with [terrain], it's possible to only remove the overlay. (see NR S2 for an example)

For blocking with an unit:
You can set zoc=none for the [unit]. The health bar probably remains, you can petrify the unit to get rid of that.
The stats and status in the sidebar will still be shown though.
Maintainer of Era of Myths.
Introduction to WML filtering and WML variables.

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

Re: ghype's Coding Problems - Modify Xp Reward / Hide Exp Bar

Post by Ravana » October 18th, 2018, 3:05 pm

There are some keys about offset, check unit type documentation.

User avatar
ghype
Posts: 401
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Coding Problems - Modify Xp Reward / Hide Exp Bar

Post by ghype » October 18th, 2018, 6:31 pm

Shiki wrote:
October 18th, 2018, 2:16 pm
I would recommend to use the impassable overlay
this is no invisible unit, I actually coded a unit as gate in order to make use of the replace mechanism on death taken from the AE_rat_pack ability. I wouldn't know how to make use of the replacing mechanism with impassable overlay without an invisible unit.
Ravana wrote:
October 18th, 2018, 3:05 pm
There are some keys about offset, check unit type documentation.
I did not found any reference to "offset" in unit type documentation or anywhere else. However, I stumbled upon something that could potentially fix both issues - kill_experience and hp_bar_scaling. Both of which should be put in the game.cfg. I never worked with a game.cfg before. so I dont know what the strucutre should look like for that file regarding a campaign or scneario.

this is not the right way, because it ain't changed anything. But it also did not gave me an error. So how do I work with these keys exactly? I want these attributes to affect only units with race=abob_special_objects.

Code: Select all

#textdomain wesnoth-abob

[game_config]

    [filter]
        [unit]
            race=abob_special_objects
        [/unit]
        kill_experience=0   
        hp_bar_scaling=0.01
    [/filter]

[/game_config]
post sprites & stuff every day: ghype's Daily Art
destroying enemy castle here: Orcish Castle - Destroyed - work in progress

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

Re: ghype's Coding Problems - Modify Xp Reward / Hide Exp Bar

Post by Ravana » October 18th, 2018, 7:28 pm

Yes, hp_bar_scaling is one of those I meant. You put it under unit_type I believe.

User avatar
ghype
Posts: 401
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Coding Problems - Modify Xp Reward / Hide Exp Bar

Post by ghype » October 19th, 2018, 9:18 am

Hide Exp Bar:
I read that you can use hp_bar_scaling directly in the unit.cfg. I worked with it but it will always reserve 2px for the border and 1px for the health.
so you cannot make it disappear but it is as good as it gets. I will enlarge the .png image size so the hp bar moves out of the frame.

Modify Xp Reward:
tried to make sense on what is written in the documentation in order to make kill_experience work, but there is not enough info. I created a game.cfg as said.

"The game.cfg file begins by referring to other files in the data/ directory. It then sets the value of some [advanced_preference]s.
The main tag in game.cfg is [game_config] . The first 9 keys in [game_config] refer to game constants."


it references [advanced_preference] but I don't know how to implement any of these correctly ...

"This tag is a top level WML tag that defines an advanced preference. It only affects the appearance in the preference dialog (in the advanced section), the actual effect of the setting is part of the game engine and is not modifiable by WML."
post sprites & stuff every day: ghype's Daily Art
destroying enemy castle here: Orcish Castle - Destroyed - work in progress

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

Re: ghype's Coding Problems - Modify Xp Reward

Post by Ravana » October 19th, 2018, 9:32 am

You can change game_config only from Lua https://github.com/ProditorMagnus/Oroci ... ts.lua#L27 https://wiki.wesnoth.org/LuaWML/Misc#we ... ame_config

Its not documented, but you can add offset to bars, if it is large enough, it is out of screen https://github.com/wesnoth/wesnoth/comm ... 6e156cd3e0

Shiki
Developer
Posts: 231
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: ghype's Coding Problems - Modify Xp Reward

Post by Shiki » October 19th, 2018, 10:33 am

Not sure how the AE_rat_pack_ability works…

If you find an event suiting as trigger, it could be opened such as

Code: Select all

[event]
    name=moveto # or die if that comes closer to the AE_rat_pack
    [filter]
        x,y= e.g. the coordinates in front of the gate
        (it's a SUF, but a SLF can be used with [filter_location] inside the [filter])
    [/filter]
    [terrain]
        x,y=the gate's coordinates (or any other SLF)
        layer=overlay
        terrain=^
    [/terrain]
    # (mainline has a REMOVE_TERRAIN macro, however, it doesn't use layer=overlay… )
    
    # if you placed the gate image with [item] before, e.g. in prestart
    [remove_item]
        x,y=… (or any other SLF)
    [/remove_item]
[/event]
One can as well do things like opening all gates simultaneously that way.
An disadvantage I see in above event is that it's specific to each gate, maybe create a macro for it.

What's the condition you want to use for opening the gate?
Maintainer of Era of Myths.
Introduction to WML filtering and WML variables.

User avatar
ghype
Posts: 401
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Coding Problems - Modify Xp Reward

Post by ghype » October 19th, 2018, 10:50 am

Modify XP Reward:
as far as i understood the LuaWML is already implemented into wesnoth, so I dont have to download anything for that.
also it is now possible to open the [lua] tag inside of [scenario] or thus a [event] too. The documentation says to use the [game_congig] but you should me an alternative.

I don't think it this simple, but how could I make this work?

code:
Hide XP Bar:
i can make sense of your approach Shiki, it understandable to me.
however, I have a total of 23 gates which each of them break down into 4 more broken versions. For example, a unit in order to break the gate he has to attack/kill the gate 4 times until it is broken down completely. thats why I thought the using a unit.cfg for my gate combined with the mechanism for breaking down works pretty well. but that is the reason why I also need the killing_reward to work, since you are killing this game 4x23 times, which gives too much xp.

this is the code for the mechanism, which is not all too complicated.
code:
post sprites & stuff every day: ghype's Daily Art
destroying enemy castle here: Orcish Castle - Destroyed - work in progress

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

Re: ghype's Coding Problems - Modify Xp Reward

Post by Ravana » October 19th, 2018, 11:33 am

StandardUnitFilter does not recognize [unit], so even when you [fire_event] lua.killing.experience, filter would not let it run.

Though game_config values are global, affecting everything. Normal way for your use is removing xp after attack. https://github.com/ProditorMagnus/Agele ... er.cfg#L17

That is how you would usually run Lua code.

Code: Select all

[event]
name = preload
[lua]
           code = << wesnoth.game_config.killing_experience = 0 >>
[/lua]
[/event]

enclave
Posts: 885
Joined: December 15th, 2007, 8:52 am

Re: ghype's Coding Problems - Modify Xp Reward

Post by enclave » October 19th, 2018, 12:34 pm

it might not be helpful but removing hp and xp bar was discussed before in forums, and i think somebody removed them succesfully. Try to use search within/inside this forum, it may have a good chance u find something more useful than links to documentation.. i think it was about experience bar, but if you can remove experience bar, u probably can remove hp bar the same way. I haven't personally removed them (as far as I remember) so I don't have a code ready to paste it here..

User avatar
ghype
Posts: 401
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Coding Problems - Modify Xp Reward

Post by ghype » October 19th, 2018, 2:28 pm

i tried that lua line as you posted it, but I assume there is more to it than those couple of lines. upon loading the game I received this error.
error:
the approach with the soulcatcher ability seems to be exactly what I needed. It also seems to work at first. I kill a unit lv4 gate, it gives me 32xp and then when I end turn it reduces it back to 0xp. There are two problems with this.
(1) it only happens once. when I kill another unit (e.g. the lv3 gate) this ability stops working. no more xp reducing even if first_time_only=no is checked everywhere
(2) currently it happens only when you end turn. It would be much more immersive if it happens right after the kill before the battle ends. The events however are are clearly defined for attack_end and die.

this is the modified code, where I basially only changed the ability names and Id's ...
code:
enclave wrote:
October 19th, 2018, 12:34 pm
removing hp and xp bar was discussed before in forums
if you refer this post, the yes it was discussed and you eventually found a solution on hiding the xp bar. but those approaches do not indicate that it is possible with the hp as well.
post sprites & stuff every day: ghype's Daily Art
destroying enemy castle here: Orcish Castle - Destroyed - work in progress

Post Reply