name: Graydle
card_text: When an opponent's monster declares a direct attack: You can Special Summon 1 "Graydle" monster from your Deck in Attack Position, if you control no monsters. When a "Graydle" monster you control declares a direct attack: You can target 1 monster in your opponent's Graveyard; Special Summon that target to their side of the field, if they control no monsters. You can only use each effect of "Graydle Parasite" once per turn.
external_ids: local SETCARD_ID_0 = 0xd1 --Graydle
  
lua: local SETCARD_ID_0 = 0xd1 --Graydle
  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)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon1)
  	e2:SetTarget(s.sptg1)
  	e2:SetOperation(s.spop1)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.spcon2)
  	e3:SetTarget(s.sptg2)
  	e3:SetOperation(s.spop2)
  	c:RegisterEffect(e3)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.spfilter1(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter1, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) ~= 0 then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter1, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  	end
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local c = Duel.GetAttacker()
  	return c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and Duel.GetAttackTarget() == nil
  end
  function s.spfilter2(c, e, tp)
  	return c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_GRAVE) and s.spfilter2(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) == 0 and Duel.GetLocationCount(1 - tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter2, tp, 0, LOCATION_GRAVE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter2, tp, 0, LOCATION_GRAVE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) ~= 0 then
  		return
  	end
  	if Duel.GetLocationCount(1 - tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Graydle
  When an opponent's monster declares a direct attack: You can Special Summon 1 "Graydle" monster from your Deck in Attack Position, if you control no monsters. When a "Graydle" monster you control declares a direct attack: You can target 1 monster in your opponent's Graveyard; Special Summon that target to their side of the field, if they control no monsters. You can only use each effect of "Graydle Parasite" once per turn.
target_text: -- Graydle
  local SETCARD_ID_0 = 0xd1 --Graydle
  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)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon1)
  	e2:SetTarget(s.sptg1)
  	e2:SetOperation(s.spop1)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.spcon2)
  	e3:SetTarget(s.sptg2)
  	e3:SetOperation(s.spop2)
  	c:RegisterEffect(e3)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.spfilter1(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter1, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) ~= 0 then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter1, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  	end
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local c = Duel.GetAttacker()
  	return c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and Duel.GetAttackTarget() == nil
  end
  function s.spfilter2(c, e, tp)
  	return c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_GRAVE) and s.spfilter2(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) == 0 and Duel.GetLocationCount(1 - tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter2, tp, 0, LOCATION_GRAVE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter2, tp, 0, LOCATION_GRAVE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) ~= 0 then
  		return
  	end
  	if Duel.GetLocationCount(1 - tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP)
  	end
  end
  
  