Help for New Abilities and Weapon Specials

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
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Help for New Abilities and Weapon Specials

Post by Barbaros »

Hello everyone, I am a beginner in wml, with an average understanding at most, already forcing the bar kkkkkk.
I am only interested in playing campaign mode. I would like you to help me a little with some codes.
In some things, I will probably only need a light, and in others I am totally lost kkkkkkk, more than failure of life. Patience should be the word for me...
Thanks for your attention.

  • Fighter Spirit - Weapon Special that does more damage to higher-level targets, while lower-level targets take more insignificant damage.
    Last Resort - Weapon Special that allows the unit to battle twice if the HP is 25% or less.
    Support Attack - Special weapon that makes a single hit attack against a target that an ally strikes, as long as it is adjacent, gains 50% of the experience if it kills the target, and the experience of the main unit proceeds normal if the target dies.
    Combat Expertise - Weapon Special that gains an extra attack hit when the unit dodges an opponent's hit.
  • Tactical Siege - Ability that allows the unit to move 3 more spaces, if it does so after attacking. Not like the hit and run, it is only activated when the unit battles without moving, in this case not spending any of the movement when attacking, but if you walk before, it is inactive.
    Strengthening - Ability that significantly increases the unit's resistances when HP is 50% or lower.
    Evasive Maneuvers - Ability that significantly increases the unit's terrain defenses when HP is 50% or lower.
    Battle Bond - Ability that increases the unit's attack damage by percentage with each adjacent enemy.
  • Some way to fix the Cleave Weapon Special, which, since I'm on Wesnoth 1.14, isn't working.
    Some way for the unit to have an attack that is only available with low HP, another condition would be on specific terrain, or only during the day or night. I broke my head a lot and couldn't do it.
    Some type of Weapon Special that has a chance of critical damage, which would be double the damage, with a 6% chance, which increases 2% for every 25% the unit has less HP.
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
gfgtdf
General Code Maintainer
Posts: 1343
Joined: February 10th, 2013, 2:25 pm

Re: Help for New Abilities and Weapon Specials

Post by gfgtdf »

Barbaros wrote: July 18th, 2020, 3:05 pm Fighter Spirit - Weapon Special that does more damage to higher-level targets, while lower-level targets take more insignificant damage.
Last Resort - Weapon Special that allows the unit to battle twice if the HP is 25% or less.


Strengthening - Ability that significantly increases the unit's resistances when HP is 50% or lower.
Evasive Maneuvers - Ability that significantly increases the unit's terrain defenses when HP is 50% or lower.
Battle Bond - Ability that increases the unit's attack damage by percentage with each adjacent enemy.


Some way for the unit to have an attack that is only available with low HP, another condition would be on specific terrain, or only during the day or night. I broke my head a lot and couldn't do it.
This is rather easy to implement with the usual ability/wesponspecial tags.
Barbaros wrote: July 18th, 2020, 3:05 pm Support Attack - Special weapon that makes a single hit attack against a target that an ally strikes, as long as it is adjacent, gains 50% of the experience if it kills the target, and the experience of the main unit proceeds normal if the target dies.
Tactical Siege - Ability that allows the unit to move 3 more spaces, if it does so after attacking. Not like the hit and run, it is only activated when the unit battles without moving, in this case not spending any of the movement when attacking, but if you walk before, it is inactive.
These needs to be done via some custom events. harder to implement than the above.
Barbaros wrote: July 18th, 2020, 3:05 pm Some type of Weapon Special that has a chance of critical damage, which would be double the damage, with a 6% chance, which increases 2% for every 25% the unit has less HP.
Afaik This can be implemented without custom [event]s but its a bit tricky, in particular if you want it to show up in the sidebar correctly.
Barbaros wrote: July 18th, 2020, 3:05 pm Combat Expertise - Weapon Special that gains an extra attack hit when the unit dodges an opponent's hit.
I think this is really hard to implement, i wouldn't try this one if you are a newcomer.

Barbaros wrote: July 18th, 2020, 3:05 pm Some way to fix the Cleave Weapon Special, which, since I'm on Wesnoth 1.14, isn't working.
No idea what you mean here.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
beetlenaut
Developer
Posts: 2493
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Help for New Abilities and Weapon Specials

