name: Mementotlan-Horned
card_text: If you have 3 or more "Memento" monsters with different names in your GY, you can Special Summon this card (from your hand). You can only Special Summon "Mementotlan-Horned Dragon" once per turn this way. If this card on the field is destroyed by card effect: You can target 3 face-up cards on the field, including a "Memento" card you control; destroy them. You can only use this effect of "Mementotlan-Horned Dragon" once per turn.
external_ids: local SETCARD_ID_0 = 0x1a1 --Memento
  
lua: local SETCARD_ID_0 = 0x1a1 --Memento
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCondition(s.spcon)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCountLimit(1, id + o)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and g:GetClassCount(Card.GetCode) > 2
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsReason(REASON_EFFECT)
  end
  function s.filter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 2, c)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local ag = Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 2, 2, g)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g + ag, 3, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(Duel.GetTargetsRelateToChain(), REASON_EFFECT)
  end
  
  
source_text: Mementotlan-Horned
  If you have 3 or more "Memento" monsters with different names in your GY, you can Special Summon this card (from your hand). You can only Special Summon "Mementotlan-Horned Dragon" once per turn this way. If this card on the field is destroyed by card effect: You can target 3 face-up cards on the field, including a "Memento" card you control; destroy them. You can only use this effect of "Mementotlan-Horned Dragon" once per turn.
target_text: -- Mementotlan-Horned
  local SETCARD_ID_0 = 0x1a1 --Memento
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCondition(s.spcon)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCountLimit(1, id + o)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and g:GetClassCount(Card.GetCode) > 2
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsReason(REASON_EFFECT)
  end
  function s.filter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 2, c)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local ag = Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 2, 2, g)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g + ag, 3, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(Duel.GetTargetsRelateToChain(), REASON_EFFECT)
  end
  
  