Poison Code

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.
User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: Poison Code

Post by Azeal »

Dugi wrote:It is meaningless to give entire pieces of code to people with little coding knowledge, because they may place it incorrectly then, or do a small change wrongly and then report that it doesn't work. It happened many times. It is much better to help him to write the code, giving him hints, corrections and smaller pieces of code, until it gets assembled. This takes more time, but will teach him to use similar things and will make sure that he'll not ask two days later about another custom ability with similar properties.
When someone is learning and has no coding experience I think it is better to provide code and explain how it works. The wiki is helpful when you already have an understanding of how and where you can place the code, but when working with pieces of wml that you haven't used before the wiki isn't enough, and fragments will just cause you to try to randomly compile them in a trial and error sense. Then IF you get it working you still don't know why and haven't learned anything. In my experience (both my own and observing others) when given a piece of code and an explanation of how it works people generally try and play with it to achieve similar bits of code before coming back here for help. Sometimes they figure it out for themselves before someone fixes it for them to. Too often someone will make a rude comment about somebody or accuse them of being lazy because they aren't learning as fast as some people would like.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Poison Code

Post by Dugi »

If he had no coding experience, he would not be asking about advanced custom abilities. He obviously had enough coding experience to be able to create custom abilities to some extent (he would not wonder how to edit poison otherwise), and that is usually more than basic things like making simple scenarios. He has enough experience to code parts of it himself, he does not need others to write lengthy codes for him. Programming was always learned by experimentation.
And there is almost no reason to continue this, as this guy has not logged in for two weeks, therefore appears to be gone.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Poison Code

Post by Ravana »

I chose to try to do this, because this interests me not because opener demanded it. Currently i have custom poison with colored unit but still need to add how it is removed.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Poison Code

Post by Dugi »

My code for incineration should contain a structure you might find useful for this task. Incineration is something like poison, but it deals 16 fire damage per turn, kills and gives exp (if I remember correctly).
Spoiler:
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Poison Code

Post by Ravana »

Almost ready, everything seems to work, going to try some more before posting it.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Poison Code

Post by Ravana »

Here, if you find any problems let me know.

Code: Select all

# Written by Laela(Ravana in forums)
# Idea how to do it from Era of Four Moons hex
# To make poison kill change line 132
#define POISON_VALUE DMG
    [dummy]
        id=lms_poison_{DMG}
        name= _ "poison {DMG}"
        name_inactive= _ "poison"
        description= _ "This attack poisons living targets. Poisoned units lose " + {DMG} + _ " HP every turn until they are cured or are reduced to 1 HP. Poison can not, of itself, kill a unit."
        description_inactive= _ "This attack poisons living targets. Poisoned units lose " + {DMG} + _ " HP every turn until they are cured or are reduced to 1 HP. Poison can not, of itself, kill a unit."
        apply_to=opponent
    [/dummy]
[/specials]
[/attack]

[event]
    name=attacker hits
    first_time_only=no
    id=attacker_poisons
    [filter_attack]
        special=lms_poison_{DMG}
    [/filter_attack]
    [filter_second]
        [not]
            [filter_wml]
                [status]
                    not_living=yes
                [/status]
            [/filter_wml]
        [/not]
        [not]
            [filter_wml]
                [variables]
                    poisoned{DMG}=yes
                [/variables]
            [/filter_wml]
        [/not]
    [/filter_second]
    {VARIABLE second_unit.variables.poisoned{DMG} yes}
    {VARIABLE second_unit.status.unhealable yes}
    [unstore_unit]
        variable=second_unit
        find_vacant=no
    [/unstore_unit]
    [object]
        [filter]
            id=$second_unit.id
        [/filter]
        silent=yes
        [effect]
            apply_to=image_mod
            replace="CS(-100,-25,-22)"
        [/effect]
    [/object]
[/event]

[event]
    name=defender hits
    first_time_only=no
    id=defender_poisons
    [filter_second_attack]
        special=lms_poison_{DMG}
    [/filter_second_attack]
    [filter]
        [not]
            [filter_wml]
                [status]
                    not_living=yes
                [/status]
            [/filter_wml]
        [/not]
    [/filter]
    {VARIABLE unit.variables.poisoned{DMG} yes}
    {VARIABLE unit.status.unhealable yes}
    [unstore_unit]
        variable=unit
        find_vacant=no
    [/unstore_unit]
    [object]
        [filter]
            id=$unit.id
        [/filter]
        silent=yes
        [effect]
            apply_to=image_mod
            replace="CS(-100,-25,-22)"
        [/effect]
    [/object]
