counting zombies

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
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

counting zombies

Post by battlestar »

Image


This counts number of zombifications, it works most of the time (adds 1 to $zombie_number per kill) but occassionally it flips out and loops couple of times thus adding more than 1 per kill. Occassionally it even fires when the attack special isn't plague... Can't quite put my finger on why, and how to fix.

Code: Select all

# if turned zombie, +1.
	[event]
		name=attacker hits
		first_time_only=no
		[filter]
			side=1
		[/filter]
		[filter_attack]
			special=plague
		[/filter_attack]
		[filter_second]
			[or]
				side=2
				side=3
				side=4
			[/or]
		[/filter_second]
#		[message]
#					id=Valia
#					message= _ "$zombie_number"
#		[/message]
			[event]
				name=die
				first_time_only=yes
				[filter]
					[not]
						side=1
					[/not]
				[/filter]
				[set_variable]
					name=zombie_number
					add=1
				[/set_variable]
				[message]
					id=Valia
					message= _ "We have zombified $zombie_number humans."
				[/message]
				
			[/event]
	[/event]
Last edited by battlestar on June 22nd, 2011, 3:54 am, edited 1 time in total.
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
Crendgrim
Moderator Emeritus
Posts: 1328
Joined: October 15th, 2010, 10:39 am
Location: Germany

Re: counting zombies

Post by Crendgrim »

