Die event modification

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
User avatar
Spannerbag
Posts: 572
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Die event modification

Post by Spannerbag »

I'm trying to do something that may be impossible :roll:

I'm posting this here first (rather than lua labs) in case it can be done in WML :)

I want to resurrect a unit immediately after it dies.
I'm testing the logic using a leader (as its death=defeat).

I have got the logic working except for the removal of the unit when the die event finishes.

I've tried using

Code: Select all

  [kill]					# Stop die event (and defeat if leader)
    x,y=$x1,$y1
    fire_event=no
    animate=no
  [/kill]
in last breath and die but when I reinstate the (healed) unit the die event fires and the unit vanishes.
Which makes sense as kill removes the unit so die has nothing to do (no unit with specified id).
So when I put the killed unit back, die kicks in again.

The logic needs to:
- work on both player and ai turn
- work without player interaction/intervention (because of previous point)
- work for more than one unit (including leaders) on the same turn
- maintain unit ids (at least for leaders and some loyals)
- cater for the fact that the resurrected unit could immediately die again, possibly on same ai turn (unit avoids dying only once)
- ideally, the animation/dialogue should be:
-- unit issues alternate last breath
-- unit heals
-- unit (at least apparently) remains on map all the time
-- gameplay continues as normal (no modified unit ids etc.)

I can think of various possibilities but they all seem complex, awkward and the combinations are too many for my little brain to accommodate :?

I don't see how any "post die" event could be crafted.

To me, the ideal solution would be in effect to allow die to fire but not remove the unit.
Would it be possible to hack die in some way to suppress unit removal or reinstate same?

For lua labs if I end up posting this there
What I'm thinking is this: could a chunk of lua code be crafted to allow the insertion of a remove=boolean tag into die?
If absent/unassigned it defaults to true (normal behaviour) but if set to no/false unit removal does not occur (but the die event still fires of course).

Not sure if this would interfere with other campaigns? I don't see that it would, but I wouldn't want to break anything...


Any thoughts/comments greatly appreciated!

Cheers,
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2379
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Die event modification

Post by Lord-Knightmare »

I want to resurrect a unit immediately after it dies.
I'm testing the logic using a leader (as its death=defeat).
I think DM's S19 had a similar code

Code: Select all


[event]
        name=last breath
        first_time_only=no
        [filter]
            id=Iliah-Malal
        [/filter]

        [message]
            speaker="Iliah-Malal"
            message=_ "The power of death is mine! When you strike me down I arise stronger than before!"
        [/message]
        {ADVANCE_UNIT (id="Iliah-Malal") ()}
    [/event]
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
octalot
General Code Maintainer
Posts: 797
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Die event modification

Post by octalot »

Have you tried just healing the unit, and not [kill]ing it in the die event?

IIRC, defeat isn't triggered by the leader dying, it's triggered by having no units with canrecruit=yes when the game isn't processing an [event]. Removing and replacing the only canrecruit=yes unit during an event is fine.
User avatar
Spannerbag
Posts: 572
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Die event modification

Post by Spannerbag »

Thanks for your reply, much appreciated.
Lord-Knightmare wrote: March 15th, 2022, 12:26 pm I think DM's S19 had a similar code

Code: Select all


[event]
        name=last breath
        first_time_only=no
        [filter]
            id=Iliah-Malal
        [/filter]

        [message]
            speaker="Iliah-Malal"
            message=_ "The power of death is mine! When you strike me down I arise stronger than before!"
        [/message]
        {ADVANCE_UNIT (id="Iliah-Malal") ()}
    [/event]
Hmm... I could try storing the unit, advancing it to itself (same type) then clobbering it with the stored version then finally healing it.
Or some other combination of same...

Thanks for the suggestion, will try it out!

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Die event modification

Post by pyrophorus »

Hi,
If I understand correctly what you want, this should work (in a die event) (at least it works for me).

Code: Select all

	# the kill action is necessary to free the unit position before creating a new one.
		# else, the new unit would be created on an adjacent hex.
			[store_unit]
				[filter]
					id=$unit.id
				[/filter]
				variable=tmp
				kill=yes
				animate=no
			[/store_unit]
			{VARIABLE tmp.moves 0}
			{VARIABLE tmp.attacks_left 0}
			{VARIABLE tmp.hitpoints $tmp.max_hitpoints} # you must restore some hitpoints to avoid unit dying again
			{VARIABLE tmp.status.poisoned no}
			{VARIABLE tmp.experience "$($tmp.experience / 2)"}
			[unstore_unit]
				variable=tmp
				x,y=$tmp.x,$tmp.y
				find_vacant=yes
			[/unstore_unit]
