Page 1 of 1

help with custom card - delayed triggers

PostPosted: 03 Nov 2016, 22:36
by nivmizzet1
I'm porting this over from the 2014 section where I originally posted it.

For some reason the first ability below (activated trigger) (1) doesn't query about drawing a card, it just draws and (2) causes the player to draw two cards instead of one.

Code: Select all
   <ACTIVATED_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[{2}{G}{B}: The next time this source would deal damage to an opponent this turn, you may draw a card.]]></LOCALISED_TEXT>
      <COST mana_cost="{2}{G}{B}" type="Mana" />
      <RESOLUTION_TIME_ACTION>
         MTG():CreateDelayedTrigger(1, nil)
      </RESOLUTION_TIME_ACTION>
   </ACTIVATED_ABILITY>
   <TRIGGERED_ABILITY resource_id="1" replacement_effect="1">
      <TRIGGER value="SOURCE_DEALS_DAMAGE_TO_PLAYER" pre_trigger="1" simple_qualifier="self" damage_type="all" />
      <MAY tag="CARD_QUERY_DRAW_A_CARD" always_prompt="1">
         -- AI behaviour
         if EffectController():Library_Count() &lt; 10 then
            return false
         else
            return true
         end
      </MAY>
      <CLEANUP fire_once="1" />
      <RESOLUTION_TIME_ACTION>
         EffectController():DrawCards(1)
      </RESOLUTION_TIME_ACTION>
   </TRIGGERED_ABILITY>
   <ACTIVATED_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[{3}{G}{G}: Until end of turn, whenever a creature you control is dealt damage, put a +1/+1 counter on it.]]></LOCALISED_TEXT>
      <COST mana_cost="{3}{G}{G}" type="Mana" />
      <RESOLUTION_TIME_ACTION>
         MTG():CreateDelayedTrigger(2, nil)
      </RESOLUTION_TIME_ACTION>
   </ACTIVATED_ABILITY>
   <TRIGGERED_ABILITY resource_id="2" replacement_effect="2">
      <TRIGGER value="OBJECT_TAKES_DAMAGE" pre_trigger="1" damage_type="all" simple_qualifier="objectyoucontrol" >
         return (TriggerObject():GetCardType():Test(CARD_TYPE_CREATURE))
      </TRIGGER>
      <RESOLUTION_TIME_ACTION>
         if TriggerObject() ~= nil then
            TriggerObject():AddCounters( MTG():PlusOnePlusOneCounters(), 1 )
         end
      </RESOLUTION_TIME_ACTION>
   </TRIGGERED_ABILITY>
   <CLEANUP simple_cleanup="EndOfTurn" />
This is for custom cards I'm making for personal use, so I completely understand if nobody has the time to help (and I probably shouldn't be posting this here, because it's not for the community wad, but I don't know where else to post it).







thefiremind suggested this
thefiremind wrote:The fact that you draw twice could be because you have 2 CLEANUP blocks and the game probably doesn't read both so you get the current delayed trigger plus all the past ones who haven't run at least once. You should keep only 1 CLEANUP with both attributes in it.
so I removed the <CLEANUP simple_cleanup="EndOfTurn" /> from both ability blocks and added one to the end (which is how it appears above); I left the <CLEANUP fire_once="1" /> in the block of the first ability, because I only want the first ability to fire once, but the second should last until end of turn. However, it's still drawing 2 cards, and still not querying about card draw.

Re: help with custom card - delayed triggers

PostPosted: 03 Nov 2016, 22:53
by Xander9009
1: When he said to keep only one with both attributes, he meant to put <CLEANUP fire_once="1" simple_cleanup="EndOfTurn" />. Cleanup tags don't do anything outside of triggered abilities. (They may or may not work in non-delayed triggers. I don't know.) That means the one you put on the very end won't do anything. So move the cleanup that's on the end into the second triggered ability, and replace the one in the first with the one I typed above.

2: The problem with not asking is probably not this, but might be, so it worth a shot: try replacing "replacement_effect" with "replacement_query". I don't think it would have an effect on MAY tags, but if it does, then that might be the problem.

3: It says it should only trigger if the player taking damage is an opponent, but it doesn't actually check that. This could matter in a couple of situations. Either it gains an ability to deal non-combat damage and damages you or your ally, or it's activated on the opponent's turn, and that opponent takes control of it and attacks you. Or a combination of the two.

