If unit Advances, all adjacent units gain experience
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.
If unit Advances, all adjacent units gain experience
I would like to have a unit event that if unit X levels, all units adjacent to unit X gain 1 exp. After spending an hour attempting. I am asking for help. I would like to do this with event name=advance or post advance, but any code that pulls this off is fine.
Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
Re: If unit Advances, all adjacent units gain experience
i havent tried if it works, so let me know if it doesnt:
it could not need these [if] blabla, but filters are often too complicated, i just woke up so i didn't want to mess with it... there is chance you could add something like [not] x=$unit.x y=$unit.y [/not] and it might have worked but i rather not give u risky solution..
Code: Select all
[event]
name=advance
first_time_only=no
[store_unit]
[filter]
x,y=$unit.x,$unit.y
ability=experience_giver ## replace it with your ability or unit id or whatever.. or you can add filter to advance event instead... so not every advancing unit gives surrounding units 1 xp
[filter_location]
[filter]
side=$unit.side
[/filter]
radius=1
[/filter_location]
[/filter]
variable=adjacent_units_array
[/store_unit]
{FOREACH adjacent_units_array counter_i}
[if]
[variable]
name=adjacent_units_array[$counter_i].x
not_equals=$unit.x
[/variable]
[and]
[variable]
name=adjacent_units_array[$counter_i].y
not_equals=$unit.y
[/variable]
[/and]
{VARIABLE_OP adjacent_units_array[$counter_i].experience add 1}
[unstore_unit]
variable=adjacent_units_array[$counter_i]
[/unstore_unit]
{NEXT counter_i}
[/event]
Re: If unit Advances, all adjacent units gain experience
Neither set of code works. In all tests I placed two units with the same event code next to each other and got one to level. For both peoples suggestions I tried #removing all filters in order to rule that out. Notes and code are below.
Code: Select all
[event]
#tried pre advance, advance, and post advance triggers, all not working, all of them were attempted with all filters removed so all units should be affected, none were.
name=advance
first_time_only=no
id=BGE_massdrop
# select all friendly units that are adjacent to the advancing unit that have 1 max exp
[filter_second]
[filter_adjacent]
#max_experience=1
is_enemy=no
[/filter_adjacent]
[/filter_second]
[modify_unit]
[filter]
#[not]
# id=$second_unit.id
#[/not]
[filter_adjacent]
is_enemy=no
#max_experience=1
[filter_adjacent]
is_enemy=no
id=$second_unit.id
[/filter_adjacent]
[/filter_adjacent]
[/filter]
experience="$($this_unit.experience + 1)"
[/modify_unit]
[/event]
Code: Select all
[event]
#code not working after fixing if statements, removing all filters so all units are affected, also tried with pre advance and post advance triggers, nothing works.
name=advance
first_time_only=no
[store_unit]
[filter]
x,y=$unit.x,$unit.y
#max_experience=1
[filter_location]
[filter]
side=$unit.side
[/filter]
radius=1
[/filter_location]
[/filter]
variable=adjacent_units_array
[/store_unit]
{FOREACH adjacent_units_array counter_i}
[if]
[variable]
name=adjacent_units_array[$counter_i].x
not_equals=$unit.x
[/variable]
[and]
[variable]
name=adjacent_units_array[$counter_i].y
not_equals=$unit.y
[/variable]
[/and]
[then]
{VARIABLE_OP adjacent_units_array[$counter_i].experience add 1}
[unstore_unit]
variable=adjacent_units_array[$counter_i]
[/unstore_unit]
[/then]
[/if]
{NEXT counter_i}
[/event]
Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: If unit Advances, all adjacent units gain experience
This is much easier than you guys are making it.
Code: Select all
[event]
name=advance
[filter]
# filter for unit X here
[/filter]
first_time_only=no
[modify_unit]
[filter]
# Finds teammates with with the advancing unit next to them.
side=$unit.side
[filter_adjacent]
id=$unit.id
[/filter_adjacent]
[/filter]
experience="$($this_unit.experience + 1)"
[/modify_unit]
[/event]
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: If unit Advances, all adjacent units gain experience
The following code is working. Thank you. Because all units I want to be triggered by this have a max of 1 experience, I used this as the filter. The chain reactions were great. Only thing I had to change from your code was changing the 'advance' trigger to 'post advance'. If the advance trigger is used, then the game gets stuck in an endless loop that requires killing the wesnoth process. This is due to an "issue" in wesnoth where you users are unable to interact with the main menu while in advancement selection.
Code: Select all
[event]
name=post advance
[filter]
max_experience=1
[/filter]
first_time_only=no
[modify_unit]
[filter]
# Finds teammates with with the advancing unit next to them.
side=$unit.side
[filter_adjacent]
id=$unit.id
[/filter_adjacent]
[/filter]
experience="$($this_unit.experience + 1)"
[/modify_unit]
[/event]
Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.