WML problem weapon special - disable ZOC

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.
Post Reply
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

WML problem weapon special - disable ZOC

Post by siddh » June 1st, 2013, 6:53 pm

I think there has been an ability like this somewhere, but I'm not sure and so I just decided to try and make on myself. Here's what I got pieced together so far, it almost works. (I got it to disable the ZOC at some point, but then restoring it didn't work out). Now it doesn't disable the ZOC, so I think the 2nd event is where the problem is at the moment.

Code: Select all

#define WEAPON_SPECIAL_DRACONIAN_STUN TYPE
     [dummy]
        id="draconian_stun_{TYPE}"
        name= _ "Stun"
        description= _ "Stun:
This attack disables ZOC with a succesful hit."
    [/dummy]
[/specials]
[/attack]
[event]
id=draconian_stun_{TYPE}
name=attacker_hits
[filter_attack]
special=draconian_stun_{TYPE}
[/filter_attack]
[filter_second]
          [not]
              race=undead
          [/not]
          [not]
              race=draconian_undead_spirit
          [/not]
          [not]
              race=draconian_undead
          [/not]
          [not]
              race=draconian_golem
          [/not]
[/filter_second]

{STORE_UNIT_VAR x,y=$x2,$y2 zoc has_zoc}
{MODIFY_UNIT x,y=$x2,$y2 variables.real_zoc $has_zoc}
{MODIFY_UNIT x,y=$x2,$y2 variables.stunned yes}
{MODIFY_UNIT x,y=$x2,$y2 zoc no}
{CLEAR_VARIABLE has_zoc}

[/event]
[event]
name=side_turn
[store_unit]
[filter]
[filter_WML]
[variables]
stunned=yes
[/variables]
[/filter_WML]
[/filter]
variable=stunneds
kill=no
[/store_unit]
{FOREACH stunneds i}
{CLEAR_VARIABLE stunneds[$i].zoc}
{VARIABLE stunneds[$i].zoc stunneds[$i].variables.realzoc}
{CLEAR_VARIABLE stunneds[$i].variables.realzoc}
{CLEAR_VARIABLE stunneds[$i].variables.stunned}
{NEXT i}
{CLEAR_VARIABLE stunneds}
[/event]
[+attack]
[+specials]
#enddef

Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: WML problem weapon special - disable ZOC

Post by Max » June 1st, 2013, 7:22 pm

mainline campaign Dead Water has units with a stun weapon special.

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: WML problem weapon special - disable ZOC

Post by zookeeper » June 1st, 2013, 8:41 pm

Both your events will only trigger once.

siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem weapon special - disable ZOC

Post by siddh » June 1st, 2013, 9:20 pm

Oops :D I fixed that, but it still doesn't work. Well gotta go to sleep and figure this out tomorrow or something :D

User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: WML problem weapon special - disable ZOC

Post by Azeal » June 2nd, 2013, 3:51 am

it is cooler to do this with a custom status effect.

Put this in your era or campaign file

Code: Select all


    [event]
        name=preload
        first_time_only=no
        [lua]
            code=<<
                local _ = wesnoth.textdomain "mydomain"
                local old_unit_status = wesnoth.theme_items.unit_status
                function wesnoth.theme_items.unit_status()
                    local u = wesnoth.get_displayed_unit()
                    if not u then return {} end
                    local s = old_unit_status()
                    if u.status.stunned then
                        table.insert(s, { "element", {
                            image = "path for custom image",
                            tooltip = "Stunned: This unit has no ZOC until it's next turn."
                        } })
                    end
                    return s
                end
            >>
        [/lua]
[/event]

this is the weapon special, put {EVENT_STUNNED} in an era or campaign file

Code: Select all


#define WEAPON_SPECIAL_DRACONIAN_STUN
     [dummy]
        id=draconian_stun
        name= _ "Stun"
        description= _ "Stun:
This attack disables ZOC with a succesful hit."
    [/dummy]
#enddef

#define EVENT_STUNNED
    [event]
        name=attacker_hits
        first_time_only=no
        [filter_attack]
            special=draconian_stun
        [/filter_attack]
        [filter_second]
               [not]
                    race=undead
                [/not]
                [not]
                    race=draconian_undead_spirit
                [/not]
                [not]
                    race=draconian_undead
                [/not]
                [not]
                    race=draconian_golem
                [/not]
        [/filter_second]
        [if]
            ###given that zoc can only equal 1 or 0 this is easier than storing variables
            [variable]
                name=second_unit.zoc
                equals=1
            [/variable]
            [then]
                {VARIABLE_OP second_unit.zoc value 0}
                [unstore_unit]
                    variable=second_unit
                    text=_ "stunned"	# wmllint: ignore
                    red,green,blue=150,80,50
                [/unstore_unit]
                {MODIFY_UNIT x,y=$x2,$y2 status.stunned yes}
            [/then]
        [/if]
    [/event]

#side turn refresh is better for modifying units, sometimes side_turn modifications will be overridden after refresh.
    [event]
        name=side_turn_refresh
        first_time_only=no
        [store_unit]
            [filter]
                ###if you want units to regain their ZOC on their own turn put side=$side_number
                ###as it stands they will regain their ZOC as soon as the damaging parties turn is over.
                [filter_WML]
                    [status]
                        stunned=yes
                    [/status]
                [/filter_WML]
            [/filter]
            variable=stunned_units
            kill=no
        [/store_unit]
        {FOREACH stunned_units i}
                {VARIABLE_OP stunned_units[$i].zoc value 1}
                {VARIABLE_OP stunned_units[$i].status.stunned value no}
                [unstore_unit]
                    variable=stunned_units[$i]
                [/unstore_unit]
        {NEXT i}
        {CLEAR_VARIABLE stunned_units}
    [/event]
#enddef


siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem weapon special - disable ZOC

Post by siddh » June 2nd, 2013, 9:31 am

Cool thanks. I tried this via copy pasting but couldn't get it to work, I think it's probably a bit too much for now to add any graphical overlays: D I mean the units don't have graphics either, but it would be very cool :D Really they're stored as 1 or 0? I thought it's "yes" "no" or *blank* like on the unit wml page? That does simplify things considerably :D

JaMiT
Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: WML problem weapon special - disable ZOC

Post by JaMiT » June 2nd, 2013, 2:26 pm

siddh wrote:Really they're stored as 1 or 0? I thought it's "yes" "no" or *blank* like on the unit wml page?
It's a boolean value, so it should be stored as "yes" or "no".
siddh wrote:That does simplify things considerably :D
Why would it? (It's just replacing one symbol for another.)

siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem weapon special - disable ZOC

Post by siddh » June 2nd, 2013, 4:53 pm

JaMiT wrote:Why would it? (It's just replacing one symbol for another.)
Because then there would be no *blank*

User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: WML problem weapon special - disable ZOC

Post by Azeal » June 3rd, 2013, 10:09 am

JaMiT wrote:
siddh wrote:Really they're stored as 1 or 0? I thought it's "yes" "no" or *blank* like on the unit wml page?
It's a boolean value, so it should be stored as "yes" or "no".
that must be new, I'm positive it used to be 0 means no ZOC and anything else means it does.

User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: WML problem weapon special - disable ZOC

Post by Azeal » June 3rd, 2013, 10:15 am

Baring that in mind try this.

Code: Select all


#define WEAPON_SPECIAL_DRACONIAN_STUN
     [dummy]
        id=draconian_stun
        name= _ "Stun"
        description= _ "Stun:
This attack disables ZOC with a succesful hit."
    [/dummy]
#enddef

#define EVENT_STUNNED
    [event]
        name=attacker_hits
        first_time_only=no
        [filter_attack]
            special=draconian_stun
        [/filter_attack]
        [filter_second]
               [not]
                    race=undead
                [/not]
                [not]
                    race=draconian_undead_spirit
                [/not]
                [not]
                    race=draconian_undead
                [/not]
                [not]
                    race=draconian_golem
                [/not]
        [/filter_second]
        [if]
            [variable]
                name=second_unit.zoc
                not_equals=no
            [/variable]
            [then]
                {VARIABLE_OP second_unit.zoc value no}
                [unstore_unit]
                    variable=second_unit
                    text=_ "stunned"	# wmllint: ignore
                    red,green,blue=150,80,50
                [/unstore_unit]
                {MODIFY_UNIT x,y=$x2,$y2 status.stunned yes}
            [/then]
        [/if]
    [/event]

    [event]
        name=side_turn_refresh
        first_time_only=no
        [store_unit]
            [filter]
                [filter_WML]
                    [status]
                        stunned=yes
                    [/status]
                [/filter_WML]
            [/filter]
            variable=stunned_units
            kill=no
        [/store_unit]
        {FOREACH stunned_units i}
                {VARIABLE_OP stunned_units[$i].zoc value yes}
                {CLEAR_VARIABLE stunned_units[$i].status.stunned}
                [unstore_unit]
                    variable=stunned_units[$i]
                [/unstore_unit]
        {NEXT i}
        {CLEAR_VARIABLE stunned_units}
    [/event]
#enddef

Last edited by Azeal on June 3rd, 2013, 11:19 am, edited 1 time in total.

siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: WML problem weapon special - disable ZOC

Post by siddh » June 3rd, 2013, 10:19 am

What I meant was that I just assumed it was like it's stored in the [unit_type] in which you can write zoc=no, zoc=yes or leave it blank, as in not write in zoc at all. And I didn't know the unit has either 0 or 1, which made it simpler than I thought it would be, but that of course was a change in my awareness of how this wml bit works, not a change in the way the WML actually works :lol2:

JaMiT
Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: WML problem weapon special - disable ZOC

Post by JaMiT » June 4th, 2013, 4:06 am

siddh wrote:
JaMiT wrote:Why would it? (It's just replacing one symbol for another.)
Because then there would be no *blank*
Well, even if that was a possibility, often phrasing your conditions in a good way prevents complications from slipping in. Let's see where the complications are in your code....
Well, it's kind of tough to read because many lines are not indented. Focusing on just the lines that mention "zoc", you seem to have more complications arising from your approach, rather than whether or not a value can be blank. Specifically, I think (again, not carefully checked) your lines:

Code: Select all

{STORE_UNIT_VAR x,y=$x2,$y2 zoc has_zoc}
{MODIFY_UNIT x,y=$x2,$y2 variables.real_zoc $has_zoc}
{MODIFY_UNIT x,y=$x2,$y2 variables.stunned yes}
{MODIFY_UNIT x,y=$x2,$y2 zoc no}
{CLEAR_VARIABLE has_zoc}
{CLEAR_VARIABLE zoc} # This line is missing. You should clear this variable as well since it is not used elsewhere.
are doing the same thing as:

Code: Select all

    {VARIABLE second_unit.variables.real_zoc $second_unit.has_zoc}
    {VARIABLE second_unit.variables.stunned yes}
    {VARIABLE second_unit.zoc no}
    [unstore_unit]
        variable=second_unit
    [/unstore_unit]
That eliminates the extra variables and greatly reduces the work done by the game behind the scenes. As a bonus, you could add a text= attribute to the [unstore_unit] tag so the player gets some feedback as to what happened.

One difference when storing the old value of zoc is that you could have the status apply to units without a zone of control, even though it would have no effect. I won't say "better" or "worse", but it is a different way to go. (Speaking of which -- do you have a filter to prevent stunned units from being stunned? If not, then hitting the unit twice with a stunning weapon could permanently remove the zone of control. With "permanent" meaning "until death or advancing".)

__
Azeal wrote:that must be new, I'm positive it used to be 0 means no ZOC and anything else means it does.
Based on the changelog, it looks like the key has been a boolean value since (at least) version 1.5.2. Although, it may be that it was possible to get away with using "0" and "1" instead of "no"/"false" and "yes"/"true" until around version 1.9.0.

Post Reply