name: Salamangreat
card_text: If you have 3 or more "Salamangreat" monsters in your GY: You can send this card from your hand to the GY, then target 1 "Salamangreat" Link Monster in your GY and 1 card in your opponent's Spell & Trap Zone; return that targeted monster from your GY to the Extra Deck, and if you do, destroy the targeted card on the field. If a card(s) in your opponent's Spell & Trap Zone is destroyed and sent to the GY, while this card is in your GY (except during the Damage Step): You can Special Summon this card in Defense Position. You can only use 1 "Salamangreat Foxer" effect per turn, and only once that turn.
external_ids: local SETCARD_ID_0 = 0x119 --Salamangreat
  
lua: local SETCARD_ID_0 = 0x119 --Salamangreat
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_TODECK)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	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:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 3, nil)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.filter(c)
  	return c:GetSequence() < 5
  end
  function s.tdfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_LINK) and c:IsAbleToExtra()
  end
  function s.target(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, 0, LOCATION_SZONE, 1, nil) and Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local lg = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_SZONE, 1, 1, nil)
  	e:SetLabelObject(g:GetFirst())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 1 - tp, LOCATION_SZONE)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, lg, 1, tp, LOCATION_GRAVE)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local sc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local lc = g:GetFirst()
  	if lc == sc then
  		lc = g:GetNext()
  	end
  	if lc and lc:IsRelateToEffect(e) and Duel.SendtoDeck(lc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) > 0 and lc:IsLocation(LOCATION_EXTRA) and sc and sc:IsRelateToEffect(e) then
  		Duel.Destroy(sc, REASON_EFFECT)
  	end
  end
  function s.spfilter(c, tp)
  	return c:IsReason(REASON_DESTROY) and c:IsPreviousLocation(LOCATION_SZONE) and c:IsPreviousControler(1 - tp) and c:GetPreviousSequence() < 5
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp)
  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 e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, tp, LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsRelateToEffect(e) then
  		Duel.SpecialSummon(e:GetHandler(), 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  
source_text: Salamangreat
  If you have 3 or more "Salamangreat" monsters in your GY: You can send this card from your hand to the GY, then target 1 "Salamangreat" Link Monster in your GY and 1 card in your opponent's Spell & Trap Zone; return that targeted monster from your GY to the Extra Deck, and if you do, destroy the targeted card on the field. If a card(s) in your opponent's Spell & Trap Zone is destroyed and sent to the GY, while this card is in your GY (except during the Damage Step): You can Special Summon this card in Defense Position. You can only use 1 "Salamangreat Foxer" effect per turn, and only once that turn.
target_text: -- Salamangreat
  local SETCARD_ID_0 = 0x119 --Salamangreat
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_TODECK)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	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:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 3, nil)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.filter(c)
  	return c:GetSequence() < 5
  end
  function s.tdfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_LINK) and c:IsAbleToExtra()
  end
  function s.target(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, 0, LOCATION_SZONE, 1, nil) and Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local lg = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_SZONE, 1, 1, nil)
  	e:SetLabelObject(g:GetFirst())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 1 - tp, LOCATION_SZONE)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, lg, 1, tp, LOCATION_GRAVE)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local sc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local lc = g:GetFirst()
  	if lc == sc then
  		lc = g:GetNext()
  	end
  	if lc and lc:IsRelateToEffect(e) and Duel.SendtoDeck(lc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) > 0 and lc:IsLocation(LOCATION_EXTRA) and sc and sc:IsRelateToEffect(e) then
  		Duel.Destroy(sc, REASON_EFFECT)
  	end
  end
  function s.spfilter(c, tp)
  	return c:IsReason(REASON_DESTROY) and c:IsPreviousLocation(LOCATION_SZONE) and c:IsPreviousControler(1 - tp) and c:GetPreviousSequence() < 5
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp)
  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 e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, tp, LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsRelateToEffect(e) then
  		Duel.SpecialSummon(e:GetHandler(), 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  