[/event]

[event]
    name=turn refresh
    id=main_harmer
    first_time_only=no
    [store_unit]
        [filter]
            side=$side_number
            [filter_wml]
                [variables]
                    poisoned{DMG}=yes
                [/variables]
            [/filter_wml]
            [not]
                [filter_adjacent]
                    is_enemy=no
                    ability=curing
                [/filter_adjacent]
                [or]
                    [filter_adjacent]
                        is_enemy=no
                        ability=healing
                    [/filter_adjacent]
                [/or]
                [or]
                    [filter_location]
                        terrain=*^V*
                    [/filter_location]
                [/or]
                [or]
                    ability=regenerates
                [/or]
            [/not]
        [/filter]
        variable=poisoned_temp
    [/store_unit]
    {FOREACH poisoned_temp i}
        [harm_unit]
            [filter]
                id=$poisoned_temp[$i].id
            [/filter]
            amount={DMG}
            kill=no
        [/harm_unit]
    {NEXT i}
    {CLEAR_VARIABLE poisoned_temp}
[/event]

[event]
    name=turn refresh
    first_time_only=no
    id=remove_poison
    [store_unit]
        [filter]
            side=$side_number
            [filter_wml]
                [variables]
                    poisoned{DMG}=yes
                [/variables]
            [/filter_wml]

            [and]
                [filter_adjacent]
                    is_enemy=no
                    ability=curing
                [/filter_adjacent]

                [or]
                    [filter_location]
                        terrain=*^V*
                    [/filter_location]
                [/or]
                [or]
                    ability=regenerates
                [/or]
            [/and]
        [/filter]
        variable=poisoned_temp
    [/store_unit]

    {FOREACH poisoned_temp i}
        {VARIABLE poisoned_temp[$i].variables.poisoned{DMG} no}
        {VARIABLE poisoned_temp[$i].status.unhealable no}
        [unstore_unit]
            variable=poisoned_temp[$i]
            find_vacant=no
        [/unstore_unit]
        [object]
            [filter]
                id=$poisoned_temp[$i].id
            [/filter]
            silent=yes
            [effect]
                apply_to=image_mod
                replace="CS(0,0,0)"
            [/effect]
        [/object]
    {NEXT i}
    {CLEAR_VARIABLE poisoned_temp}
[/event]

[event]
    name=post advance
    first_time_only=no
    id=unpoison_on_levelup
    {VARIABLE unit.variables.poisoned{DMG} no}
    {VARIABLE unit.status.unhealable no}
    [unstore_unit]
        variable=unit
        find_vacant=no
    [/unstore_unit]
[/event]

[+attack]
    [+specials]
#enddef
Added id to events and removed poison after levelup.
Last edited by Ravana on June 18th, 2013, 5:48 pm, edited 2 times in total.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Poison Code

Post by Dugi »

Looking at it, I see that you forgot to give id= keys to most events. Some events will be duplicated if the units appear more than once.
To understand what does the +tag thing do, read this::
User avatar
Astoria
Inactive Developer
Posts: 1007
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Re: Poison Code

Post by Astoria »

I'd recommend you animate the healer, so it actually looks like it's healing the poisoned unit. Also, you could use a bit of lua to make the poisoned icon appear in the sidebar.
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Poison Code

Post by Ravana »

I have never animated here anything and never done anything with lua. Would be helpful if you could point out where to start learning wesnoth-related lua.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Poison Code

Post by Wussel »

Wow, so nice!
Hope we will get an easy to use macro for everybody. This coding really goes over my head.
Keep up the great work!
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Poison Code

Post by Wussel »

JaMiT wrote: Greater sophistication in implementation (more-or-less meaning being able to handle variations) is usually good, provided the overall "simple stupid" guideline is not violated.

In this case, the question really is whether or not it is worth complicating the player's experience with poisons of various strengths. For example, suppose a player has poisoned units on the board -- how would the player know which are affected by the weaker (or stronger) poison and which are affected by standard poison? How would this difference be distinguished in the poisoning units? (And maybe some additional non-obvious complications that I cannot think of off the top of my head.) Is there enough benefit from this change to poison to warrant these complications for players?
Well I suppose the word got your attention. I would assume more variety of poison would be cool for campaigns. Not for core units of course. The strength and duration of poison would not have to be displayed in my opinion. You could announce that in a dialog like: "Beware of the snakes they have very strong poison! If they do not kill you in 3 turns you might survive."

