How to consume attack?
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.
How to consume attack?
I'm making an ability to heal units, this "healer" must to be adjacent to the wound target, open right click and chose "Heal Unit" from the menu. Then it will display a little menu where you have to choose which healer will heal the target (this happen because a wound unit could have several healer adjacent). After click the healer the unit get heal and the choosen healer loose its attack for this turn. My problem is: How can I do the last part?
This is the healer function:
And this is the list of "healers" that are adjacent to the wounded unit:
Am I having third main problems here.
1) How to get the coordinates of the healer. $healers[{number}].x and $healers[{number}].y?
2) How to modify the unit in order to consume its attack? I found that heal can restore attacks, but it doesn't work with negative numbers...
3) How can I check if the healer unit has its attacks? I don't want the healer be able to heal even if he already use it attack.
This is the healer function:
Code: Select all
#define HEALER_WORK number
[heal_unit]
amount=$healers[{number}].abilities.dummyhealer.value
animate=yes
[/heal_unit]
#enddef
Code: Select all
[store_unit]
[filter]
side=$side_number
ability=healer
[filter_adjacent]
x,y=$x1,$y1
[/filter_adjacent]
[/filter]
variable=healers
[/store_unit]
1) How to get the coordinates of the healer. $healers[{number}].x and $healers[{number}].y?
2) How to modify the unit in order to consume its attack? I found that heal can restore attacks, but it doesn't work with negative numbers...
3) How can I check if the healer unit has its attacks? I don't want the healer be able to heal even if he already use it attack.
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: How to consume attack?
There is a unit variable called "attacks_left". You can check it or modify it.
http://wiki.wesnoth.org/SingleUnitWML
http://wiki.wesnoth.org/SingleUnitWML
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: How to consume attack?
Each unit has an attacks_left attribute, set it to 0:Enderlook wrote:After click the healer the unit get heal and the choosen healer loose its attack for this turn. My problem is: How can I do the last part?
Code: Select all
[modify_unit]
[filter]
# the healer
[/filter]
attacks_left=0
[/modify_unit]
[set_menu_item] has a [filter] tag. When applied, the menu item is only shown if there is a unit matching the filter where the cursor is. This filter could be to have a healer there, AND that he still has his attack (inside an [and] in the filter, unit.attacks_left must be greater than 0). Then 1) is solved: the healer is the unit with x,y=$x1,$y1.
Then you'd need to store the units adjacent to $x1,$y1 (with 1 radius), and the player selects which wounded unit to heal. When done, use the code above to set the healer's attacks to zero. (so that he won't pass the filter another time in this turn, and can't heal again until next turn).
Checking whether a unit can still attack or not is only possible when an enemy unit is standing next to it I guess... but if you stick with this solution, it's trivial: if the menu item is present, he can still attack, if not, then the unit already used its attack, or has already healed.
For development and testing, these values can be checked manually in the inspection window, using :debug, then :inspect commands.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: How to consume attack?
No, the orb turns red if you set attacks_left to 0.WhiteWolf wrote:Checking whether a unit can still attack or not is only possible when an enemy unit is standing next to it I guess.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: How to consume attack?
I'm sorry, but I didn't understand why you want to reverse my code. Actually, I do right click in the wounded target and then select the medic. But you want to right click in the healer and then select the wounded. I also though about that option, but isn't there the same problem? Instead of not know the location of the healer I won't know the location of the wounded target (actually it's x1, y1, but you want to use that variables to store the healer).WhiteWolf wrote:Each unit has an attacks_left attribute, set it to 0:Enderlook wrote:After click the healer the unit get heal and the choosen healer loose its attack for this turn. My problem is: How can I do the last part?To solve the rest of your issues, I recommend a bit of change in the approach:Code: Select all
[modify_unit] [filter] # the healer [/filter] attacks_left=0 [/modify_unit]
[set_menu_item] has a [filter] tag. When applied, the menu item is only shown if there is a unit matching the filter where the cursor is. This filter could be to have a healer there, AND that he still has his attack (inside an [and] in the filter, unit.attacks_left must be greater than 0). Then 1) is solved: the healer is the unit with x,y=$x1,$y1.
Then you'd need to store the units adjacent to $x1,$y1 (with 1 radius), and the player selects which wounded unit to heal. When done, use the code above to set the healer's attacks to zero. (so that he won't pass the filter another time in this turn, and can't heal again until next turn).
Checking whether a unit can still attack or not is only possible when an enemy unit is standing next to it I guess... but if you stick with this solution, it's trivial: if the menu item is present, he can still attack, if not, then the unit already used its attack, or has already healed.
For development and testing, these values can be checked manually in the inspection window, using :debug, then :inspect commands.
Thanks!beetlenaut wrote:There is a unit variable called "attacks_left". You can check it or modify it.
http://wiki.wesnoth.org/SingleUnitWML
Re: How to consume attack?
1) Impresive! Seems that "x,y=$healers[{number}].x,$healers[{number}].y" actually works!
2)
2)
Code: Select all
[modify_unit]
[filter]
x,y=$healers[{number}].x,$healers[{number}].y
[/filter]
attacks_left=0
[/modify_unit]
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: How to consume attack?
I think it makes more sense to click on the healer first since it's the one doing the action.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: How to consume attack?
Ok. I'll take that in consideration. Thanks for your opinion, but the opinion of my brother is stronger... and he isn't agree .
Re: How to consume attack?
Doesn't that depend on settings? Also, it stays green in 1.12.beetlenaut wrote:No, the orb turns red if you set attacks_left to 0.
I misunderstood Stick with your code: the coordinates of a healer are indeed $healers[number].x and y. The fun part is of course to determine the number, since its range changes, depending on how many healers are nearby. There could be more ways to this, here's what I'd do, but there's probably easier ways.Enderlook wrote: I'm sorry, but I didn't understand why you want to reverse my code. Actually, I do right click in the wounded target and then select the medic. But you want to right click in the healer and then select the wounded. I also though about that option, but isn't there the same problem? Instead of not know the location of the healer I won't know the location of the wounded target (actually it's x1, y1, but you want to use that variables to store the healer).
Spoiler:
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Re: How to consume attack?
I use 1.12.6, when a unit attack, the orb turns black.WhiteWolf wrote:Doesn't that depend on settings? Also, it stays green in 1.12.beetlenaut wrote:No, the orb turns red if you set attacks_left to 0.
I use something similar to your second code and it's work:
I use this code [option] six times, from 0 to 6. And it works even if there is only 1 adjacent, or 3, or etc.WhiteWolf wrote: Another way would be to have a [message] with six options, each option containing a [show_if] regarding:But I'm not quite sure about this one. If there aren't 3 healers, this means you are indexing out of the healers array. It's supposed to be something zero-like, I think, so have_unit should yield false, and it should work, but I'm not 100% sure.[/spoiler]Code: Select all
# say this is the 3rd option: [show_if] [have_unit] ability=healer x,y=$healers[3].x,$healers[3].y [/have_unit] [/show_if]
Code: Select all
[option]
message={HEALER_PRINT 0}
[show_if]
[variable]
name=healers[0].hitpoints
greater_than=0
[/variable]
[and]
[variable]
name=healers[0].attacks_left
greater_than=0
[/variable]
[/and]
[/show_if]
[command]
{HEALER_WORK 0}
[/command]
[/option]
Re: How to consume attack?
I notice now that I have two little graphical bugs:
That heal the target and consume the attack of the unit. But it doesn't turn the orb into black. What can I do?
Also, when I use [message] it always appear the portrait of the king, not the portrait of the unit in that hex.
Code: Select all
#define HEALER_WORK number
[heal_unit]
amount=$healers[{number}].abilities.dummyhealer.value
animate=yes
[/heal_unit]
[modify_unit]
[filter]
x,y=$healers[{number}].x,$healers[{number}].y
[/filter]
attacks_left=0
[/modify_unit]
#enddef
Also, when I use [message] it always appear the portrait of the king, not the portrait of the unit in that hex.
Re: How to consume attack?
Because in 1.12, orb only turns black when moves=0. Of course, when a unit attacks, its moves also become 0 But, when you modify attacks_left to 0 by hand, moves don't become 0, so orb doesn't turn black.
Who is the speaker in the [message]? Can you please attach that code?
Who is the speaker in the [message]? Can you please attach that code?
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Re: How to consume attack?
Ok, I will reduce its moves also.WhiteWolf wrote:Because in 1.12, orb only turns black when moves=0. Of course, when a unit attacks, its moves also become 0 But, when you modify attacks_left to 0 by hand, moves don't become 0, so orb doesn't turn black.
Who is the speaker in the [message]? Can you please attach that code?
Code: Select all
[message]
message= _ "Which unit will you use to heal me?"
[option]
message= _ "None"
[/option]
[message]
Re: How to consume attack?
Add speaker=unit to the [message]
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny