Unit advance and stats changing - [SOLVED].

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
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Unit advance and stats changing - [SOLVED].

Post by ChaosRider »

How can I stop unit advancing from changing back (set to normal) unit stats like resistances, hp, or weapon dmg/strikes when i dont use object tags and i cant use:

Code: Select all

duration=forever
Im changing these stats inside stored unit which is later unstored as a copy from first one. Everything is fine besides that strikes/dmgs/resistances goes back as in original unit.
Last edited by ChaosRider on January 31st, 2015, 7:26 pm, edited 1 time in total.
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Unit advance and stats changing.

Post by zookeeper »

If you really can't use an [object], then I'm afraid you just have to re-apply the stats changes after advancement.
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Unit advance and stats changing.

Post by ChaosRider »

I would like to use object tags but somehow used from unit stats values aint working inside code thx what while cant be stopped :/... quick little description before you see the code, main idea is that to decrease weapon strikes number and damages if this two things multiply together are higher than 150, if they are I set new max which is 75% of strikes*dmg value (later i check is this 75% is higher than 150, if not then max is again 150). When its lower i dont change weapon value.

Spoiler:
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Unit advance and stats changing.

Post by Dugi »

The changes you make via variables and apply via unstore_unit are called soft changes. They are removed when a unit changes type (not necessarily when it advances) or an object expires. I am using these changes a lot and over time, I have figured out a reliable way to work with them.

How can it be done:
1. Make up some custom [effect]s that don't normally work. For example if we wanted to make sure that a unit will not deal more than 20 damage, it would be something like:

Code: Select all

[effect]
  apply_to=limit damage
  maximum=20
[/effect]
2. The above obviously does nothing, but it stays inside the unit where it should, regardless of the number of advancements. Add it via an [object] anyway.
3. Now, make an event you fire on the unit when it advances. It reads through all [object]s the unit has in modifications, checks its [effect]s and if it finds your new effect, it will perform the change. For example (this will make that limit damage thing working):

Code: Select all

[event]
  name=post advance
  first_time_only=no
  id=fix limit damage
  {VARIABLE damage_limit 9000}
  {FOREACH unit.modification.object i}
    {FOREACH unit.modification.object[$i].effect j}
      [if]
        [variable]
          name=unit.modification.object[$i].effect[$j].apply_to
          equals=limit damage
        [/variable]
        [then]
          {VARIABLE damage_limit $unit.modification.object[$i].effect[$j].maximum}
        [/then]
      [/if]
    {NEXT j}
  {NEXT i}
  {FOREACH unit.attack i}
    [if]
      [variable]
        name=unit.attack[$i].damage
        greater_than=$damage_limit
      [/variable]
      [then]
        {VARIABLE unit.attack[$i].damage $damage_limit}
      [/then]
    [/if]
  {NEXT i}
  {CLEAR_VARIABLE damage_limit}
  [unstore_unit]
    variable=unit
    find_vacant=no
  [/unstore_unit]
[/event]
Note that I haven't tested this, it was just meant to give you an idea what it is.
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Unit advance and stats changing.

Post by ChaosRider »

Setting maximum limit damage for unit and using it by whole campaign wont be good option (I want to use it only when clone is creating first time, after whole that situation he should be allowed to increase own weapon dmg), when it can change in each turn. I changed a bit code, but still effects in object tags dont change unit weapon damages/strikes number thx what while loop cant end.
Spoiler:
Spoiler:
Below are parts of define "CHECK_WEAPON_STATS VALUE" which dont change unit weapon stats when it should works.
Spoiler:
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Unit advance and stats changing.

Post by Dugi »

Code: Select all

                                                {CHECK_WEAPON_STATS 0}
                                                {CHECK_WEAPON_STATS 1}
                                                {CHECK_WEAPON_STATS 2}
                                                {CHECK_WEAPON_STATS 3}
                                                {CHECK_WEAPON_STATS 4}
                                                {CHECK_WEAPON_STATS 5}
                                                {CHECK_WEAPON_STATS 6}
                                                {CHECK_WEAPON_STATS 7}
                                                {CHECK_WEAPON_STATS 8}
                                                {CHECK_WEAPON_STATS 9}
                                                {CHECK_WEAPON_STATS 10}
                                                {CHECK_WEAPON_STATS 11}
                                                {CHECK_WEAPON_STATS 12}
                                                {CHECK_WEAPON_STATS 13}
                                                {CHECK_WEAPON_STATS 14}
Why don't you just write:

Code: Select all

{FOREACH units_to_copy.attack i}
  {CHECK_WEAPON_STATS $i}
{NEXT i}
The code is shorter when seen and SIGNIFICANTLY shorter when loaded with macros replaced. Faster loading, less RAM usage, no drawbacks at all!
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Unit advance and stats changing.

Post by ChaosRider »

Form of code was changed a lot, so was a time when I had it in one FOREACH as you written it higher, but its still same, effect tags don't change unit weapon stats - which is important to exit from while loop. Im using here twice storing to first just create copy, and later I store only copied unit (if I do it in one store then all changes from effect tags will be added to original which is bad) to change it stats.

