name: Spider
card_text: When your opponent declares a direct attack, while you have 3 or more Insect monsters in your GY: Negate the attack, and if you do, Special Summon 3 "Spider Tokens" (Insect/EARTH/Level 1/ATK 100/DEF 100) in Attack Position.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 56051649 --Spider Token
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 56051649 --Spider Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer() and Duel.GetAttackTarget() == nil and Duel.IsExistingMatchingCard(Card.IsRace, tp, LOCATION_GRAVE, 0, 3, nil, RACE_INSECT)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tg = Duel.GetAttacker()
  	if chk == 0 then
  		return tg:IsOnField()
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) >= 3
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH, POS_FACEUP_ATTACK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 3, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 3, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if
  		Duel.NegateAttack()
  		and Duel.GetLocationCount(tp, LOCATION_MZONE) > 2
  		and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH, POS_FACEUP_ATTACK)
  	then
  		for i = 1, 3 do
  			local token = Duel.CreateToken(tp, id + 1)
  			Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  		end
  		Duel.SpecialSummonComplete()
  	end
  end
  
  
source_text: Spider
  When your opponent declares a direct attack, while you have 3 or more Insect monsters in your GY: Negate the attack, and if you do, Special Summon 3 "Spider Tokens" (Insect/EARTH/Level 1/ATK 100/DEF 100) in Attack Position.
target_text: -- Spider
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 56051649 --Spider Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer() and Duel.GetAttackTarget() == nil and Duel.IsExistingMatchingCard(Card.IsRace, tp, LOCATION_GRAVE, 0, 3, nil, RACE_INSECT)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tg = Duel.GetAttacker()
  	if chk == 0 then
  		return tg:IsOnField()
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) >= 3
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH, POS_FACEUP_ATTACK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 3, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 3, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if
  		Duel.NegateAttack()
  		and Duel.GetLocationCount(tp, LOCATION_MZONE) > 2
  		and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH, POS_FACEUP_ATTACK)
  	then
  		for i = 1, 3 do
  			local token = Duel.CreateToken(tp, id + 1)
  			Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  		end
  		Duel.SpecialSummonComplete()
  	end
  end
  
  