Issues with giving xp in a [fire_event]

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
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Issues with giving xp in a [fire_event]

Post by LordAwsomeness »

So im attempting to create scenario where anytime players kill an enemy unit, all of the teammates receive bonus xp. The idea behind it is that players level up and essentially receive skill points to spend on abilities. I felt there was a balance issue with turn order having the first player generally rack up a vast majority of the xp since units are able to attack multiple times in one turn and if you kill an enemy unit, the killer unit is able to get some movement points back as well as yet another attack.
To combat this issue I wanted to just share xp. So I created an event to fire every time an enemy unit is slain at the hands of a player. the event below is a pillaged and modified version of a macro from the brotherhood of light (thank you bob <3 ). essentially I want to give xp to all of the teammates every time one of them gets a kill. The event is somewhat working as it gives xp to all teammates, however for some reason it is not giving only the designated amount of xp to players that I want... it keeps giving triple the amount of xp that I want to give for whatever reason. Can somebody look through this code and figure out what is causing this issue to happen?

Code: Select all

[event]
name=give_xp
first_time_only=no

#set the initial xp to test. once the testing is done, the xp is going to be set in the killing event.
{VARIABLE xp 1}

  [store_unit]
        [filter]
            side=$la_player_sides
            canrecruit=yes
        [/filter]
        kill=no
        variable=la_xp
    [/store_unit]

    {FOREACH la_xp q}
        {VARIABLE_OP la_xp[$q].experience add $xp}

        [unstore_unit]
            variable=la_xp[$q]
            find_vacant=no
            text=_"+$xp XP"
			red,green,blue=255,255,255
            advance=yes
        [/unstore_unit]
		#want to negate the killer from getting double xp...
        {VARIABLE_OP killer2.experience add -$xp}
	[unstore_unit]
		variable=killer2
	[/unstore_unit]
        [if]
            [have_unit]
                x,y=$la_xp[$q].x,$la_xp[$q].y
                
                [filter_wml]
                    experience=$la_xp[$q].experience
                [/filter_wml]
            [/have_unit]
            
            [else]
                [fire_event]
                    name=post_advance
                    [primary_unit]
                        x,y=$la_xp[$q].x,$la_xp[$q].y
                    [/primary_unit]
                [/fire_event]
            [/else]
        [/if]
    {NEXT q}

    {CLEAR_VARIABLE la_xp}
    {CLEAR_VARIABLE killer2}
[/event]
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Issues with giving xp in a [fire_event]

Post by LordAwsomeness »

nevermind I just coded it into my event where the unit gets killed and the bug stopped.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Issues with giving xp in a [fire_event]

Post by octalot »

Is there any chance that you've got three copies of this event? As in, is it in a macro?

BTW, the [for] and [foreach] loops are simpler than using the older {FOREACH} macro. It looks like you unstore the killer2 unit multiple times (once for each time through the loop).
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Issues with giving xp in a [fire_event]

Post by LordAwsomeness »

octalot wrote: October 16th, 2019, 3:38 pm Is there any chance that you've got three copies of this event? As in, is it in a macro?
so I actually do need this specific macro to work. I updated it to the [foreach] syntax and it was still an issue oddly enough. dont have 3 copies in the macro but it is still strange how it is adding more. seems weird but the bug gets even weirder as I go through the customize hero menus and develop the characters in game. it then always seems to add +1 for every activated hero. but I dont see any variables or macros that should do that. maybe it is repeating it improperly according to how many players that are activated.. by why is it being affected by how many commanders have been activated? none of the variables are reliant on the commander being customized. it still fires for them when they are inactivated so it is odd that it adds more for each one active.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Issues with giving xp in a [fire_event]

Post by LordAwsomeness »

octalot wrote: October 16th, 2019, 3:38 pm BTW, the [for] and [foreach] loops are simpler than using the older {FOREACH} macro. It looks like you unstore the killer2 unit multiple times (once for each time through the loop).
this is the new code im running. it gives xp to them all but still does the bug...

Code: Select all

[event]
name=give_xp
first_time_only=no



			[store_unit]
				[filter]
					side=$la_player_sides
					canrecruit=yes
				[/filter]
				variable=killers
			[/store_unit]

[foreach]
array=killers
[do]

		{VARIABLE_OP this_item.experience add $xp}
		
#		{VARIABLE_OP this_item add -1}
			[unstore_unit]
				variable=this_item
				text="+$xp XP"
				red,green,blue=255,255,255
				advance=yes
			[/unstore_unit]
		[if]
            [have_unit]
                x,y=$this_item.x,$this_item.y
                
                [filter_wml]
                    experience=$this_item.experience
                [/filter_wml]
            [/have_unit]
            
            [else]
                [fire_event]
                    name=post_advance
                    [primary_unit]
                        x,y=$this_item.x,$this_item.y
                    [/primary_unit]
                [/fire_event]
            [/else]
        [/if]
[/do]
[/foreach]
#			{CLEAR_VARIABLE killers}
[/event]
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Issues with giving xp in a [fire_event]

Post by LordAwsomeness »

Ravana wrote: October 16th, 2019, 3:41 pm Sounds like the example https://wiki.wesnoth.org/EventWML#A_Trap_for_the_Unwary
wow that is so strange. the event id was all I needed... after adding an event id it started working as I initially anticipated. I dont understand how that bug was coming up though because I didn't have multiple of the same event. that is so weird.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
Celtic_Minstrel
Developer
Posts: 2214
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Issues with giving xp in a [fire_event]

Post by Celtic_Minstrel »

LordAwsomeness wrote: October 16th, 2019, 5:32 pm
octalot wrote: October 16th, 2019, 3:38 pm Is there any chance that you've got three copies of this event? As in, is it in a macro?
so I actually do need this specific macro to work. I updated it to the [foreach] syntax and it was still an issue oddly enough. dont have 3 copies in the macro but it is still strange how it is adding more. seems weird but the bug gets even weirder as I go through the customize hero menus and develop the characters in game. it then always seems to add +1 for every activated hero. but I dont see any variables or macros that should do that. maybe it is repeating it improperly according to how many players that are activated.. by why is it being affected by how many commanders have been activated? none of the variables are reliant on the commander being customized. it still fires for them when they are inactivated so it is odd that it adds more for each one active.
Just for the record, the simplest replacement for {FOREACH} is [for], not [foreach] - with [for], you basically don't have to change any of the code inside the loop. I'm not sure how relevant this is now though…
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Issues with giving xp in a [fire_event]

Post by LordAwsomeness »

Celtic_Minstrel wrote: October 21st, 2019, 12:04 am
LordAwsomeness wrote: October 16th, 2019, 5:32 pm
octalot wrote: October 16th, 2019, 3:38 pm Is there any chance that you've got three copies of this event? As in, is it in a macro?
so I actually do need this specific macro to work. I updated it to the [foreach] syntax and it was still an issue oddly enough. dont have 3 copies in the macro but it is still strange how it is adding more. seems weird but the bug gets even weirder as I go through the customize hero menus and develop the characters in game. it then always seems to add +1 for every activated hero. but I dont see any variables or macros that should do that. maybe it is repeating it improperly according to how many players that are activated.. by why is it being affected by how many commanders have been activated? none of the variables are reliant on the commander being customized. it still fires for them when they are inactivated so it is odd that it adds more for each one active.
Just for the record, the simplest replacement for {FOREACH} is [for], not [foreach] - with `[for]`, you basically don't have to change any of the code inside the loop. I'm not sure how relevant this is now though…

no worries! Thank you!
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Post Reply