Problems would be: If killed by poison, are the XP lost?
If already poisoned by weak poison, will it protect from strong poison?
Could there be be immunity built up to poison which does not last indefinite?

While this stuff might get complicated, I would still call it sophisticated, but I am not a native speaker.

I believe it has huge potential for user made content.
User avatar
Astoria
Inactive Developer
Posts: 1007
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Re: Poison Code

Post by Astoria »

Code: Select all

#define POISON_VALUE DMG
    [dummy]
        id=lms_poison_{DMG}
        name= _ "poison {DMG}"
        name_inactive= _ "poison"
        description= _ "This attack poisons living targets. Poisoned units lose " + {DMG} + _ " HP every turn until they are cured or are reduced to 1 HP. Poison can not, of itself, kill a unit."
        description_inactive= _ "This attack poisons living targets. Poisoned units lose " + {DMG} + _ " HP every turn until they are cured or are reduced to 1 HP. Poison can not, of itself, kill a unit."
        apply_to=opponent
    [/dummy]
[/specials]
[/attack]

[event]
    name=attacker hits
    first_time_only=no
    id=attacker_poisons{DMG}
    [filter_attack]
        special=lms_poison_{DMG}
    [/filter_attack]
    [filter_second]
        [not]
            [filter_wml]
                [status]
                    not_living=yes
                [/status]
            [/filter_wml]
        [/not]
        [not]
            [filter_wml]
                [status]
                    poisoned=yes
                [/status]
            [/filter_wml]
        [/not]
        [not]
            [filter_wml]
                [variables]
                    poisoned=yes
                [/variables]
            [/filter_wml]
        [/not]
    [/filter_second]
    {VARIABLE second_unit.variables.poisoned yes}
    {VARIABLE second_unit.variables.poison_value ({DMG})}
    {VARIABLE second_unit.status.unhealable yes}
    [sound]
        name=poison.ogg
    [/sound]
    [unstore_unit]
        variable=second_unit
        find_vacant=no
    [/unstore_unit]
    [object]
        [filter]
            id=$second_unit.id
        [/filter]
        silent=yes
        [effect]
            apply_to=image_mod
            replace="CS(-100,-25,-22)"
        [/effect]
    [/object]
[/event]

[event]
    name=defender hits
    first_time_only=no
    id=defender_poisons{DMG}
    [filter_second_attack]
        special=lms_poison_{DMG}
    [/filter_second_attack]
    [filter]
        [not]
            [filter_wml]
                [status]
                    not_living=yes
                [/status]
            [/filter_wml]
        [/not]
        [not]
            [filter_wml]
                [status]
                    poisoned=yes
                [/status]
            [/filter_wml]
        [/not]
        [not]
            [filter_wml]
                [variables]
                    poisoned=yes
                [/variables]
            [/filter_wml]
        [/not]
    [/filter]
    {VARIABLE unit.variables.poisoned yes}
    {VARIABLE second_unit.variables.poison_value ({DMG})}
    {VARIABLE unit.status.unhealable yes}
    [sound]
        name=poison.ogg
    [/sound]
    [unstore_unit]
        variable=unit
        find_vacant=no
    [/unstore_unit]
    [object]
        [filter]
            id=$unit.id
        [/filter]
        silent=yes
        [effect]
            apply_to=image_mod
            replace="CS(-100,-25,-22)"
        [/effect]
    [/object]
[/event]

[event]
    name=turn refresh
    id=main_harmer{DMG}
    first_time_only=no
    [store_unit]
        [filter]
            side=$side_number
            [filter_wml]
                [variables]
                    poisoned=yes
                    poison_value={DMG}
                [/variables]
            [/filter_wml]
            [not]
                [filter_adjacent]
                    is_enemy=no
                    ability=curing
                [/filter_adjacent]
                [or]
                    [filter_adjacent]
                        is_enemy=no
                        ability=healing
                    [/filter_adjacent]
                [/or]
                [or]
                    [filter_location]
                        terrain=*^V*
                    [/filter_location]
                [/or]
                [or]
                    ability=regenerates
                [/or]
            [/not]
        [/filter]
        variable=poisoned_temp
    [/store_unit]
    {FOREACH poisoned_temp i}
        [harm_unit]
            [filter]
                id=$poisoned_temp[$i].id
            [/filter]
            amount={DMG}
            kill=no
        [/harm_unit]
    {NEXT i}
    {CLEAR_VARIABLE poisoned_temp}
