name: Cartorhyn
card_text: You can discard this card; you can Normal Summon 1 EARTH or WATER monster during your Main Phase this turn, in addition to your Normal Summon/Set. (You can only gain this effect once per turn.) If you control an EARTH and WATER monster(s), while this card is in your GY: You can Special Summon this card, but banish it when it leaves the field. You can only use each effect of "Cartorhyn the Hidden Gem of the Seafront" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--extra summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.sumcost)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.sumcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable()
  	end
  	Duel.SendtoGrave(c, REASON_COST + REASON_DISCARD)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanSummon(tp) and Duel.IsPlayerCanAdditionalSummon(tp) and Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  function s.sumop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 2))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetTargetRange(LOCATION_HAND + LOCATION_MZONE, 0)
  	e1:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsAttribute, ATTRIBUTE_EARTH + ATTRIBUTE_WATER))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.cfilter(c, attr)
  	return c:IsFaceup() and c:IsAttribute(attr)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil, ATTRIBUTE_EARTH) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil, ATTRIBUTE_WATER)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		c:RegisterEffect(e1, true)
  	end
  end
  
  
source_text: Cartorhyn
  You can discard this card; you can Normal Summon 1 EARTH or WATER monster during your Main Phase this turn, in addition to your Normal Summon/Set. (You can only gain this effect once per turn.) If you control an EARTH and WATER monster(s), while this card is in your GY: You can Special Summon this card, but banish it when it leaves the field. You can only use each effect of "Cartorhyn the Hidden Gem of the Seafront" once per turn.
target_text: -- Cartorhyn
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--extra summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.sumcost)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.sumcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable()
  	end
  	Duel.SendtoGrave(c, REASON_COST + REASON_DISCARD)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanSummon(tp) and Duel.IsPlayerCanAdditionalSummon(tp) and Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  function s.sumop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 2))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetTargetRange(LOCATION_HAND + LOCATION_MZONE, 0)
  	e1:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsAttribute, ATTRIBUTE_EARTH + ATTRIBUTE_WATER))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.cfilter(c, attr)
  	return c:IsFaceup() and c:IsAttribute(attr)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil, ATTRIBUTE_EARTH) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil, ATTRIBUTE_WATER)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		c:RegisterEffect(e1, true)
  	end
  end
  
  