HTH...
User avatar
Spannerbag
Posts: 572
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Die event modification

Post by Spannerbag »

Thanks for taking the trouble to reply.
octalot wrote: March 15th, 2022, 2:46 pm Have you tried just healing the unit, and not [kill]ing it in the die event?

IIRC, defeat isn't triggered by the leader dying, it's triggered by having no units with canrecruit=yes when the game isn't processing an [event]. Removing and replacing the only canrecruit=yes unit during an event is fine.
Just tried that, unit still disappears.
FWIW I'm using :debug's kill (shift-K) to test.

The defeat issue is solved, thanks, the issue is that the healed unit disappears when the various death related events complete.

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 572
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Die event modification

Post by Spannerbag »

Hi pyrophorus,
thanks for the reply.
pyrophorus wrote: March 15th, 2022, 9:46 pm Hi,
If I understand correctly what you want, this should work (in a die event) (at least it works for me).

Code: Select all

	# the kill action is necessary to free the unit position before creating a new one.
		# else, the new unit would be created on an adjacent hex.
			[store_unit]
				[filter]
					id=$unit.id
				[/filter]
				variable=tmp
				kill=yes
				animate=no
			[/store_unit]
			{VARIABLE tmp.moves 0}
			{VARIABLE tmp.attacks_left 0}
			{VARIABLE tmp.hitpoints $tmp.max_hitpoints} # you must restore some hitpoints to avoid unit dying again
			{VARIABLE tmp.status.poisoned no}
			{VARIABLE tmp.experience "$($tmp.experience / 2)"}
			[unstore_unit]
				variable=tmp
				x,y=$tmp.x,$tmp.y
				find_vacant=yes
			[/unstore_unit]
HTH...
Tried something similar. Sadly didn't work.
The issue is (I think) that although the unit is healed it retains the same id, type etc. so die finds a matching id and removes it.

I'm happy to post the relevant code chunks if that helps?

I think I'm going to have to setup a test sling...

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 572
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Die event modification: solved (at least in test sling)

Post by Spannerbag »

Hi all,
many thanks to everyone who replied, it really is appreciated.

As octalot suggested simply healing the unit does work.
The issue was that I'd hacked about the original code so much I'd forgotten that I wasn't using [filter] but [filter_condition].
Using the former seems to work fine in my test environment so I'll try it in the scenario I'm testing.

Wish I'd spotted that 2 days ago... :augh: :augh: :augh:

Very annoyed with myself :annoyed:

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 572
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Die event modification - ps

Post by Spannerbag »

Heh, tried the very same code from my test sling in my real scenario: didn't work, same as before.
So, noting that in my test sling I had an enemy kill my leader I spawned a berserker and had that kill my test unit in the real scenario... and it worked :shock:

This means that when I was testing using debug and killing the unit "manually" (rather than getting an enemy to do so) my test would never work.
Oh well, I've learned something (if I remember it).

Again, thanks to all for your help and patience, this was driving me crazy and after several days, I can resume testing.

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Ravana
Forum Moderator
Posts: 3084
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Die event modification

Post by Ravana »

I thought it would be expected that if you use debug you can get any kind of results which have nothing to do with what would actually happen in game.

So instead of debug kill, create new unit, set old unit to 1hp.
User avatar
Spannerbag
Posts: 572
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Die event modification

Post by Spannerbag »

Hi Ravana, thanks for your post.
Ravana wrote: March 16th, 2022, 2:41 pm I thought it would be expected that if you use debug you can get any kind of results which have nothing to do with what would actually happen in game.

So instead of debug kill, create new unit, set old unit to 1hp.
Yep, I did something similar, created an enemy Dwarvish Berserker (didn't bother setting hitpoints to zero on the old unit, though usually I do where appropriate).
I'd just assumed that :debug kill would fire the same death events etc. and behave the same as if an enemy had done so.
As I say, I've learned something and won't use :debug kill except for clearing away unwanted units during testing :)

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Post Reply