Various questions: making unit unable to be attacked

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
WTrawi
Posts: 136
Joined: July 11th, 2016, 6:04 pm
Location: My location is not public, but I know YOURS and I can use it against you.

Various questions: making unit unable to be attacked

Post by WTrawi »

Hi everyone! :D

Currently I'm working on a campaign and I have quite a problem in WML. I want to make a unit unable to move (which isn't the problem) and also unable to attack others or to be attacked by others. The attribute "petrified" does this effect, but it also makes the unit a statue as far as I know.

Could you please help me out if you know the solution? Thanks:
WTrawi
Not very active on the forum anymore, but I still read it, and I also still play Wesnoth and draw a bit.
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Various questions: making unit unable to be attacked

Post by Ravana »

For unable to attack, there is attacks_left and max_attacks in unit.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Various questions: making unit unable to be attacked

Post by zookeeper »

To prevent anyone from attacking it, this seems to work if your unit has both a melee and ranged attack:

Code: Select all

                [object]
                    [effect]
                        apply_to=attack

                        [set_specials]
                            mode=append

                            [disable]
                                apply_to=opponent
                            [/disable]
                        [/set_specials]
                    [/effect]
                [/object]
Curiously, you can't use apply_to=both (nor multiple [disable] blocks) to disable both self and opponent attacks. That's probably because as self's weapon is evaluated as being disabled, its disable special won't be able to affect the opponent anymore.
User avatar
skeptical_troll
Posts: 500
Joined: August 31st, 2015, 11:06 pm

Re: Various questions: making unit unable to be attacked

Post by skeptical_troll »

If you are happy with a dirty hack, make a hidden side controlled by 'null' and allied with everyone, then assign that side to the units you want to immobilize. They should stay still and everyone will ignore them. Just remember to bring them back at the end of the scenario.
jyrkive
Inactive Developer
Posts: 36
Joined: July 7th, 2016, 6:20 pm
Location: Helsinki, Finland

Re: Various questions: making unit unable to be attacked

Post by jyrkive »

For making the unit unable to be attacked: this might not be what you need, but on 1.13 you can add the invulnerable status that prevents attacks from hitting the unit.
User avatar
WTrawi
Posts: 136
Joined: July 11th, 2016, 6:04 pm
Location: My location is not public, but I know YOURS and I can use it against you.

Re: Various questions: making unit unable to be attacked

Post by WTrawi »

Wow, there are a lot of answers, thank you for that! :) Now, let's go through:
Ravana wrote:For unable to attack, there is attacks_left and max_attacks in unit.
I tried and it works, but only for one turn... still, it could be the right thing, but Skeptical_troll's solution does it better.
Zookeeper wrote:To prevent anyone from attacking it, this seems to work if your unit has both a melee and ranged attack...
The unit is a drake enforcer which has only melee attacks, does it mean that what you wrote won't work then? Or how can it be changed to be able for using on the enforcer (because I don't understand the code you've written :lol:)
Skeptical_troll wrote:If you are happy with a dirty hack, make a hidden side controlled by 'null' and allied with everyone, then assign that side to the units you want to immobilize.
Haha, that's nice, but the game will show them as allies to the user-controlled team, which is not what I want. But I loved the idea. :lol: Oh, and setting the controller "null" is what I need to prevent the unit attacking others, so thanks for that! :D
Jyrkive wrote:...this might not be what you need, but on 1.13 you can add the invulnerable status that prevents attacks from hitting the unit.
I know about the status "invulnerable", and yes, it isn't what I need.

Thank you for all who answered! :D
Not very active on the forum anymore, but I still read it, and I also still play Wesnoth and draw a bit.
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Various questions: making unit unable to be attacked

Post by Ravana »

attacks_left is one turn, max_attacks stays until changed.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Various questions: making unit unable to be attacked

Post by Sapient »

WTrawi wrote: Haha, that's nice, but the game will show them as allies to the user-controlled team, which is not what I want. But I loved the idea. :lol: Oh, and setting the controller "null" is what I need to prevent the unit attacking others, so thanks for that! :D
It sounds like you have all the pieces you need, but you just need to combine them using events. For example, you can change the unit's side to the one with controller=null at the end of the human turn (side 1 turn end), then restore it at the beginning of the human turn (side 1 turn).
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
WTrawi
Posts: 136
Joined: July 11th, 2016, 6:04 pm
Location: My location is not public, but I know YOURS and I can use it against you.

Re: Various questions: making unit unable to be attacked

Post by WTrawi »

Saplent wrote:It sounds like you have all the pieces you need, but you just need to combine them using events.
No, that's not true, thanks to Zookeeper and Sceptical_troll my problem is totally solved! The unit I wanted to lock has its own side with controller=null and I copied Zookeeper's code in the right place and it worked! :D

Again, thank you so much for all who tried to help me! :D
Not very active on the forum anymore, but I still read it, and I also still play Wesnoth and draw a bit.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Various questions: making unit unable to be attacked

Post by Sapient »

I thought you weren't able to use zookeeper's code because the Drake Enforcer lacks a ranged attack? Try putting some Dark Adepts near it and see if they can attack it.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
WTrawi
Posts: 136
Joined: July 11th, 2016, 6:04 pm
Location: My location is not public, but I know YOURS and I can use it against you.

Re: Various questions: making unit unable to be attacked

Post by WTrawi »

Sapient wrote:I thought you weren't able to use Zookeeper's code because the Drake Enforcer lacks a ranged attack?
Yeah, as it turned out, I wasn't. :? I'm still trying to use a variation of it somehow...
Not very active on the forum anymore, but I still read it, and I also still play Wesnoth and draw a bit.
User avatar
Samonella
Posts: 382
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Various questions: making unit unable to be attacked

Post by Samonella »

Here are a couple ideas that might or might not make sense, depending on your scenario:

1) You could give him a dummy ranged attack, something like 1-1 Intimidation, so it could have that attack special.

2) You could have an attack event that prevents combat by doing something like this, so the human could try to attack, but then nothing happens except a message or something.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
skeptical_troll
Posts: 500
Joined: August 31st, 2015, 11:06 pm

Re: Various questions: making unit unable to be attacked

Post by skeptical_troll »

Other possible approach: if the only reason you don' t like ' petrified' is the grey appearance, maybe you can hide the petrified unit and put on the same hex the base image of the unit :hmm:

it won' t have the idle animations and the HP bars, though.

I don' t know what you are trying to do, but maybe you don' t want the player to find out that he cannot attack the unit only after he has done the (not-undoable) move.
Post Reply