Post by beetlenaut »

Tactical Siege might be the easiest to start with. It does need a custom event, but it almost exists already in mainline. Scouts in UtBS have an ability called Disengage which gives them all their movement points back if they attack without moving. You would need the three DISENGAGE macros in abilities.cfg in the campaign's utils folder. First, you should copy them over to your own campaign and see if you can get the ability working. (Look in scout.cfg and _main.cfg if you need more of a hint.) Next, see if you can figure out how it works and how to change it from full MP to just three spaces.

Other than that, we recommend that you give one of these a try, and then ask a specific question if you need more help. That will get you more useful responses. If you were hoping we would write some of the code for you, we probably won't because you wouldn't learn anything that way!
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

I usually implement these things in the base game, so I can use it in any campaign.
And I didn't expect them to write all the code. Stop aggression kkkkk.
About "Cleave Weapon Special" , I already solved it.

So, I already work a little with the most common code, but it is very difficult.

Let's do it by steps.

Fighter Spirit: I need a type of "Filter" or some "Formula" to do more damage to targets with a higher Level than the unit with the Weapon Special, and Reduced against the same Level, or lower, so that it is not feasible to use the attack in question. however I am not sure how to do it.
I have a lot of difficulty with this part of the formulas, and what I understand by filters didn't work kkkkkk.
So, I don't know how to filter attack damage by target level, if you help me with that I develop the rest.
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

Tell me if Last Resort works like this:
I'm a little tired, just let me know if you have a problem with the code.
This frustrates me when it doesn't work, it's the tenth time I modified this code today, I stopped testing on the ninth kkkkkk.
Sorry for the code not being organized here on the forum, have a little patience to read.

Code: Select all

#define SECOND_ATTACK
    [set_variable]
        name=tmp_double_attack_unit_store.attacks_left
        add=1
    [/set_variable]

    [set_variables]
        name=tmp_double_attack_unit_store.variables
        mode=merge
        [value]
            double_attack_attacked=yes
            double_attack_turn=$turn_number
        [/value]
    [/set_variables]

    [unstore_unit]
        text= _ "double attack"
        {COLOR_HARM}
        variable=tmp_double_attack_unit_store
    [/unstore_unit]

#enddef

#define WEAPON_SPECIAL_LAST_RESORT
# wmlxgettext: [attack]
# wmlxgettext: [specials]

    [chance_to_hit]
    [dummy]
        id=double attack
        name= _ "Last Resort"
        description= _ "This unit can attack two enemies in one turn with a minimum of 50% accuracy, only if 25% or less of your HP or less remains, but cannot move from a hex, where the first enemy was attacked."
        name_inactive= _ "Last Resort"
        description_inactive="This unit can attack two enemies in one turnwith a minimum of 50% accuracy, only if 25% or less of your HP or less remains, but cannot move from a hex, where the first enemy was attacked."
    [/dummy]
        value=50
        cumulative=yes
    [/chance_to_hit]
[/specials]
[/attack]

[event]
    name=attack_end
    first_time_only=no
    [filter_self]
        formula="(($this_unit.max_hitpoints -1+1) / ($this_unit.hitpoints -1+1)) > 4"
    [/filter_self]
    [filter_attack]
        special=double attack
    [/filter_attack]

    [filter]
        type={TYPE}
    [/filter]

    [store_unit]
        [filter]
            id=$unit.id
        [/filter]
        variable=tmp_double_attack_unit_store
    [/store_unit]

    [if]
        [variable]
            name=tmp_double_attack_unit_store.variables.double_attack_attacked
            boolean_not_equals=yes
        [/variable]

        [then]
            {SECOND_ATTACK}
        [/then]

        [else]
            [if]
                [variable]
                    name=tmp_double_attack_unit_store.variables.double_attack_turn
                    not_equals=$turn_number
                [/variable]

                [then]
                    {SECOND_ATTACK}
                [/then]
            [/if]
        [/else]
    [/if]
[/event]

[event]
    name=side turn
    first_time_only=no

    [clear_variable]
        name=tmp_double_attack_unit_store
    [/clear_variable]
[/event]

[event]
    name=victory

    [clear_variable]
        name=tmp_double_attack_unit_store
    [/clear_variable]
