name: D/D/D
card_text: Pendulum Scale = 4
  [ Pendulum Effect ]
  You can banish 2 "D/D" monsters from your Graveyard; Special Summon this card from your Pendulum Zone.
  ----------------------------------------
  [ Monster Effect ]
  During your opponent's turn, if this card is in your hand or Graveyard: You can target 2 face-up Spell/Trap Cards you control; you cannot Special Summon monsters for the rest of this turn, except Fiend-Type monsters, also destroy the targeted cards, and if you do, Special Summon this card (this is a Quick Effect). You can only use this effect of "D/D/D Chaos King Apocalypse" once per turn.
external_ids: local SETCARD_ID_0 = 0xaf --D/D
  
lua: local SETCARD_ID_0 = 0xaf --D/D
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id)
  	e2:SetRange(LOCATION_HAND + LOCATION_GRAVE)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 2, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 2, 2, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  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.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local ct = -ft + 1
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, 0, 2, nil)
  			and ct <= 2
  			and (ct <= 0 or Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, ct, nil))
  			and not c:IsStatus(STATUS_CHAINING)
  			and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = nil
  	if ct <= 0 then
  		g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 2, 2, nil)
  	elseif ct == 1 then
  		g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g2 = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 1, 1, g:GetFirst())
  		g:Merge(g2)
  	else
  		g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 2, 2, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 2, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 and Duel.Destroy(g, REASON_EFFECT) ~= 0 then
  		local c = e:GetHandler()
  		if not c:IsRelateToEffect(e) then
  			return
  		end
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.splimit(e, c)
  	return c:GetRace() ~= RACE_FIEND
  end
  
  
source_text: D/D/D
  Pendulum Scale = 4
  [ Pendulum Effect ]
  You can banish 2 "D/D" monsters from your Graveyard; Special Summon this card from your Pendulum Zone.
  ----------------------------------------
  [ Monster Effect ]
  During your opponent's turn, if this card is in your hand or Graveyard: You can target 2 face-up Spell/Trap Cards you control; you cannot Special Summon monsters for the rest of this turn, except Fiend-Type monsters, also destroy the targeted cards, and if you do, Special Summon this card (this is a Quick Effect). You can only use this effect of "D/D/D Chaos King Apocalypse" once per turn.
target_text: -- D/D/D
  local SETCARD_ID_0 = 0xaf --D/D
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id)
  	e2:SetRange(LOCATION_HAND + LOCATION_GRAVE)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 2, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 2, 2, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  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.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local ct = -ft + 1
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, 0, 2, nil)
  			and ct <= 2
  			and (ct <= 0 or Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, ct, nil))
  			and not c:IsStatus(STATUS_CHAINING)
  			and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = nil
  	if ct <= 0 then
  		g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 2, 2, nil)
  	elseif ct == 1 then
  		g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g2 = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 1, 1, g:GetFirst())
  		g:Merge(g2)
  	else
  		g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 2, 2, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 2, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 and Duel.Destroy(g, REASON_EFFECT) ~= 0 then
  		local c = e:GetHandler()
  		if not c:IsRelateToEffect(e) then
  			return
  		end
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.splimit(e, c)
  	return c:GetRace() ~= RACE_FIEND
  end
  
  