As a minor side-note, the wording for the first ability is slightly off from how it would appear on an official card. I don't know if you care about that, or if you specifically worded it the way you did on purpose, but on an official card, it would almost definitely read "The next time (this source/CARDNAME) deals damage to an opponent this turn, you may draw a card." This would make it a normal triggered ability, not a replacement. Also, since it's not actually replacing it (it still deals damage), you shouldn't need pre-trigger.

Code: Select all
   <ACTIVATED_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[{2}{G}{B}: The next time this source would deal damage to an opponent this turn, you may draw a card.]]></LOCALISED_TEXT>
      <COST mana_cost="{2}{G}{B}" type="Mana" />
      <RESOLUTION_TIME_ACTION>
         MTG():CreateDelayedTrigger(1, nil)
      </RESOLUTION_TIME_ACTION>
   </ACTIVATED_ABILITY>
   <TRIGGERED_ABILITY resource_id="1" replacement_query="1">
      <TRIGGER value="SOURCE_DEALS_DAMAGE_TO_PLAYER" pre_trigger="1" simple_qualifier="self" damage_type="all">
         return SecondaryPlayer() ~= nil and EffectController() ~= nil and SecondaryPlayer():GetTeam() ~= EffectController():GetTeam()
      </TRIGGER>
      <MAY tag="CARD_QUERY_DRAW_A_CARD" always_prompt="1">
         -- AI behaviour
         return EffectController():Library_Count() &gt;= 10
      </MAY>
      <CLEANUP fire_once="1" simple_cleanup="EndOfTurn" />
      <RESOLUTION_TIME_ACTION>
         EffectController():DrawCards(1)
      </RESOLUTION_TIME_ACTION>
   </TRIGGERED_ABILITY>
   <ACTIVATED_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[{3}{G}{G}: Until end of turn, whenever a creature you control is dealt damage, put a +1/+1 counter on it.]]></LOCALISED_TEXT>
      <COST mana_cost="{3}{G}{G}" type="Mana" />
      <RESOLUTION_TIME_ACTION>
         MTG():CreateDelayedTrigger(2, nil)
      </RESOLUTION_TIME_ACTION>
   </ACTIVATED_ABILITY>
   <TRIGGERED_ABILITY resource_id="2" replacement_effect="2">
      <TRIGGER value="OBJECT_TAKES_DAMAGE" pre_trigger="1" damage_type="all" simple_qualifier="objectyoucontrol" >
         return (TriggerObject():GetCardType():Test(CARD_TYPE_CREATURE))
      </TRIGGER>
      <RESOLUTION_TIME_ACTION>
         if TriggerObject() ~= nil then
            TriggerObject():AddCounters( MTG():PlusOnePlusOneCounters(), 1 )
         end
      </RESOLUTION_TIME_ACTION>
      <CLEANUP simple_cleanup="EndOfTurn" />
   </TRIGGERED_ABILITY>
Note that the code above only has the changes from my numbered points, not the side-note, since it might have been intentional.

No promises it'll work, but try it out and let us know. (Also, there's a forum here for custom cards, but for talking about help with them, I'd say this is the best place for it. Although I'd personally note in the thread title that it's for 2014 since the different versions use slightly different coding.)

Re: help with custom card - delayed triggers

PostPosted: 03 Nov 2016, 23:41
by nivmizzet1
Xander9009 wrote:1: When he said to keep only one with both attributes, he meant to put <CLEANUP fire_once="1" simple_cleanup="EndOfTurn" />. Cleanup tags don't do anything outside of triggered abilities. (They may or may not work in non-delayed triggers. I don't know.) That means the one you put on the very end won't do anything. So move the cleanup that's on the end into the second triggered ability, and replace the one in the first with the one I typed above.
Thanks. I figured that one out myself after testing, lol. :oops:

Xander9009 wrote:2: The problem with not asking is probably not this, but might be, so it worth a shot: try replacing "replacement_effect" with "replacement_query". I don't think it would have an effect on MAY tags, but if it does, then that might be the problem.
cool, I'll give that a go.

