name: Vendread
card_text: If this card is sent to the GY: You can reveal 1 "Vendread" card in your hand; Special Summon this card, but banish it when it leaves the field. A "Vendread" monster Ritual Summoned using this card on the field gains the following effect. You can only use each of the preceding effects of "Vendread Striges" once per turn.
  ● After damage calculation, if this card battled an opponent's monster: You can draw 1 card, then discard 1 card.
external_ids: local SETCARD_ID_0 = 0x106 --Vendread
  
lua: local SETCARD_ID_0 = 0x106 --Vendread
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--gain
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_EVENT_PLAYER)
  	e2:SetCode(EVENT_BE_MATERIAL)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.mtcon)
  	e2:SetOperation(s.mtop)
  	c:RegisterEffect(e2)
  end
  function s.spcfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsPublic()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spcfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local cg = Duel.SelectMatchingCard(tp, s.spcfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	Duel.ConfirmCards(1 - tp, cg)
  	Duel.ShuffleHand(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)
  	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 Duel.GetLocationCount(tp, LOCATION_MZONE) < 1 or not c:IsRelateToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e1, true)
  	end
  end
  function s.mtcon(e, tp, eg, ep, ev, re, r, rp)
  	return r == REASON_RITUAL and e:GetHandler():IsPreviousLocation(LOCATION_MZONE) and eg:IsExists(Card.IsSetCard, 1, nil, 0x106)
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = eg:Filter(Card.IsSetCard, nil, 0x106)
  	local rc = g:GetFirst()
  	if not rc then
  		return
  	end
  	local e1 = Effect.CreateEffect(rc)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_HANDES + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BATTLED)
  	e1:SetTarget(s.drtg)
  	e1:SetOperation(s.drop)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  	rc:RegisterEffect(e1, true)
  	if not rc:IsType(TYPE_EFFECT) then
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_ADD_TYPE)
  		e3:SetValue(TYPE_EFFECT)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		rc:RegisterEffect(e3, true)
  	end
  	rc:RegisterFlagEffect(0, RESET_EVENT + RESETS_STANDARD, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 2))
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetAttackTarget() ~= nil and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.Draw(tp, 1, REASON_EFFECT) ~= 0 then
  		Duel.BreakEffect()
  		Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  	end
  end
  
  
source_text: Vendread
  If this card is sent to the GY: You can reveal 1 "Vendread" card in your hand; Special Summon this card, but banish it when it leaves the field. A "Vendread" monster Ritual Summoned using this card on the field gains the following effect. You can only use each of the preceding effects of "Vendread Striges" once per turn.
  ● After damage calculation, if this card battled an opponent's monster: You can draw 1 card, then discard 1 card.
target_text: -- Vendread
  local SETCARD_ID_0 = 0x106 --Vendread
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--gain
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_EVENT_PLAYER)
  	e2:SetCode(EVENT_BE_MATERIAL)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.mtcon)
  	e2:SetOperation(s.mtop)
  	c:RegisterEffect(e2)
  end
  function s.spcfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsPublic()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spcfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local cg = Duel.SelectMatchingCard(tp, s.spcfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	Duel.ConfirmCards(1 - tp, cg)
  	Duel.ShuffleHand(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)
  	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 Duel.GetLocationCount(tp, LOCATION_MZONE) < 1 or not c:IsRelateToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e1, true)
  	end
  end
  function s.mtcon(e, tp, eg, ep, ev, re, r, rp)
  	return r == REASON_RITUAL and e:GetHandler():IsPreviousLocation(LOCATION_MZONE) and eg:IsExists(Card.IsSetCard, 1, nil, 0x106)
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = eg:Filter(Card.IsSetCard, nil, 0x106)
  	local rc = g:GetFirst()
  	if not rc then
  		return
  	end
  	local e1 = Effect.CreateEffect(rc)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_HANDES + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BATTLED)
  	e1:SetTarget(s.drtg)
  	e1:SetOperation(s.drop)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  	rc:RegisterEffect(e1, true)
  	if not rc:IsType(TYPE_EFFECT) then
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_ADD_TYPE)
  		e3:SetValue(TYPE_EFFECT)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		rc:RegisterEffect(e3, true)
  	end
  	rc:RegisterFlagEffect(0, RESET_EVENT + RESETS_STANDARD, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 2))
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetAttackTarget() ~= nil and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.Draw(tp, 1, REASON_EFFECT) ~= 0 then
  		Duel.BreakEffect()
  		Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  	end
  end
  
  