name: D/D/D
card_text: 2 "D/D" monsters
  If this card is Special Summoned: You can activate this effect; you cannot Special Summon monsters for the rest of this turn, except "D/D" monsters, also place 2 "D/D" Pendulum Monsters with different names from your Deck in your Pendulum Zones, and if you do, take 1000 damage. If this Link Summoned card is destroyed by battle with an opponent's attacking monster, or by an opponent's card effect while in its owner's Monster Zone: You can Special Summon 1 "D/D" monster from your Extra Deck or GY in Defense Position. You can only use each effect of "D/D/D Abyss King Gilgamesh" 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)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 2)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.settg)
  	e1:SetOperation(s.setop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.setfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and not c:IsForbidden()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.setfilter, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return Duel.CheckLocation(tp, LOCATION_PZONE, 0) and Duel.CheckLocation(tp, LOCATION_PZONE, 1) and g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, tp, 1000)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	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)
  	if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) or not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.GetMatchingGroup(s.setfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	local tc1 = g1:GetFirst()
  	local tc2 = g1:GetNext()
  	if Duel.MoveToField(tc1, tp, tp, LOCATION_PZONE, POS_FACEUP, false) then
  		if Duel.MoveToField(tc2, tp, tp, LOCATION_PZONE, POS_FACEUP, false) then
  			Duel.Damage(tp, 1000, REASON_EFFECT)
  			tc2:SetStatus(STATUS_EFFECT_ENABLED, true)
  		end
  		tc1:SetStatus(STATUS_EFFECT_ENABLED, true)
  	end
  end
  function s.splimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousControler(tp)
  		and c:IsSummonType(SUMMON_TYPE_LINK)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and (c:IsReason(REASON_EFFECT) and rp == 1 - tp or c:IsReason(REASON_BATTLE) and Duel.GetAttacker():IsControler(1 - tp))
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  		and (c:IsLocation(LOCATION_GRAVE) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  
source_text: D/D/D
  2 "D/D" monsters
  If this card is Special Summoned: You can activate this effect; you cannot Special Summon monsters for the rest of this turn, except "D/D" monsters, also place 2 "D/D" Pendulum Monsters with different names from your Deck in your Pendulum Zones, and if you do, take 1000 damage. If this Link Summoned card is destroyed by battle with an opponent's attacking monster, or by an opponent's card effect while in its owner's Monster Zone: You can Special Summon 1 "D/D" monster from your Extra Deck or GY in Defense Position. You can only use each effect of "D/D/D Abyss King Gilgamesh" 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)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 2)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.settg)
  	e1:SetOperation(s.setop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.setfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and not c:IsForbidden()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.setfilter, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return Duel.CheckLocation(tp, LOCATION_PZONE, 0) and Duel.CheckLocation(tp, LOCATION_PZONE, 1) and g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, tp, 1000)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	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)
  	if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) or not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.GetMatchingGroup(s.setfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	local tc1 = g1:GetFirst()
  	local tc2 = g1:GetNext()
  	if Duel.MoveToField(tc1, tp, tp, LOCATION_PZONE, POS_FACEUP, false) then
  		if Duel.MoveToField(tc2, tp, tp, LOCATION_PZONE, POS_FACEUP, false) then
  			Duel.Damage(tp, 1000, REASON_EFFECT)
  			tc2:SetStatus(STATUS_EFFECT_ENABLED, true)
  		end
  		tc1:SetStatus(STATUS_EFFECT_ENABLED, true)
  	end
  end
  function s.splimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousControler(tp)
  		and c:IsSummonType(SUMMON_TYPE_LINK)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and (c:IsReason(REASON_EFFECT) and rp == 1 - tp or c:IsReason(REASON_BATTLE) and Duel.GetAttacker():IsControler(1 - tp))
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  		and (c:IsLocation(LOCATION_GRAVE) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  