Xander9009 wrote:3: It says it should only trigger if the player taking damage is an opponent, but it doesn't actually check that. This could matter in a couple of situations. Either it gains an ability to deal non-combat damage and damages you or your ally, or it's activated on the opponent's turn, and that opponent takes control of it and attacks you. Or a combination of the two.
I was thinking it might be something like this, like it's triggering when it deals damage to me as well as the opponent (because I've only been using pestilence type effects to trigger the draw -- I haven't tested just swinging with the creature, which will probably result in drawing a single card)

Xander9009 wrote:As a minor side-note, the wording for the first ability is slightly off from how it would appear on an official card. I don't know if you care about that, or if you specifically worded it the way you did on purpose, but on an official card, it would almost definitely read "The next time (this source/CARDNAME) deals damage to an opponent this turn, you may draw a card." This would make it a normal triggered ability, not a replacement. Also, since it's not actually replacing it (it still deals damage), you shouldn't need pre-trigger.

Code: Select all
   <ACTIVATED_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[{2}{G}{B}: The next time this source would deal damage to an opponent this turn, you may draw a card.]]></LOCALISED_TEXT>
      <COST mana_cost="{2}{G}{B}" type="Mana" />
      <RESOLUTION_TIME_ACTION>
         MTG():CreateDelayedTrigger(1, nil)
      </RESOLUTION_TIME_ACTION>
   </ACTIVATED_ABILITY>
   <TRIGGERED_ABILITY resource_id="1" replacement_query="1">
      <TRIGGER value="SOURCE_DEALS_DAMAGE_TO_PLAYER" pre_trigger="1" simple_qualifier="self" damage_type="all">
         return SecondaryPlayer() ~= nil and EffectController() ~= nil and SecondaryPlayer():GetTeam() ~= EffectController():GetTeam()
      </TRIGGER>
      <MAY tag="CARD_QUERY_DRAW_A_CARD" always_prompt="1">
         -- AI behaviour
         return EffectController():Library_Count() &gt;= 10
      </MAY>
      <CLEANUP fire_once="1" simple_cleanup="EndOfTurn" />
      <RESOLUTION_TIME_ACTION>
         EffectController():DrawCards(1)
      </RESOLUTION_TIME_ACTION>
   </TRIGGERED_ABILITY>
   <ACTIVATED_ABILITY>
      <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[{3}{G}{G}: Until end of turn, whenever a creature you control is dealt damage, put a +1/+1 counter on it.]]></LOCALISED_TEXT>
      <COST mana_cost="{3}{G}{G}" type="Mana" />
      <RESOLUTION_TIME_ACTION>
         MTG():CreateDelayedTrigger(2, nil)
      </RESOLUTION_TIME_ACTION>
   </ACTIVATED_ABILITY>
   <TRIGGERED_ABILITY resource_id="2" replacement_effect="2">
      <TRIGGER value="OBJECT_TAKES_DAMAGE" pre_trigger="1" damage_type="all" simple_qualifier="objectyoucontrol" >
         return (TriggerObject():GetCardType():Test(CARD_TYPE_CREATURE))
      </TRIGGER>
      <RESOLUTION_TIME_ACTION>
         if TriggerObject() ~= nil then
            TriggerObject():AddCounters( MTG():PlusOnePlusOneCounters(), 1 )
         end
      </RESOLUTION_TIME_ACTION>
      <CLEANUP simple_cleanup="EndOfTurn" />
   </TRIGGERED_ABILITY>
Note that the code above only has the changes from my numbered points, not the side-note, since it might have been intentional.

No promises it'll work, but try it out and let us know. (Also, there's a forum here for custom cards, but for talking about help with them, I'd say this is the best place for it. Although I'd personally note in the thread title that it's for 2014 since the different versions use slightly different coding.)
Thanks Xander, I'll give it a shot and let you know how it goes.

Re: help with custom card - delayed triggers

PostPosted: 03 Nov 2016, 23:43
by Xander9009
Just make sure it's a new post, not an edit, or I won't be notified if you still have questions.

Re: help with custom card - delayed triggers

PostPosted: 04 Nov 2016, 00:01
by thefiremind
If you still have the problem of the triggered ability working twice, I recalled that it happened to me in the past as well, but always on things I was testing just to see if they worked: since I wasn't aiming for a card in particular, I made modifications here and there and forgot about it.

