name: Stand
card_text: Tribute 1 monster, then target 1 monster in your opponent's GY with the same original Type and Attribute; Special Summon it to your field. You can only activate 1 "Stand In" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetLabel(0)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, e, tp)
  	local race = c:GetOriginalRace()
  	local attr = c:GetOriginalAttribute()
  	return bit.band(c:GetOriginalType(), TYPE_MONSTER) ~= 0 and Duel.GetMZoneCount(tp, c, tp) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, 0, LOCATION_GRAVE, 1, nil, race, attr, e, tp)
  end
  function s.spfilter(c, race, attr, e, tp)
  	return c:GetOriginalRace() == race and c:GetOriginalAttribute() == attr and c:IsCanBeEffectTarget(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, tp)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, e, tp)
  	end
  	local sg = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, e, tp)
  	e:SetLabelObject(sg:GetFirst())
  	Duel.Release(sg, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local rc = e:GetLabelObject()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(1 - tp) and s.spfilter(chkc, rc:GetOriginalRace(), rc:GetOriginalAttribute(), e, tp)
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return true
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = Duel.SelectTarget(tp, s.spfilter, tp, 0, LOCATION_GRAVE, 1, 1, nil, rc:GetOriginalRace(), rc:GetOriginalAttribute(), e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, sg, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  
source_text: Stand
  Tribute 1 monster, then target 1 monster in your opponent's GY with the same original Type and Attribute; Special Summon it to your field. You can only activate 1 "Stand In" per turn.
target_text: -- Stand
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetLabel(0)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, e, tp)
  	local race = c:GetOriginalRace()
  	local attr = c:GetOriginalAttribute()
  	return bit.band(c:GetOriginalType(), TYPE_MONSTER) ~= 0 and Duel.GetMZoneCount(tp, c, tp) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, 0, LOCATION_GRAVE, 1, nil, race, attr, e, tp)
  end
  function s.spfilter(c, race, attr, e, tp)
  	return c:GetOriginalRace() == race and c:GetOriginalAttribute() == attr and c:IsCanBeEffectTarget(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, tp)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, e, tp)
  	end
  	local sg = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, e, tp)
  	e:SetLabelObject(sg:GetFirst())
  	Duel.Release(sg, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local rc = e:GetLabelObject()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(1 - tp) and s.spfilter(chkc, rc:GetOriginalRace(), rc:GetOriginalAttribute(), e, tp)
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return true
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = Duel.SelectTarget(tp, s.spfilter, tp, 0, LOCATION_GRAVE, 1, 1, nil, rc:GetOriginalRace(), rc:GetOriginalAttribute(), e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, sg, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  