[/event]
[+attack]
[+specials]
# wmlxgettext: [/specials]
# wmlxgettext: [/attack]
#enddef
Last edited by Pentarctagon on July 19th, 2020, 9:06 pm, edited 1 time in total.
Reason: Added [code]
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

I don't know how people do to post the codes well organized here...
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
User avatar
beetlenaut
Developer
Posts: 2493
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Help for New Abilities and Weapon Specials

Post by beetlenaut »

Barbaros wrote: July 19th, 2020, 8:03 pm Fighter Spirit: I am not sure how to do it.
I think you will have to give the unit two different weapon specials. One increases damage, the other decreases it. Then you can do something like this for finding the lower-level units:

Code: Select all

[filter_adjacent]
	level="$($this_unit - 1)"
	[or]
		level="$($this_unit - 2)"
	[/or]
	[or]
		level="$($this_unit - 3)"
	[/or]
[/filter_adjacent]
(I didn't try this code, but I think it would work.) This is probably not the only way to do it, but it's the way I thought of just now.
Barbaros wrote: July 19th, 2020, 8:31 pm just let me know if you have a problem with the code.
That's not how this is supposed to work. You tell us if there is a problem with the code. To check it, I would create a campaign and copy your code into it. (Studying someone else's code looking for logic errors is more difficult.) But if it does work correctly, I would be wasting my time because you could have checked it first much faster.
Barbaros wrote: July 19th, 2020, 8:31 pm Sorry for the code not being organized here on the forum
Use code tags. There is a button on the toolbar that looks like this: </>

I hope you don't think I'm being aggressive. I am happy to help, I just don't want to waste my time.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
gfgtdf
General Code Maintainer
Posts: 1343
Joined: February 10th, 2013, 2:25 pm

Re: Help for New Abilities and Weapon Specials

Post by gfgtdf »

beetlenaut wrote: July 19th, 2020, 9:21 pm
Barbaros wrote: July 19th, 2020, 8:03 pm Fighter Spirit: I am not sure how to do it.
I think you will have to give the unit two different weapon specials. One increases damage, the other decreases it. Then you can do something like this for finding the lower-level units:

Code: Select all

[filter_adjacent]
	level="$($this_unit - 1)"
	[or]
		level="$($this_unit - 2)"
	[/or]
	[or]
		level="$($this_unit - 3)"
	[/or]
[/filter_adjacent]
It quite likely that this_unit refers to the adajcent unit if you are inside a filter_adjacent
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

I solved this crap, or at least I think ...
Until it was not difficult, the problem is that difficult codes tire the mind, so I run out of ideas kkkkkk.
If I did something stupid that would definitely not work in the code, let me know.
I'm not asking anyone to test it, it's just that I still have very little knowledge; therefore, if writing is very wrong, you can be critical. Anything that helps me see.

Code: Select all

#define ABILITY_STRENGTHENING VALUE
    [resistance]
        id=Strengthening
        add={VALUE}
        max_value=60
        apply_to=blade,pierce,impact
        name= _ "Strengthening"
        description="This units receive a +{VALUE}% bonus to physical resistances (up to a maximum of 60%) and heal itself 10% of max hp per turn, when your remaining HP is 50% or less."
        affect_self=yes
        affect_allies=no
        cumulative=yes
          [filter_self]
              formula="(($this_unit.max_hitpoints -1+1) / ($this_unit.hitpoints -1+1)) > 2"
          [/filter_self]
    [/resistance]
[/abilities]
[event]
  id=regenerates_10%
  first_time_only=no
  name=side turn
  [store_unit]
    [filter]
      ability=regenerates 10%
      side=$side_number
          [filter_self]
              formula="(($this_unit.max_hitpoints -1+1) / ($this_unit.hitpoints -1+1)) > 2"
          [/filter_self]
    [/filter]
    variable=unit_healed
    kill=no
  [/store_unit]
  {FOREACH unit_healed i}
    [if]
      [variable]
        name=unit_healed[$i].status.poisoned
        equals=yes
      [/variable]
      [then]
        [heal_unit]
          [filter]
            id=$unit_healed[$i].id
          [/filter]
          animate=yes
          amount=0
          restore_statuses=yes
        [/heal_unit]
      [/then]
      [else]
        [heal_unit]
          [filter]
            id=$unit_healed[$i].id
          [/filter]
          animate=yes
          amount=$($unit_healed[$i].max_hitpoints/10)
         [/heal_unit]
      [/else]
    [/if]
  {NEXT i}
  {CLEAR_VARIABLE unit_healed}