Well, the first event (attacker hits) is fired each time when a unit of side 1 is hitting another unit (I don't know if the filters are correct, they're looking weird, but I'm not that good in WML. Leaving this for someone else). In this event, you register another event - a die event which only triggers once.
However, imagine the following situation: You need two hits to kill your opponent - then two of the latter events are registered and triggered on that unit's death. This even works, if you hit one unit, don't kill it and then kill another one.
I don't think it's necessary to use nested events here, you should also be fine with only the die event (modified, of course).


Crend
UMC Story Images — Story images for your campaign!
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: counting zombies

Post by Sapient »

this is definitely wrong:

Code: Select all

         [or]
            side=2
            side=3
            side=4
         [/or]
Assuming for a moment that side= in Standard Unit Filter doesn't support lists, the first condition should be outside the [or] tag and the others should have their own seperate [or] tags. However, since side= in SUF *does* support lists, you don't need the [or] tag at all.
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
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: counting zombies

Post by battlestar »

Thanks for your inputs. Portion of the code fixed according to Sapient and the problem persist as Crendgrim pointed out. It added multiple times if several attacks using plague was done.

Using only name=die didn't work, it didn't seem to accept the weapon filter (the wiki also didn't list weapon filter can be used in die event). It needs an if-else I think, either inside the nested event: if another unit was selected -- nothing happens, else -- variable plus 1. Or no nested event: if secondary unit dies -- variable plus 1, else -- nothing.

Anyways, close to figuring it out.
LUA: Llama Under Apprenticeship
Hell faction: completed
Brilliand
Posts: 80
Joined: July 11th, 2009, 12:15 am

Re: counting zombies

Post by Brilliand »

Check the target's HP - it should be zero or less if the unit is dying.

Alternatively, check whether the unit's tile is occupied in the Die event. The unit should be gone by then, so if the tile is occupied, then it's probably due to a plague attack (you can check the unit type for more insurance).
You are a Dark Adept: you dimmerse yourself in the dark arts...potentially with great rewards....
-JW's personality quiz
User avatar
Crendgrim
Moderator Emeritus
Posts: 1328
Joined: October 15th, 2010, 10:39 am
Location: Germany

Re: counting zombies

Post by Crendgrim »

Brilliand wrote:Alternatively, check whether the unit's tile is occupied in the Die event. The unit should be gone by then, so if the tile is occupied, then it's probably due to a plague attack (you can check the unit type for more insurance).
No, this shouldn't work; at least not if the Wiki is right. It says that the unit isn't removed until after the die event finishes and that it can still be adressed. So this won't work.


Crend
UMC Story Images — Story images for your campaign!
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: counting zombies

Post by monochromatic »

If I'm understanding what you want:

Code: Select all

[event]
    name=prestart
    {VARIABLE zombie_number 0}
[/event]

[event]
    name=attack end
    first_time_only=no
    [filter]
        side=1
    [/filter]
    [filter_attack]
        special=plague
    [/filter_attack]
    [filter_second]
        [not]
            race=undead
            [and]
                race=mechanical
            [/and]
        [/not]
    [/filter]

    [if]
        [variable]
            name=second_unit.hitpoints
            less_than_equal_to=0
        [/variable]
        [then]
            {VARIABLE_OP zombie_number add 1}
            # Messages.. and the like.
        [/then]
    [/if]
[/event]
# And repeat backwards in the case of a retaliatory plague kill.
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: counting zombies

Post by battlestar »

thanks, that does exactly it.
LUA: Llama Under Apprenticeship
Hell faction: completed
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: counting zombies

Post by monochromatic »

Did you repeat it backwards? At this stage, it won't count a kill if the WC kills a unit in retaliation.
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: counting zombies

Post by Ceres »

monochromatic wrote:

Code: Select all

[filter_second]
        [not]
            race=undead
            [and]
                race=mechanical
            [/and]
        [/not]
    [/filter]
Wouldn't [or] be more senseful?
Also, the closing tag should be [/filter_second] (though [/filter] would've created an error, which it apparently didn't, so I guess it's fixed by now).
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: counting zombies

Post by monochromatic »

Ceres wrote:
monochromatic wrote:

Code: Select all

[filter_second]
        [not]
            race=undead
            [and]
                race=mechanical
            [/and]
        [/not]
    [/filter]
Wouldn't [or] be more senseful?
Also, the closing tag should be [/filter_second] (though [/filter] would've created an error, which it apparently didn't, so I guess it's fixed by now).
He must have fixed it. Sorry, my bad. And on the [or] things, I'm not sure.
User avatar
Crendgrim
Moderator Emeritus
Posts: 1328
Joined: October 15th, 2010, 10:39 am
Location: Germany

Re: counting zombies

Post by Crendgrim »

IMO Ceres is right; and if he isn't, it should be changed. You have to read "from inward to outward", so you first see "race=undead [logical and] race=mechanical" which cannot be true anytime, and then you negate this which will cause the event to trigger always. :?
At least that's how it makes sense to me.


Crend
UMC Story Images — Story images for your campaign!
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: counting zombies

Post by battlestar »

For the purpose of the current SP scn, it doesn't need to consider retaliation, I'll keep it in mind if another map has something similar. The only kink is when the enemy is on a village it doesn't get zombified... but I thought the player should get the bonus for the motion anyway, so letting it slide I guess.

Thanks for the help.

monochromatic's code syntax adjusted:

Code: Select all

[event]
    name=prestart
    {VARIABLE zombie_number 0}
[/event]

[event]
    name=attack end
    first_time_only=no
    [filter]
        side=1
    [/filter]
    [filter_attack]
        special=plague
    [/filter_attack]
    [filter_second]
        [not]
            race=undead
            [or]
                race=mechanical
            [/or]
        [/not]
    [/filter_second]

    [if]
        [variable]
            name=second_unit.hitpoints
            less_than_equal_to=0
        [/variable]
        [then]
            {VARIABLE_OP zombie_number add 1}
            # Messages.. and the like.
        [/then]
    [/if]
[/event]
# And repeat backwards in the case of a retaliatory plague kill.
LUA: Llama Under Apprenticeship
Hell faction: completed
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: counting zombies

Post by monochromatic »

For villages, this should work (untested):

Code: Select all

# Replace the [filter_second] with
[filter_second]
    [not]
        [filter_location]
            terrain=*^V*
        [/filter_location]
        [and]
            race=undead
            [or]
                race=mechanical
            [/or]
        [/and]
    [/not]
[/filter_second]
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: counting zombies

Post by Dixie »

It just occured to me that isntead of:

Code: Select all

    [not]
            race=undead
            [or]
                race=mechanical
            [/or]
    [/not]
You could probably use a more general/exhaustive code (I haven,t done this in a while, the exact syntax may be a bit flawed):

Code: Select all

[not]
    [filter_wml]
        [status]
            not_living="yes"
        [/status]
    [/filter_wml]
[/not]
Basically, undead/mechanical/whatever races are made unaffected by plague/poison/drain/etc. via giving them the not_living status (aka. making not_living=true, or "yes")

But you could also just filter every non-living as you are doing, it's just a different way of doing it :)

And by the way I don't know why you wouldn't want to check for zombie creation in retaliation, it souldn't be too difficult to add...
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Post Reply