name: Mementotlan
card_text: If a face-up "Memento" monster(s) you control leaves the field because of an opponent's card: Special Summon 1 "Mementoal Tecuhtlica - Combined Creation" from your hand or Deck, ignoring its Summoning conditions. If your opponent moves a "Memento" monster(s) out of your GY, while this card is in your GY (except during the Damage Step): You can banish this card; Special Summon as many "Memento" monsters as possible with different names from your hand and/or Deck. You can only use each effect of "Mementotlan Bone Back" once per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 23288411 --Mementoal Tecuhtlica - Combined Creation
  local SETCARD_ID_0 = 0x1a1 --Memento
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 23288411 --Mementoal Tecuhtlica - Combined Creation
  local SETCARD_ID_0 = 0x1a1 --Memento
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_LEAVE_FIELD)
  	e1:SetCountLimit(1, id)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_LEAVE_GRAVE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.spcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousControler(tp) and c:GetReasonPlayer() == 1 - tp
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_HAND)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	Duel.SpecialSummon(g, 0, tp, tp, true, false, POS_FACEUP)
  end
  function s.mfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsPreviousControler(tp)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and eg:IsExists(s.mfilter, 1, nil, tp)
  end
  function s.sfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.sfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.sfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, nil, e, tp)
  	local ft = math.min(Duel.GetLocationCount(tp, LOCATION_MZONE), g:GetClassCount(Card.GetCode))
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, ft, ft)
  	if sg then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Mementotlan
  If a face-up "Memento" monster(s) you control leaves the field because of an opponent's card: Special Summon 1 "Mementoal Tecuhtlica - Combined Creation" from your hand or Deck, ignoring its Summoning conditions. If your opponent moves a "Memento" monster(s) out of your GY, while this card is in your GY (except during the Damage Step): You can banish this card; Special Summon as many "Memento" monsters as possible with different names from your hand and/or Deck. You can only use each effect of "Mementotlan Bone Back" once per turn.
target_text: -- Mementotlan
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 23288411 --Mementoal Tecuhtlica - Combined Creation
  local SETCARD_ID_0 = 0x1a1 --Memento
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_LEAVE_FIELD)
  	e1:SetCountLimit(1, id)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_LEAVE_GRAVE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.spcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousControler(tp) and c:GetReasonPlayer() == 1 - tp
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_HAND)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	Duel.SpecialSummon(g, 0, tp, tp, true, false, POS_FACEUP)
  end
  function s.mfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsPreviousControler(tp)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and eg:IsExists(s.mfilter, 1, nil, tp)
  end
  function s.sfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.sfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.sfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, nil, e, tp)
  	local ft = math.min(Duel.GetLocationCount(tp, LOCATION_MZONE), g:GetClassCount(Card.GetCode))
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, ft, ft)
  	if sg then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  