Other idea which i have for now is to let 2 units (original and copy) have a same id for a moment, thx what later I will be able to find this unit (copied one) with this id but with diffrent x,y than its set for a bonus hex (cause i cant say where its will be spawned).
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Unit advance and stats changing.

Post by Dugi »

:annoyed: My method IS working, I am using it like everywhere in my campaign and almost none of its items would work without it. If you can't get it to work, you are doing it wrong.

First, familiarise yourself with the code I proposed. Make a unit, apply that object on it and fire the post advance event on it. See that it has an effect. Have it advance and you'll see that the effect persists. Then, start experimenting with it until you edit it into the form you desire. You absolutely don't need to copy the unit.
effect tags don't change unit weapon stats
That isn't supposed to do that. The effect I proposed does nothing, it is just a mark for the post advance event to know what it should do. The mark remains regardless of the number of level-ups and the event will recreate the effect every time.
Other idea which i have for now is to let 2 units (original and copy) have a same id for a moment
This will not work. Two units with the same id can't live together, one of them will suddenly disappear shortly afterwards.
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Unit advance and stats changing.

Post by ChaosRider »

Dugi wrote::annoyed: My method IS working, I am using it like everywhere in my campaign and almost none of its items would work without it. If you can't get it to work, you are doing it wrong.
That "bonus" which is coping unit i dont want to make it threat as an item, also i dont want allow copied one to drop his decreased stats of weapons which he was using while coping (after copy him he can get new weapon later, who knows what will happen) and go back to normal one as in original unit.

Dugi wrote:First, familiarise yourself with the code I proposed. Make a unit, apply that object on it and fire the post advance event on it. See that it has an effect. Have it advance and you'll see that the effect persists. Then, start experimenting with it until you edit it into the form you desire. You absolutely don't need to copy the unit.
Your setting limits for weapon damages which are used by whole game can disturb other bonuses which can increase weapon stats. Its not a good path as for me, also my code is working when im using as you said "soft changes" when its right time:
Spoiler:
as this line higher posted & blocked by hash this below should works same (but its not thx what my code isnt working, cant leave while loop)
Spoiler:
I need to use it in effect tags to solve problem with unit advancing, so I dont know why something what i used already in other codes isnt working here. Diffrence is that Im changing copy of the unit, which is already spawned on map (earlier version of this code has been split for 2 smaller parts), and not the original unit as in other codes which i made already.

I have already require for me variables and values so I need to know how it should be properly written in effect tags.

Below are parts of code:
Code to copy unit (works)
Spoiler:
Code to find & change copied units (not works, reason is higher posted)
Spoiler:
Spoiler:
In this code you have also set messages to appear which helps to know whats going on and in which place.

I can use it with "soft changes" but copied units which don't use yet own last form will get back stats (hp,mp,xp max, weapons stats) as in original one (which differs from my idea to make copies weaker than original unit).

Edit 2: Also if some admins is watching it I have to say that at Wesnoth Wiki is no info about how to carry these "soft changes" made by wml between unit forms while its advancing to higher lvl.
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Unit advance and stats changing.

Post by Dugi »

That "bonus" which is coping unit i dont want to make it threat as an item, also i dont want allow copied one to drop his decreased stats of weapons which he was using while coping (after copy him he can get new weapon later, who knows what will happen) and go back to normal one as in original unit.
So you can just set it as a variable. If you have problems with using [object], you can just set a variable into it, for example unit.variables.damage_limit to 20 and you have it working too. I just found the objects more convenient. The point is that you have to mark somehow that the change was done and that it has to be done again when it advances. If the order of changes troubles you, you have no other options than to create an object specially tailored for that change and apply it.
Your setting limits for weapon damages which are used by whole game can disturb other bonuses which can increase weapon stats.
Have you really read what I wrote? I told you that it's just an example. Get it working first to understand properly how is it supposed to work, then change it so that it would suit you.
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Unit advance and stats changing.

Post by ChaosRider »

Thx that I created this topic I tried other options with post_advance (thx Dugi idea), but this wasnt enought since units default weapons (which they have from the beginning of own existence) may change weapon name while advancing (as 1 lvl ghost which touch is changing in to baneblade at 2 lvl).
That changing of their names may cause some bug when copied unit which sold default weapon after advance get it back with diffrent name and also without any minus bonuses (because it hadn't it before advance).
Other situation in which it may fail is that when weapon after advance change own name & place in weapons list.
Another one is when while coping hadn't weapon which it get after advance - it works only for weapons which unit had while coping.

Other information which I deduced during of writing this code:
Spoiler:
My code is immune for changing weapon place at weapons list (when its not changing also name!) in unit.
I don't know is it cause oos, its not tested in mp game.
If no one will do that funny bug about which I wrote higher then weapon which is changing name after advance also will get minus bonuses which copied unit had from being copied.

end turn 1 event - when we copy unit
Spoiler:
end turn 2nd event - when its copied already and we change weapons
Spoiler:
advance event - we check what weapons we have (its done like this to make it works also for weapons which changed own name or place in weapons list in unit after advance) at unit before advance
Spoiler:
post advance event
Spoiler:
So I can say the problem is solved... in crazy way, but it is done.
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
Post Reply