[/event]
[+abilities]
#enddef
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

It's just that I think that you, being more experienced, can easily point out some silly error in my code. But maybe I have too high an expectation.
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
gfgtdf
General Code Maintainer
Posts: 1343
Joined: February 10th, 2013, 2:25 pm

Re: Help for New Abilities and Weapon Specials

Post by gfgtdf »

Barbaros wrote: July 19th, 2020, 10:12 pm

Code: Select all

          [filter_self]
              formula="(($this_unit.max_hitpoints -1+1) / ($this_unit.hitpoints -1+1)) > 2"
          [/filter_self]
If you use formula you don't need to use $this_unit, you can just write: formula="max_hitpoints / hitpoints > 2"
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

Wow that simple, thank you.
I loved this.
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

According to what I want, the increase in attack power has to stay at just 25%. Is the code correct like this, or using "Leadership" will the code want to increase the attack taking into account the unit level?
Should I use "Damage" or "Leadership"?

Code: Select all

#define ABILITY_MAVERICK
    [leadership]
        id=ROLloner
        value=25
        cumulative=yes
        name= _ "maverick"
        female_name= _ "female^loner"
        description= _ "This units attacks and resistances are increased by 25% when it is at least one hexe from any allied unit. The increase in resistances can reach up to 40%."
        affect_self=yes
        affect_allies=no
            [filter]
                [filter_adjacent]
			is_enemy=no
			count=0
		[/filter_adjacent]
            [/filter]
    [/leadership]
    [resistance]
        add=25
        max_value=40
        apply_to=blade,pierce,impact,cold,fire,arcane
        affect_self=yes
        affect_allies=no
        [filter_base_value]
            less_than=40
        [/filter_base_value]
    [/resistance]
#enddef
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
User avatar
Barbaros
Posts: 71
Joined: July 17th, 2020, 7:42 pm

Re: Help for New Abilities and Weapon Specials

Post by Barbaros »

So this is how I should apply the filter you mentioned gfgtdf?

Code: Select all

#define ABILITY_FIGHTER_SPIRIT
    [leadership]
        id=Fighter_1
        value=-15
        cumulative=yes
        name= _ "Fighter Spirit"
        female_name= _ "Fighter Spirit"
        description= _ "This attack increases its damage by 15% times the levels above that the target has in relation to this unit; or decrease your damage by 15% for each level above the attacker has."
        affect_self=yes
        affect_allies=no
	    [filter_adjacent]
		level="$($this_unit - 1)"
		[or]
		level="$($this_unit - 2)"
		[/or]
		[or]
		level="$($this_unit - 3)"
		[/or]
		[or]
		level="$($this_unit - 4)"
		[/or]
	    [/filter_adjacent]
    [/leadership]
    [leadership]
        id=Fighter_2
        value=15
        cumulative=yes
        affect_self=yes
        affect_allies=no
	    [filter_adjacent]
		level="$($this_unit + 1)"
		[or]
		level="$($this_unit + 2)"
		[/or]
		[or]
		level="$($this_unit + 3)"
		[/or]
		[or]
		level="$($this_unit + 4)"
		[/or]
	    [/filter_adjacent]
    [/leadership]
#enddef
If from 15 to 30 years old, you have not been successful in life, you are already doomed.
gfgtdf
General Code Maintainer
Posts: 1343
Joined: February 10th, 2013, 2:25 pm

Re: Help for New Abilities and Weapon Specials

Post by gfgtdf »

I think this should work to check whether there is an adjacent unit with a lower level adjacent. I didn ttest it though and im not an expert on wesnoth frmoula filte syntax so it might not work.

Code: Select all

formula = "def adjacent_occupied_locs(loc)
				filter(
					adjacent_locs(loc),
					'loc',
					unit_at(loc) != null()
				);
			size(filter(adjacent_occupied_locs(loc), 'loc', unit_at(loc).level > self.level)) > 0"
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Post Reply