name: Salamangreat
card_text: If you have 2 or more "Salamangreat" monsters in your GY: You can Special Summon this card from your hand. If a "Salamangreat" Ritual, Fusion, Synchro, Xyz, or Link Monster(s) is Special Summoned to your field, while this card is in your GY (except during the Damage Step): You can target 1 other "Salamangreat" monster in your GY; place this card on the bottom of your Deck, and if you do, Special Summon that monster to your opponent's field, then draw 1 card. You can only use each effect of "Salamangreat Weasel" once per 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)
  	--same effect send this card to grave and spsummon another card check
  	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--special summon and draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_SPECIAL_SUMMON + CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetLabelObject(e0)
  	e2:SetCondition(s.spdcon)
  	e2:SetTarget(s.spdtg)
  	e2:SetOperation(s.spdpop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 2, nil)
  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)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  end
  function s.cfilter(c, tp, se)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_FUSION + TYPE_RITUAL + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK) and (se == nil or c:GetReasonEffect() ~= se)
  end
  function s.spdcon(e, tp, eg, ep, ev, re, r, rp)
  	local se = e:GetLabelObject():GetLabelObject()
  	return eg:IsExists(s.cfilter, 1, nil, tp, se)
  end
  function s.spdfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  end
  function s.spdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.spdfilter(chkc, e, tp) and chkc ~= c
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and Duel.GetLocationCount(1 - tp, LOCATION_MZONE, tp) > 0 and Duel.IsExistingTarget(s.spdfilter, tp, LOCATION_GRAVE, 0, 1, c, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spdfilter, tp, LOCATION_GRAVE, 0, 1, 1, c, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, c, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.spdpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if
  		c:IsRelateToEffect(e)
  		and Duel.SendtoDeck(c, nil, SEQ_DECKBOTTOM, REASON_EFFECT) ~= 0
  		and c:IsLocation(LOCATION_DECK)
  		and tc:IsRelateToEffect(e)
  		and Duel.GetLocationCount(1 - tp, LOCATION_MZONE, tp) > 0
  		and Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP) > 0
  		and Duel.IsPlayerCanDraw(tp)
  	then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  
  
source_text: Salamangreat
  If you have 2 or more "Salamangreat" monsters in your GY: You can Special Summon this card from your hand. If a "Salamangreat" Ritual, Fusion, Synchro, Xyz, or Link Monster(s) is Special Summoned to your field, while this card is in your GY (except during the Damage Step): You can target 1 other "Salamangreat" monster in your GY; place this card on the bottom of your Deck, and if you do, Special Summon that monster to your opponent's field, then draw 1 card. You can only use each effect of "Salamangreat Weasel" once per turn.
target_text: -- Salamangreat
  local SETCARD_ID_0 = 0x119 --Salamangreat
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--same effect send this card to grave and spsummon another card check
  	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--special summon and draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_SPECIAL_SUMMON + CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetLabelObject(e0)
  	e2:SetCondition(s.spdcon)
  	e2:SetTarget(s.spdtg)
  	e2:SetOperation(s.spdpop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 2, nil)
  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)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  end
  function s.cfilter(c, tp, se)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_FUSION + TYPE_RITUAL + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK) and (se == nil or c:GetReasonEffect() ~= se)
  end
  function s.spdcon(e, tp, eg, ep, ev, re, r, rp)
  	local se = e:GetLabelObject():GetLabelObject()
  	return eg:IsExists(s.cfilter, 1, nil, tp, se)
  end
  function s.spdfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  end
  function s.spdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.spdfilter(chkc, e, tp) and chkc ~= c
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and Duel.GetLocationCount(1 - tp, LOCATION_MZONE, tp) > 0 and Duel.IsExistingTarget(s.spdfilter, tp, LOCATION_GRAVE, 0, 1, c, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spdfilter, tp, LOCATION_GRAVE, 0, 1, 1, c, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, c, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.spdpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if
  		c:IsRelateToEffect(e)
  		and Duel.SendtoDeck(c, nil, SEQ_DECKBOTTOM, REASON_EFFECT) ~= 0
  		and c:IsLocation(LOCATION_DECK)
  		and tc:IsRelateToEffect(e)
  		and Duel.GetLocationCount(1 - tp, LOCATION_MZONE, tp) > 0
  		and Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP) > 0
  		and Duel.IsPlayerCanDraw(tp)
  	then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  
  