Experience with [harm_unit]

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

Experience with [harm_unit]

Post by siddh »

Hello I have a problem with an ability that uses [harm_unit] inside an event. The ability itself works fine. [Harm_unit] works fine. But there's a problem related to experience, and the default "experience=yes/no" boolean operator isn't sufficient to cover this. I think it can be done one way or another, but I can't figure out how to exactly.

Essentially I have an ability which does extra damage per each hit from an attack. However if I allow experience gain from the [harm_unit] then it means both sides will gain experience from every hit. But it does also mean that if the target dies because of the [harm_unit] then experience is given properly. If i disable experience, then no experience is given if the harm_unit kills the target. So the problem is specifically that the unit needs to get XP when the target dies. (The default experience=yes doesnt work because it results to ie. 4hits = total 5 experience points for an attack)

Here's an example of the ability. I have several abilities which use the same structure. It was made with help from others.

Code: Select all

#define WEAPON_SPECIAL_DRACONIAN_FROST TYPE
     [dummy]
        id="draconian_frost_{TYPE}"
        name= _ "Frost"
        description= _ "This attack has a 75 prcnt chance to deal additional cold damage to the target on every hit."
    [/dummy]
[/specials]
[/attack]
[event]
id=draconian_frost_{TYPE}
name=attacker_hits
first_time_only=no
[filter_attack]
special=draconian_frost_{TYPE}
[/filter_attack]
[filter_second]
[/filter_second]
	[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=5
	damage_type=cold
	fire_event=yes
	experience=yes
	[/harm_unit]
[/event]
[event]
id=draconian_frost_{TYPE}
name=defender_hits
first_time_only=no
[filter_second_attack]
special=draconian_frost_{TYPE}
[/filter_second_attack]
[filter]
[/filter]
	[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=5
	damage_type=cold
	fire_event=yes
	experience=yes
	[/harm_unit]
[/event]
[+attack]
[+specials]
#enddef
I'm thinking that you could somehow compare the amount of damage harm_unit is gonna do with the target's hitpoints, and then award experience with something like {VARIABLE.. This way you could set the default experience=no. Another way would be to set experience=yes and then deduct from the xp of both sides the number of attacks multiplied with each sides level. However I don't know how to do either of things, and so I am unable to resolve the problem.

Any ideas? :)

PS. The description talks about 75% chance but that is currently not implemented
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Experience with [harm_unit]

Post by Dugi »

I am dealing with this problem by checking if the unit would survive the hit, if it would survive, harm_unit is used with experience=no, if it would not, it's used with experience=yes.
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: Experience with [harm_unit]

Post by siddh »

Alright I tried doing what Dugi suggested, thanks for the tip btw, but couldn't get it to work.

Basically once I added this if, then, else routine, teh ability stopped working entirely. Now when the defender hits, it doesnt work at all, but works when the attacker hits ( but xp is all over the place )

Here's what I got

Code: Select all

#define WEAPON_SPECIAL_DRACONIAN_FROST DAMG TYPE
     [dummy]
        id="draconian_frost_{DAMG}_{TYPE}"
        name= _ "Frost"
        description= _ "This attack has a 75 prcnt chance to deal additional {DAMG} cold damage to the target on every hit."
    [/dummy]
[/specials]
[/attack]
[event]
id=draconian_frost_{DAMG}_{TYPE}
name=attacker_hits
first_time_only=no
[filter_attack]
	special=draconian_frost_{DAMG}_{TYPE}
[/filter_attack]
[filter_second]
[/filter_second]
	[if]
		[variable]
		name=second_unit.variables.hitpoints
		greater_than_equal_to={DAMG}
		[/variable]
		[then]
			[harm_unit]
				[filter]
					x,y=$x2,$y2
				[/filter]
				[filter_second]
					x,y=$x1,$y1
				[/filter_second]
			amount={DAMG}
			damage_type=cold
			fire_event=yes
			experience=no
			[/harm_unit]
		[/then]
		[else]
			[harm_unit]
				[filter]
					x,y=$x2,$y2
				[/filter]
				[filter_second]
					x,y=$x1,$y1
				[/filter_second]
			amount={DAMG}
			damage_type=cold
			fire_event=yes
			experience=yes
			[/harm_unit]
		[/else]
	[/if]
[/event]
[event]
id=draconian_frost_{DAMG}_{TYPE}
name=defender_hits
first_time_only=no
[filter_second_attack]
	special=draconian_frost_{DAMG}_{TYPE}
[/filter_second_attack]
[filter]
[/filter]
	[if]
		[variable]
		name=unit.variables.hitpoints
		greater_than_equal_to={DAMG}
		[/variable]
		[then]
			[harm_unit]
				[filter]
					x,y=$x1,$y1
				[/filter]
				[filter_second]
					x,y=$x2,$y2
				[/filter_second]
			amount={DAMG}
			damage_type=cold
			fire_event=yes
			experience=no
			[/harm_unit]
		[/then]
		[else]
			[harm_unit]
				[filter]
					x,y=$x1,$y1
				[/filter]
				[filter_second]
					x,y=$x2,$y2
				[/filter_second]
			amount={DAMG}
			damage_type=cold
			fire_event=yes
			experience=yes
			[/harm_unit]
		[/else]
	[/if]
[/event]
[+attack]
[+specials]
#enddef
Any ideas? :D

PS. I dont know how to check for the resistance in addition to hitpoints, but since the ability no longer works it's not priority atm :D

PPS. Also I fixed teh event ID problem which was remnant from downloading the era from incorrect add-on server (I didnt have a backup of the latest version when starting to work again, but the actual version would've been on the obsolete server.. So there were some bugs which I had fixed, but werent fixed on the version, but didnt realize that.... anyway the [if] hitpoint check thing doesnt work. Any ideas?)
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Experience with [harm_unit]

Post by Dugi »

What is second_unit.variables.hitpoints supposed to mean? Are saving a variable named hitpoints into the unit?

Use the :inspect debug command to see how is the data arranged within a unit. You'll see that you should check the second_unit.hitpoints variable instead.

And be careful to replace both occurrences of that mistake.
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: Experience with [harm_unit]

Post by siddh »

myea I asked zookeeper and he said:
[11:35:16] <zookeeper> name=unitvariable.hitpoints greater_than_equal_to=1
so I tried unit.variables.hitpoints and unitvariable.hitpoints but neither worked

Thanks dude I just spent several hours on this.. And was getting a little irritated. :D

Ps. Also thanks for the tip about usin the inspect command, this should make things easier in the future as well :D
Last edited by siddh on March 19th, 2014, 1:53 pm, edited 1 time in total.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Experience with [harm_unit]

Post by Dugi »

Not sure what he meant by that, but unit.variables.hitpoints is very unlikely to be the solution. Also, I recommend you using the resistances.

This chunk of code should do what you want, I've copied most of it from my campaign's code and it was working there.

Code: Select all

        [if]
            [variable]
                name=second_unit.hitpoints
                less_than="$({DAMG}*$($second_unit.resistance.{TYPE})/100)"
            [/variable]
            [then]
                [harm_unit]
                    [filter]
                        x,y=$x2,$y2
                    [/filter]
                    [filter_second]
                        x,y=$x1,$y1
                    [/filter_second]
                    amount={DAMG}
                    damage_type={TYPE}
                    fire_event=yes
                    experience=yes
                    kill=yes
                    animate=no
                [/harm_unit]
            [/then]
            [else]
                [harm_unit]
                    [filter]
                        x,y=$x2,$y2
                    [/filter]
                    [filter_second]
                        x,y=$x1,$y1
                    [/filter_second]
                    amount={DAMG}
                    damage_type={TYPE}
                    fire_event=yes
                    experience=no
                    kill=yes
                    animate=no
                [/harm_unit]
            [/else]
        [/if]
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Experience with [harm_unit]

Post by pyrophorus »

siddh wrote:Alright I tried doing what Dugi suggested, thanks for the tip btw, but couldn't get it to work.

Code: Select all

[event]
...	[if]
		[variable]
		name=second_unit.variables.hitpoints

# should be name=second_unit.hitpoints
HTH
siddh
Posts: 192
Joined: August 30th, 2009, 5:54 pm

Re: Experience with [harm_unit]

Post by siddh »

Alright the issue is mostly resolved. What zookeeper meant was that I should've realized myself that I should replace "unitvariable" with whatever variable the unit is stored in. But I didn't realize that and so that's how it went wrong.. In the meantime I tried fixing this to include resistances, which got very complicated. I think it should work for the most part, here's a couple of examples:

Code: Select all

#define ABILITY_DRACONIAN_SHADOW_AURA TYPE
    [dummy]
        id="draconian_shadow_aura_{TYPE}"
        name= _ "Shadow Aura"
        description= _ "Whenever this unit is hit in melee combat, attacker takes shadow damage."
    [/dummy]
[/abilities]
[event]
id=draconian_shadow_aura_attacker
name=attacker_hits
first_time_only=no
[filter_attack]
range=melee
[/filter_attack]
[filter_second]
ability=draconian_shadow_aura_{TYPE}
[/filter_second]
	[set_variable]
		name=testvar2
		round=0
		value="$($unit.resistance.shadow*0.01*3)"
		[/set_variable]
		[if]
        [variable]
        name=unit.hitpoints
        greater_than_equal_to=$testvar2
        [/variable]
        [then]
	[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=3
	damage_type=shadow
	fire_event=yes
	experience=no
	[/harm_unit]
	    [/then]
		[else]
			[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=3
	damage_type=shadow
	fire_event=yes
	experience=yes
	[/harm_unit]
		[/else]
		[/if]
		{CLEAR_VARIABLE testvar2}
[/event]
[event]
id=draconian_shadow_aura_defender
name=defender_hits
first_time_only=no
[filter_second_attack]
[/filter_second_attack]
[filter]
ability=draconian_shadow_aura_{TYPE}
[/filter]
	[set_variable]
		name=testvar
		round=0
		value="$($second_unit.resistance.shadow*0.01*3)"
		[/set_variable]
		[if]
        [variable]
        name=second_unit.hitpoints
        greater_than_equal_to=$testvar
        [/variable]
        [then]
	[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=3
	damage_type=shadow
	fire_event=yes
	experience=no
	[/harm_unit]
		    [/then]
		[else]
			[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=3
	damage_type=shadow
	fire_event=yes
	experience=yes
	[/harm_unit]
			[/else]
		[/if]
		{CLEAR_VARIABLE testvar2}
[/event]
[+abilities]
#enddef

Code: Select all

#define WEAPON_SPECIAL_DRACONIAN_CRUSH TYPE
     [dummy]
        id="draconian_crush_{TYPE}"
        name= _ "Crush"
        description= _ "This attack deals additional 5 impact damage on each hit."
    [/dummy]
[/specials]
[/attack]
[event]
name=attacker_hits
first_time_only=no
[filter_attack]
special=draconian_crush_{TYPE}
[/filter_attack]
[filter_second]
[/filter_second]
		[set_variable]
		name=testvar
		round=0
		value="$($second_unit.resistance.impact*0.01*5)"
		[/set_variable]
		[if]
        [variable]
        name=second_unit.hitpoints
        greater_than_equal_to=$testvar
        [/variable]
        [then]
	[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=5
	damage_type=impact
	fire_event=yes
	experience=no
	[/harm_unit]
		[/then]
		[else]
	[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=5
	damage_type=impact
	fire_event=yes
	experience=yes
	[/harm_unit]
		[/else]
		[/if]
	    {CLEAR_VARIABLE testvar}

[/event]
[event]
name=defender_hits
first_time_only=no
[filter_second_attack]
special=draconian_crush_{TYPE}
[/filter_second_attack]
[filter]
[/filter]
		[set_variable]
		name=testvar2
		round=0
		value="$($unit.resistance.impact*0.01*5)"
		[/set_variable]
		[if]
        [variable]
        name=unit.hitpoints
        greater_than_equal_to=$testvar2
        [/variable]
        [then]
	[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=5
	damage_type=impact
	fire_event=yes
	experience=no
	[/harm_unit]
		[/then]
		[else]
	[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=5
	damage_type=impact
	fire_event=yes
	experience=yes
	[/harm_unit]
		[/else]
		[/if]
	    {CLEAR_VARIABLE testvar2}

[/event]
[+attack]
[+specials]
#enddef

Code: Select all

#define WEAPON_SPECIAL_DRACONIAN_ELECTROCUTE TYPE
     [dummy]
        id="draconian_electrocute_{TYPE}"
        name= _ "Electrocute"
        description= _ "This attack has a 66 percent chance to deal additional lightning damage to the target on every hit."
    [/dummy]
[/specials]
[/attack]
[event]
id=draconian_electrocute
name=attacker_hits
first_time_only=no
[filter_attack]
special=draconian_electrocute_{TYPE}
[/filter_attack]
[filter_second]
[/filter_second]
   {VARIABLE_OP electrocute_chance rand(0,1,2)}
   [if]
       [variable]
       name=electrocute_chance
       greater_than_equal_to=1
       [/variable]
	   [then]
	   	[set_variable]
		name=testvar
		round=0
		value="$($second_unit.resistance.lightning*0.01*6)"
		[/set_variable]
		[if]
        [variable]
        name=second_unit.hitpoints
        greater_than_equal_to=$testvar
        [/variable]
        [then]
	[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=6
	damage_type=lightning
	fire_event=yes
	experience=no
	[/harm_unit]
		[/then]
		[else]
	[harm_unit]
	[filter]
	x,y=$x2,$y2
	[/filter]
	[filter_second]
	x,y=$x1,$y1
	[/filter_second]
	amount=6
	damage_type=lightning
	fire_event=yes
	experience=yes
	[/harm_unit]
		[/else]
		[/if]
	    {CLEAR_VARIABLE testvar}

		[/then]
	[/if]
[/event]
[event]
id=draconian_electrocute_defender
name=defender_hits
first_time_only=no
[filter_second_attack]
special=draconian_electrocute_{TYPE}
[/filter_second_attack]
[filter]
[/filter]
   {VARIABLE_OP electrocute_chance rand(0,1,2)}
   [if]
       [variable]
        name=electrocute_chance
		greater_than_equal_to=1
       [/variable]
	   [then]
	   	[set_variable]
		name=testvar2
		round=0
		value="$($unit.resistance.lightning*0.01*6)"
		[/set_variable]
		[if]
        [variable]
        name=unit.hitpoints
        greater_than_equal_to=$testvar2
        [/variable]
        [then]
	[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=6
	damage_type=lightning
	fire_event=yes
	experience=no
	[/harm_unit]
		[/then]
		[else]
	[harm_unit]
	[filter]
	x,y=$x1,$y1
	[/filter]
	[filter_second]
	x,y=$x2,$y2
	[/filter_second]
	amount=6
	damage_type=lightning
	fire_event=yes
	experience=yes
	[/harm_unit]
		[/else]
		[/if]
	    {CLEAR_VARIABLE testvar2}

		[/then]
	[/if]
[/event]
[+attack]
[+specials]
#enddef

Code: Select all

#define WEAPON_SPECIAL_DRACONIAN_FROST DAMG TYPE
     [dummy]
        id="draconian_frost_{DAMG}_{TYPE}"
        name= _ "Frost"
        description= _ "This attack has a 75 percent chance to deal additional cold damage to the target on every hit."
    [/dummy]
[/specials]
[/attack]
[event]
id=draconian_frost
name=attacker_hits
first_time_only=no
[filter_attack]
special=draconian_frost_{DAMG}_{TYPE}
[/filter_attack]
[filter_second]
[/filter_second]
   {VARIABLE_OP frost_chance rand (0,1,2,3)}
   [if]
		[variable]
		name=frost_chance
		greater_than_equal_to=1
		[/variable]
		[then]
		[set_variable]
		name=testvar2
		round=0
		value="$($second_unit.resistance.cold*0.01*{DAMG})"
		[/set_variable]
		[if]
        [variable]
        name=second_unit.hitpoints
        greater_than_equal_to=$testvar2
        [/variable]
        [then]
			[harm_unit]
			[filter]
			x,y=$x2,$y2
			[/filter]
			[filter_second]
			x,y=$x1,$y1
			[/filter_second]
			amount={DAMG}
			damage_type=cold
			fire_event=yes
			experience=no
			[/harm_unit]
		[/then]
		[else]
			[harm_unit]
			[filter]
			x,y=$x2,$y2
			[/filter]
			[filter_second]
			x,y=$x1,$y1
			[/filter_second]
			amount={DAMG}
			damage_type=cold
			fire_event=yes
			experience=yes
			[/harm_unit]
		[/else]
		[/if]
	[/then]
	{CLEAR_VARIABLE testvar2}
	[/if]
	{CLEAR_VARIABLE frost_chance}
[/event]
[event]
id=draconian_frost_defender
name=defender_hits
first_time_only=no
[filter_second_attack]
special=draconian_frost_{DAMG}_{TYPE}
[/filter_second_attack]
[filter]
[/filter]
   {VARIABLE_OP frost_chance rand (0,1,2,3)}
   [if]
		[variable]
		name=frost_chance
		greater_than_equal_to=1
		[/variable]
		[then]
		[set_variable]
		name=testvar
		round=0
		value="$($unit.resistance.cold*0.01*{DAMG})"
		[/set_variable]
			[if]
				[variable]
				name=unit.hitpoints
				greater_than_equal_to=$testvar
				[/variable]
					[then]
					[harm_unit]
					[filter]
					x,y=$x1,$y1
					[/filter]
					[filter_second]
					x,y=$x2,$y2
					[/filter_second]
					amount={DAMG}
					damage_type=cold
					fire_event=yes
					experience=no
					[/harm_unit]
				[/then]
				[else]
					[harm_unit]
					[filter]
					x,y=$x1,$y1
					[/filter]
					[filter_second]
					x,y=$x2,$y2
					[/filter_second]
					amount={DAMG}
					damage_type=cold
					fire_event=yes
					experience=yes
					[/harm_unit]
				[/else]
			[/if]
		[/then]
	{CLEAR_VARIABLE testvar2}
	[/if]
	{CLEAR_VARIABLE frost_chance}
[/event]
[+attack]
[+specials]
#enddef
Post Reply