By looking at your code, I think I might have found an explanation for the strange behavior: you are using a pre_trigger but never override the damage, so maybe the game erroneously considers it as triggering twice (once before the damage is dealt, and once the moment it is dealt).

If I'm right, then the solution is to follow Xander9009's advice and decide what you want your card to really do: either you let the damage through (then you don't use a replacement_effect nor a pre_trigger), or you substitute the damage with the draw (then you override the damage and maybe add an "instead" in the ability text).

Re: help with custom card - delayed triggers

PostPosted: 04 Nov 2016, 02:39
by nivmizzet1
Xander9009 wrote:Just make sure it's a new post, not an edit, or I won't be notified if you still have questions.
Hi. Sorry, I thought I replied hours ago, but it turns out I didn't (although I know I prepared a reply; I had to go to work and probably forgot to press 'submit') #-o

Your changes fixed the problem with double drawing, but not the problem with the query (or rather lack thereof).

For both abilities, after being activated, when the trigger condition is met there is no time delay, it just resolves instantly, a bit like if there was an auto_skip condition met, but there is no auto_skip function and it does it even with auto resolution switched ff. This is a bit of a problem in itself, as it should go on the stack, but I'm wondering if this could have something to do with the query not happening?

Re: help with custom card - delayed triggers

PostPosted: 04 Nov 2016, 02:41
by nivmizzet1
thefiremind wrote:If you still have the problem of the triggered ability working twice, I recalled that it happened to me in the past as well, but always on things I was testing just to see if they worked: since I wasn't aiming for a card in particular, I made modifications here and there and forgot about it.
Thanks for your input thefiremind. Xanders fix worked, so it's all good now (well, the card draw part anyway).

Re: help with custom card - delayed triggers

PostPosted: 04 Nov 2016, 02:41
by Xander9009
nivmizzet1 wrote:
Xander9009 wrote:Just make sure it's a new post, not an edit, or I won't be notified if you still have questions.
Hi. Sorry, I thought I replied hours ago, but it turns out I didn't (although I know I prepared a reply; I had to go to work and probably forgot to press 'submit') #-o

Your changes fixed the problem with double drawing, but not the problem with the query (or rather lack thereof).

For both abilities, after being activated, when the trigger condition is met there is no time delay, it just resolves instantly, a bit like if there was an auto_skip condition met, but there is no auto_skip function and it does it even with auto resolution switched ff. This is a bit of a problem in itself, as it should go on the stack, but I'm wondering if this could have something to do with the query not happening?
'replacement_effect="1"' is meant to make it skip the stack. Remove that (and 'pre_trigger="1"') if you want it to use the stack.

Re: help with custom card - delayed triggers

PostPosted: 04 Nov 2016, 05:04
by nivmizzet1
Xander9009 wrote:'replacement_effect="1"' is meant to make it skip the stack. Remove that (and 'pre_trigger="1"') if you want it to use the stack.
so that's what those do!

Re: help with custom card - delayed triggers

PostPosted: 04 Nov 2016, 09:38
by thefiremind
nivmizzet1 wrote:
Xander9009 wrote:'replacement_effect="1"' is meant to make it skip the stack. Remove that (and 'pre_trigger="1"') if you want it to use the stack.
so that's what those do!
Also, something I didn't remember to add yesterday: I'm pretty sure that the MAY block doesn't work when you don't use the stack, not even with replacement_query. I had an occasion where I wanted the standard "Do you want to use this ability?" in a replacement trigger but couldn't use MAY and had to build my own query. If you use the stack, the MAY will work properly.

Re: help with custom card - delayed triggers

PostPosted: 04 Nov 2016, 12:50
by nivmizzet1
thefiremind wrote:
nivmizzet1 wrote:
Xander9009 wrote:'replacement_effect="1"' is meant to make it skip the stack. Remove that (and 'pre_trigger="1"') if you want it to use the stack.
so that's what those do!
Also, something I didn't remember to add yesterday: I'm pretty sure that the MAY block doesn't work when you don't use the stack, not even with replacement_query. I had an occasion where I wanted the standard "Do you want to use this ability?" in a replacement trigger but couldn't use MAY and had to build my own query. If you use the stack, the MAY will work properly.
Yep, you're right. I took Xander's advice and removed the 'replacement_effect="1"' and 'pre_trigger="1"' and it's all working perfectly now! :D