name: Vylon
card_text: When any face-up "Vylon" Equip Card(s) you control are destroyed (except during the Damage Step): You can Special Summon an equal or lower number of "Vylon" Tuner monsters from your Deck. They cannot be used as Synchro Material Monsters, except for the Synchro Summon of a "Vylon" Synchro Monster.
external_ids: local SETCARD_ID_0 = 0x30 --Vylon
  
lua: local SETCARD_ID_0 = 0x30 --Vylon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--Search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_SZONE)
  		and c:IsPreviousPosition(POS_FACEUP)
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and bit.band(c:GetPreviousTypeOnField(), TYPE_EQUIP) ~= 0
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = eg:FilterCount(s.cfilter, nil, tp)
  	e:SetLabel(ct)
  	return ct > 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TUNER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsStatus(STATUS_CHAINING) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 then
  		return
  	end
  	if ft > e:GetLabel() then
  		ft = e:GetLabel()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, ft, nil, e, tp)
  	local tc = g:GetFirst()
  	while tc do
  		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_BE_SYNCHRO_MATERIAL)
  		e1:SetValue(s.synlimit)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		tc = g:GetNext()
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.synlimit(e, c)
  	if not c then
  		return false
  	end
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  
  
source_text: Vylon
  When any face-up "Vylon" Equip Card(s) you control are destroyed (except during the Damage Step): You can Special Summon an equal or lower number of "Vylon" Tuner monsters from your Deck. They cannot be used as Synchro Material Monsters, except for the Synchro Summon of a "Vylon" Synchro Monster.
target_text: -- Vylon
  local SETCARD_ID_0 = 0x30 --Vylon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--Search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_SZONE)
  		and c:IsPreviousPosition(POS_FACEUP)
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and bit.band(c:GetPreviousTypeOnField(), TYPE_EQUIP) ~= 0
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = eg:FilterCount(s.cfilter, nil, tp)
  	e:SetLabel(ct)
  	return ct > 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TUNER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsStatus(STATUS_CHAINING) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 then
  		return
  	end
  	if ft > e:GetLabel() then
  		ft = e:GetLabel()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, ft, nil, e, tp)
  	local tc = g:GetFirst()
  	while tc do
  		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_BE_SYNCHRO_MATERIAL)
  		e1:SetValue(s.synlimit)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		tc = g:GetNext()
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.synlimit(e, c)
  	if not c then
  		return false
  	end
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  
  