fire event in teleport
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.
- hermestrismi
- Posts: 632
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
fire event in teleport
Hi,
Is there a way to fire an event when a unit teleport?
something like:
Is there a way to fire an event when a unit teleport?
something like:
Code: Select all
[event]
name=teleport
...
[/event]
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
Re: fire event in teleport
Add [fire_event]name=teleport[/fire_event] after you teleport units. If you mean ability then enter hex should work.
- hermestrismi
- Posts: 632
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: fire event in teleport
I mean fire event AFTER the specified unit teleport (precisely harm a specific unit whenever it use teleportation)
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
-
- Posts: 1282
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: fire event in teleport
Have you looked at unit_placed? It seems to be a bit of a last restort, but you should be able to make it work.
[I assume you mean fire event after unit uses the teleport ability, not [teleport] ]
[I assume you mean fire event after unit uses the teleport ability, not [teleport] ]
Speak softly, and carry Doombringer.
- hermestrismi
- Posts: 632
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: fire event in teleport
yes. as I mentioned before, I am trying to make an event that fire after a unit uses the teleport ability.white_haired_uncle wrote: ↑May 7th, 2024, 3:17 pm Have you looked at unit_placed? It seems to be a bit of a last restort, but you should be able to make it work.
[I assume you mean fire event after unit uses the teleport ability, not [teleport] ]
a workaround came to mind is to store both the exit hex and the entered hex then comparing the distance (+- the unit movement points)...
but:
1. I don't know if this will work flawlessly,
2. I need a way to calculate distance instead of using x and y alone ,
3. it is not a beautiful way anyway.
I locked also to the teleport related files in wml and lua but no idea came to mind...
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- Spannerbag
- Posts: 553
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: fire event in teleport
Hi,
Your post intrigued me so I had a bit of a play, building on the suggestion by Ravana.
This code isn't perfect, it might need
Anyway, it should at least give you a starting point.
I assumed you'd be using
I also assumed you'd want to avoid lua if possible.
The
Here's my 'orrible hack code:
As I must repeat I have only minuimally tested this with a Silver Mage and a Spearman, in particular this will also affect/process AI controlled units which may or may not be the desired behaviour.
Anyway, hope it helps, good luck... and if you do get it working I'd appreciate a copy of your polished code, I might also find a use for it.
Cheers!
-- Spannerbag
Your post intrigued me so I had a bit of a play, building on the suggestion by Ravana.
This code isn't perfect, it might need
[allow_undo]
or maybe [cancel_action]
but from my limited testing it does seem to trap teleports and filter out non-teleport movement.Anyway, it should at least give you a starting point.
I assumed you'd be using
{ABILITY_TELEPORT}
.I also assumed you'd want to avoid lua if possible.
The
[filter]
for which unit(s) are considered teleport-capable (ability_id_active=teleport
) can be changed (e.g. to type=Silver Mage
) depending on circumstance.Here's my 'orrible hack code:
Code: Select all
# --- DEBUG: SETUP TEST CONDITIONS ---
[event]
name=side 1 turn 1
[terrain]
x=8,8,10,11,12
y=8,9, 7,11,11
terrain=*^Vh
layer=overlay
[/terrain]
[capture_village]
side=1
x=8,8,10,11
y=8,9, 7,11
[/capture_village]
{GENERIC_UNIT 1 (Silver Mage) 7 7}
{DEBUG_MSG (_"Done")}
[/event]
# --- TELEPORT DETECT EVENTS (DEBUG VERSIONS) ---
# Teleport setup
# Setup when teleport capable unit enters village
# (i.e. do not yet know if unit will actually teleport or not)
[event]
name=enter_hex
first_time_only=no
[filter]
x,y=$x1,$y1
ability_id_active=teleport # Always active; excludes units without {ABILITY_TELEPORT}
[filter_location]
terrain=*^V* # Unit entered a village
[/filter_location]
[/filter]
[filter_condition]
{VARIABLE_CONDITIONAL unit.variables.tpt_x numerical_equals 0}
[/filter_condition]
[modify_unit]
[filter]
id=$unit.id
[/filter]
{VARIABLE tpt_x $x1}
{VARIABLE tpt_y $y1}
[/modify_unit]
{DEBUG_MSG (_"Enter hex fired, unit stored x,y")}
[/event]
#
# Teleport teardown (unit moved to adjacent hex)
# Unit did not teleport
[event]
name=exit_hex
first_time_only=no
[filter]
x,y=$x1,$y1
ability_id_active=teleport # Always active; excludes units without {ABILITY_TELEPORT}
[/filter]
[filter_condition]
{VARIABLE_CONDITIONAL unit.variables.tpt_x greater_than 0}
[have_location]
x,y=$x2,$y2
[filter_adjacent_location] # Unit moved 1 hex (i.e. did not teleport, includes adjacent village)
x,y=$x1,$y1
[/filter_adjacent_location]
[/have_location]
[/filter_condition]
[modify_unit]
[filter]
id=$unit.id
[/filter]
{CLEAR_VARIABLE tpt_x,tpt_y}
[/modify_unit]
{DEBUG_MSG (_"Exit hex no_teleport fired, cleared unit stored x,y")}
[/event]
#
# Teleport capture (unit moved to non-adjacent hex)
# Unit did teleport
[event]
name=enter_hex
first_time_only=no
[filter]
x,y=$x1,$y1
ability_id_active=teleport # Always active; excludes units without {ABILITY_TELEPORT}
[/filter]
[filter_condition]
{VARIABLE_CONDITIONAL unit.variables.tpt_x greater_than 0}
[have_location]
x,y=$x2,$y2
[filter_adjacent_location] # Unit moved >1 hex (i.e. did teleport)
x,y=$x1,$y1
count=0
[/filter_adjacent_location]
[/have_location]
[/filter_condition]
# [modify_unit]
# [filter]
# id=$unit.id
# [/filter]
# {CLEAR_VARIABLE tpt_x,tpt_y}
# [/modify_unit]
{DEBUG_MSG (_"Enter hex ***teleport*** fired")}
[/event]
Anyway, hope it helps, good luck... and if you do get it working I'd appreciate a copy of your polished code, I might also find a use for it.
Cheers!
-- Spannerbag
- hermestrismi
- Posts: 632
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: fire event in teleport
Thank you very much.Spannerbag wrote: ↑May 8th, 2024, 1:47 pm Hi,
Your post intrigued me so I had a bit of a play, building on the suggestion by Ravana.
This code isn't perfect, it might need[allow_undo]
or maybe[cancel_action]
but from my limited testing it does seem to trap teleports and filter out non-teleport movement.
Anyway, it should at least give you a starting point.
I assumed you'd be using{ABILITY_TELEPORT}
.
I also assumed you'd want to avoid lua if possible.
The[filter]
for which unit(s) are considered teleport-capable (ability_id_active=teleport
) can be changed (e.g. totype=Silver Mage
) depending on circumstance.
Here's my 'orrible hack code:
As I must repeat I have only minuimally tested this with a Silver Mage and a Spearman, in particular this will also affect/process AI controlled units which may or may not be the desired behaviour.Code: Select all
# --- DEBUG: SETUP TEST CONDITIONS --- [event] name=side 1 turn 1 [terrain] x=8,8,10,11,12 y=8,9, 7,11,11 terrain=*^Vh layer=overlay [/terrain] [capture_village] side=1 x=8,8,10,11 y=8,9, 7,11 [/capture_village] {GENERIC_UNIT 1 (Silver Mage) 7 7} {DEBUG_MSG (_"Done")} [/event] # --- TELEPORT DETECT EVENTS (DEBUG VERSIONS) --- # Teleport setup # Setup when teleport capable unit enters village # (i.e. do not yet know if unit will actually teleport or not) [event] name=enter_hex first_time_only=no [filter] x,y=$x1,$y1 ability_id_active=teleport # Always active; excludes units without {ABILITY_TELEPORT} [filter_location] terrain=*^V* # Unit entered a village [/filter_location] [/filter] [filter_condition] {VARIABLE_CONDITIONAL unit.variables.tpt_x numerical_equals 0} [/filter_condition] [modify_unit] [filter] id=$unit.id [/filter] {VARIABLE tpt_x $x1} {VARIABLE tpt_y $y1} [/modify_unit] {DEBUG_MSG (_"Enter hex fired, unit stored x,y")} [/event] # # Teleport teardown (unit moved to adjacent hex) # Unit did not teleport [event] name=exit_hex first_time_only=no [filter] x,y=$x1,$y1 ability_id_active=teleport # Always active; excludes units without {ABILITY_TELEPORT} [/filter] [filter_condition] {VARIABLE_CONDITIONAL unit.variables.tpt_x greater_than 0} [have_location] x,y=$x2,$y2 [filter_adjacent_location] # Unit moved 1 hex (i.e. did not teleport, includes adjacent village) x,y=$x1,$y1 [/filter_adjacent_location] [/have_location] [/filter_condition] [modify_unit] [filter] id=$unit.id [/filter] {CLEAR_VARIABLE tpt_x,tpt_y} [/modify_unit] {DEBUG_MSG (_"Exit hex no_teleport fired, cleared unit stored x,y")} [/event] # # Teleport capture (unit moved to non-adjacent hex) # Unit did teleport [event] name=enter_hex first_time_only=no [filter] x,y=$x1,$y1 ability_id_active=teleport # Always active; excludes units without {ABILITY_TELEPORT} [/filter] [filter_condition] {VARIABLE_CONDITIONAL unit.variables.tpt_x greater_than 0} [have_location] x,y=$x2,$y2 [filter_adjacent_location] # Unit moved >1 hex (i.e. did teleport) x,y=$x1,$y1 count=0 [/filter_adjacent_location] [/have_location] [/filter_condition] # [modify_unit] # [filter] # id=$unit.id # [/filter] # {CLEAR_VARIABLE tpt_x,tpt_y} # [/modify_unit] {DEBUG_MSG (_"Enter hex ***teleport*** fired")} [/event]
Anyway, hope it helps, good luck... and if you do get it working I'd appreciate a copy of your polished code, I might also find a use for it.
Cheers!
-- Spannerbag
this seems to be more logic and straight than my approach. I will test it as soon as possible and I will give you my result.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- Spannerbag
- Posts: 553
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: fire event in teleport
Glad to have been able to help!hermestrismi wrote: ↑May 8th, 2024, 3:55 pm Thank you very much.
this seems to be more logic and straight than my approach. I will test it as soon as possible and I will give you my result.
Cheers!
-- Spannerbag
- Celtic_Minstrel
- Developer
- Posts: 2273
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: fire event in teleport
…what? This is not a workaround. This is the most logical way to do it. A teleport ability is just a regular move where the hexes moved between are not adjacent, so enter/exit hex is the obvious way to detect a teleport. And as Spannerbag showed, it certainly works.hermestrismi wrote: ↑May 7th, 2024, 4:02 pmyes. as I mentioned before, I am trying to make an event that fire after a unit uses the teleport ability.white_haired_uncle wrote: ↑May 7th, 2024, 3:17 pm Have you looked at unit_placed? It seems to be a bit of a last restort, but you should be able to make it work.
[I assume you mean fire event after unit uses the teleport ability, not [teleport] ]
a workaround came to mind is to store both the exit hex and the entered hex then comparing the distance (+- the unit movement points)...
but:
1. I don't know if this will work flawlessly,
2. I need a way to calculate distance instead of using x and y alone ,
3. it is not a beautiful way anyway.
I locked also to the teleport related files in wml and lua but no idea came to mind...
My only complaint about Spannerbag's code is that it only catches the default teleport ability and will not detect any custom teleport abilities that you define. A starting point for fixing this would be to use
ability_type_active=teleport
instead of ability_id_active=teleport
. That's not sufficient however, as his code also relies on setting a flag when entering a teleportable terrain. I think there should be some way of doing it without setting a flag, but if you only care about default teleport, then his solution seems quite reasonable.- Spannerbag
- Posts: 553
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: fire event in teleport
Just to be clear it was one of the assumptions in my post:Celtic_Minstrel wrote: ↑May 10th, 2024, 2:00 pm My only complaint about Spannerbag's code is that it only catches the default teleport ability and will not detect any custom teleport abilities that you define. A starting point for fixing this would be to useability_type_active=teleport
instead ofability_id_active=teleport
. That's not sufficient however, as his code also relies on setting a flag when entering a teleportable terrain. I think there should be some way of doing it without setting a flag, but if you only care about default teleport, then his solution seems quite reasonable.
But yes, I take your point that generalising it to any teleport would be trivial.I assumed you'd be using{ABILITY_TELEPORT}
.
I agree with you regarding setting a flag and have thought about it a bit more.
I think this much simplified code might be the basis of a more elegant solution, in my very quick and minimal testing it seemed to work.
But it does need much more robust testing, unfortunately I'm not in a position to do that just now.
Code: Select all
# Teleport capture (unit moved to non-adjacent hex)
# Unit did teleport
[event]
name=enter_hex
first_time_only=no
[filter]
x,y=$x1,$y1
[/filter]
[filter_condition]
[have_location]
x,y=$x2,$y2
[filter_adjacent_location] # Unit moved >1 hex (i.e. did teleport)
x,y=$x1,$y1
count=0
[/filter_adjacent_location]
[/have_location]
[/filter_condition]
{DEBUG_MSG (_"Enter hex ***teleport*** fired")}
[/event]
-- Spannerbag
Re: fire event in teleport
[filter] x,y=$x1,$y1 [/filter]
Is always passing, so you can just remove that.
Is always passing, so you can just remove that.
- hermestrismi
- Posts: 632
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: fire event in teleport
you guys are just wizards. unfortunately, I didn't have time to test the suggestion but I think that it is very logical so now we can built an ability like 'weakned teleportation' that give a penalty for using teleportation or to make it like a first AMLA before another AMLA (a regular teleport ability).
I hope I will be able to test it soon.
I hope I will be able to test it soon.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- Spannerbag
- Posts: 553
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: fire event in teleport
Less is more so even better!
Must remember that, thanks.
Cheers!
-- Spannerbag
- Spannerbag
- Posts: 553
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: fire event in teleport
Just as well, the latest version is about 1/3rd the size of the first attempt!hermestrismi wrote: ↑May 10th, 2024, 11:03 pm you guys are just wizards. unfortunately, I didn't have time to test the suggestion...
Good luck with your idea!
Cheers!
-- Spannerbag