Creating Poison like effect with Plague effect at 0 HP?

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.
Wayirr
Posts: 90
Joined: February 11th, 2012, 3:42 pm

Re: Creating Poison like effect with Plague effect at 0 HP?

Post by Wayirr »

Of course you should, I'm trying to do exactly same thing, but for other purpose. Please post the entire code. Why didn't you post it yet?

Since you didn't post your code, I will post mine:

Code: Select all

#define INFECTION_RESULT
"Walking Corpse" #enddef

#define WEAPON_SPECIAL_INFECTION
    # Canned definition of the Infection ability to be included in a
    # [specials] clause. Must be used with {EVENTS_INFECTION}
    [plague]
        # infection also implies plague, name tag other way to override this behavior
        id=infection
        name=_"infection"
        description= _ "Infection:
This attack infects living targets. Infected units lose 8 HP every turn until their brains decay completely making them behave and look like a walking corpse."
        type={INFECTION_RESULT}
    [/plague]
#enddef

#define EVENTS_INFECTION
    # Macro to add necessary events, it's meant to be used with {WEAPON_SPECIAL_INFECTION}
    # For units having infected weapon

    [event]
         name=preload
         first_time_only=no
         id=show_infection
         [lua]
             code=<<
                 local _ = wesnoth.textdomain "wesnoth-MyTextDomain"
                 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.infected then
                         table.insert(s, { "element", {
                             image = "misc/infected.png",
                             tooltip = _"infected: This unit is infected. It will lose 8 hp every turn and will be turned into zombie after death."
                         } })
                     end
                     return s
                 end
             >>
         [/lua]
    [/event]
    [event]
    # Helper event to fire preload event even if there was no save/loads
        name=attack
        first_time_only=yes
        id=fire_preload_event
        [fire_event]
            name=preload
        [/fire_event]
    [/event]

    [event]
        name=attacker_hits
        id=defender_infected
        first_time_only=no
        [filter_attack]
            special=infection
        [/filter_attack]
        [filter_second]
            [not]
                [filter_wml]
                    [status]
                        not_living=yes
                    [/status]
                [/filter_wml]
            [/not]
        [/filter_second]
        [modify_unit]
            [filter]
                id=$second_unit.id
            [/filter]
            [status]
                infected=yes
            [/status]
            [variables]
                infected_by_side=$unit.side
            [/variables]
        [/modify_unit]
    [/event]
    [event]
        name=defender_hits
        id=attacker_infected
        first_time_only=no
        [filter_second_attack]
            special=infection
        [/filter_second_attack]
        [filter]
            [not]
                [filter_wml]
                    [status]
                        not_living=yes
                    [/status]
                [/filter_wml]
            [/not]
        [/filter]
        [modify_unit]
            [filter]
                id=$unit.id
            [/filter]
            [status]
                infected=yes
            [/status]
            [variables]
                infected_by_side=$second_unit.side
            [/variables]
        [/modify_unit]
    [/event]

    [event]
        name=side_turn
        first_time_only=no
        [harm_unit]
            kill=yes
            fire_event=yes
            animate=no
            amount=8
            [filter]
                [filter_wml]
                    [status]
                        infected=yes
                    [/status]
                [/filter_wml]
                [and]
                    [filter_side]
                        side=$side_number
                    [/filter_side]
                [/and]
            [/filter]
        [/harm_unit]
    [/event]
    [event]
        name=last_breath
        id=zombify_infected_units
        first_time_only=no
        [filter]
            [filter_wml]
                [status]
                    infected=yes
                [/status]
            [/filter_wml]
        [/filter]
        [store_unit]
            [filter]
                id=$unit.id
            [/filter]
            variable=infected_unit
            kill=yes
        [/store_unit]
        [unit]
            type={INFECTION_RESULT}
            upkeep=loyal # you may want to use trait loyal instead, or don't use it at all
            animate=yes
            side=$infected_unit.variables.infected_by_side
            x,y=$infected_unit.x,$infected_unit.y
            name=$infected_unit.name
            variation=$infected_unit.undead_variation
            facing=$infected_unit.facing
        [/unit]
        {CLEAR_VARIABLE infected_unit}
    [/event]
#enddef
I written this code on my own, since you didn't post yours, except lua fragment, hopefully this code will help someone.

Also, to add weapon special you should use macro {EVENTS_INFECTION} into either scenario where this special is used or better under [unit_type] tag, while the {WEAPON_SPECIAL_INFECTION} macro is for using inside [attack][specials] tags. INFECTION_RESULT is used only in this two macros to define into what should the infected unit be turned to, for example you may copy zombie from mainline and name it other way.

Also, this code lacks proper animation and other visual effects, except the icon in sidebar, so if you add it, post it here (thought I guess, that's easy and I will do it myself beforehand).

This code works slightly other way, for example it doesn't treat poison separately, though I didn't check how it behave in combination, I guess, it should result into unit losing 16 hp in turn and turning into corpse after that.
Attachments
Icon to use with the code
Icon to use with the code
infected.png (3.07 KiB) Viewed 601 times
Post Reply