[/event]

[event]
    name=turn refresh
    first_time_only=no
    id=remove_poison{DMG}
    [store_unit]
        [filter]
            side=$side_number
            [filter_wml]
                [variables]
                    poisoned=yes
                [/variables]
            [/filter_wml]

            [and]
                [filter_adjacent]
                    is_enemy=no
                    ability=curing
                [/filter_adjacent]

                [or]
                    [filter_location]
                        terrain=*^V*
                    [/filter_location]
                [/or]
                [or]
                    ability=regenerates
                [/or]
            [/and]
        [/filter]
        variable=poisoned_temp
    [/store_unit]

    {FOREACH poisoned_temp i}
        [if]
            [have_unit]
                id=$poisoned_temp[$i].id
                ability=regenerates
            [/have_unit]
            [else]
                [animate_unit]
                    flag=healing
                    [filter]
                        ability=curing
                        [filter_adjacent]
                            is_enemy=no
                            id=$poisoned_temp[$i].id
                        [/filter_adjacent]
                    [/filter]
                    with_bars=yes
                [/animate_unit]
            [/else]
        [/if]
        {CLEAR_VARIABLE poisoned_temp[$i].variables.poisoned}
        {CLEAR_VARIABLE poisoned_temp[$i].variables.poison_value}
        {VARIABLE poisoned_temp[$i].status.unhealable no}
        [sound]
            name=heal.wav
        [/sound]
        [unstore_unit]
            variable=poisoned_temp[$i]
            find_vacant=no
            {COLOR_HEAL}
            text= _ "cured"
        [/unstore_unit]
        [object]
            [filter]
                id=$poisoned_temp[$i].id
            [/filter]
            silent=yes
            [effect]
                apply_to=image_mod
                replace="CS(0,0,0)"
            [/effect]
        [/object]
    {NEXT i}
    {CLEAR_VARIABLE poisoned_temp}
[/event]

[event]
    name=post advance
    first_time_only=no
    id=unpoison_on_levelup{DMG}
    {CLEAR_VARIABLE unit.variables.poisoned}
    {CLEAR_VARIABLE unit.variables.poison_value}
    {VARIABLE unit.status.unhealable no}
    [unstore_unit]
        variable=unit
        find_vacant=no
    [/unstore_unit]
    [object]
        [filter]
            id=$unit.id
        [/filter]
        silent=yes
        [effect]
            apply_to=image_mod
            replace="CS(0,0,0)"
        [/effect]
    [/object]
[/event]

[+attack]
    [+specials]
#enddef
I changed your code a little bit to improve usability with different poison values, and I added an animation for the healers. I haven't tested the code yet, though.
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Poison Code

Post by JaMiT »

Wussel wrote:Problems would be: If killed by poison, are the XP lost?
If already poisoned by weak poison, will it protect from strong poison?
Could there be be immunity built up to poison which does not last indefinite?
I would not implement death-by-poison. It adds too much complexity to the game mechanics.
No, the stronger poison would overwrite the weaker. (Weaker would not overwrite stronger, though.)
No, this sort of immunity would be an unnecessary complication and moreover goes against [acronym=Frequently Proposed (and rejected) Ideas]FPI[/acronym] 29.
Wussel wrote:While this stuff might get complicated, I would still call it sophisticated, but I am not a native speaker.
There is overlap between "complicated" and "sophisticated" (something can be both complicated and sophisticated), but they are not the same thing (something can be complicated without being sophisticated, and something can be sophisticated without being complicated).
User avatar
beshead0
Posts: 8
Joined: July 17th, 2012, 9:48 pm

Re: Poison Code

Post by beshead0 »

I tested bumbadadabum's code and it works perfectly (I tested it by giving the assassin an advancement with poison 20).

I have a question of my own:
Would it be possible to modify a poison sort of ability so that the amount damaged increased every turn? (It's not intended to be mainline balanced, but my original idea was 2 and then increased by 4 every turn, so, 2 damage first turn, 6 damage second, 10 third, so on.) I'm intending on creating a "burn" special and I can figure out how to make it orange/red, have it affect even the nonliving, etc. but I would have no idea how to modify the poison damage between turns.
you know
the person
who does the things
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Poison Code

Post by Ravana »

This could be done with adding new event for every turn that increases all existing poisons values, but then whole ability structure might require minor changes in order to keep all parts working.
Post Reply