name: Kuribah
card_text: (This card is always treated as a "Kuriboh" card.)
  When this card, or another "Kuriboh" monster, you control is destroyed by battle: You can Special Summon 1 monster with 300 ATK/200 DEF from your Deck, except "Kuribah". You can only use this effect of "Kuribah" once per turn. You can Tribute this card you control and 1 each of "Kuribee", "Kuriboo", "Kuribeh" and "Kuriboh" from your hand and/or field; Special Summon 1 "Kuribabylon" from your hand, Deck, or GY.
external_ids: local CARD_ID_0 = 7021574 --Kuriboo
  local CARD_ID_1 = 34419588 --Kuribeh
  local CARD_ID_2 = 71036835 --Kuribee
  local CARD_ID_3 = 40640057 --Kuriboh
  local CARD_ID_4 = 70914287 --Kuribabylon
  local SETCARD_ID_0 = 0xa4 --Kuriboh
  
lua: local CARD_ID_0 = 7021574 --Kuriboo
  local CARD_ID_1 = 34419588 --Kuribeh
  local CARD_ID_2 = 71036835 --Kuribee
  local CARD_ID_3 = 40640057 --Kuriboh
  local CARD_ID_4 = 70914287 --Kuribabylon
  local SETCARD_ID_0 = 0xa4 --Kuriboh
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3)
  	--Destroyed
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BATTLE_DESTROYED)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.spcon)
  	c:RegisterEffect(e2)
  	--Special Summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCost(s.spcost2)
  	e3:SetTarget(s.sptg2)
  	e3:SetOperation(s.spop2)
  	c:RegisterEffect(e3)
  end
  s.spchecks = aux.CreateChecks(Card.IsCode, { CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3 })
  function s.spfilter(c, e, tp)
  	return c:IsDefense(200) and c:IsAttack(300) and not c:IsCode(id) 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 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)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsControler(tp) and c:IsPreviousControler(tp) and c:IsPreviousSetCard(SETCARD_ID_0)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.rlfilter(c, tp)
  	return c:IsCode(CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3) and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.rlcheck(sg, c, tp)
  	local g = sg:Clone()
  	g:AddCard(c)
  	return Duel.GetMZoneCount(tp, g) > 0 and Duel.CheckReleaseGroupEx(tp, aux.IsInGroup, #g, REASON_COST, true, nil, g)
  end
  function s.spcost2(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local g = Duel.GetReleaseGroup(tp, true):Filter(s.rlfilter, c, tp)
  	if chk == 0 then
  		return c:IsReleasable() and g:CheckSubGroupEach(s.spchecks, s.rlcheck, c, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  	local rg = g:SelectSubGroupEach(tp, s.spchecks, false, s.rlcheck, c, tp)
  	aux.UseExtraReleaseCount(rg, tp)
  	rg:AddCard(c)
  	Duel.Release(rg, REASON_COST)
  end
  function s.spfilter2(c, e, tp)
  	return c:IsCode(CARD_ID_4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter2), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Kuribah
  (This card is always treated as a "Kuriboh" card.)
  When this card, or another "Kuriboh" monster, you control is destroyed by battle: You can Special Summon 1 monster with 300 ATK/200 DEF from your Deck, except "Kuribah". You can only use this effect of "Kuribah" once per turn. You can Tribute this card you control and 1 each of "Kuribee", "Kuriboo", "Kuribeh" and "Kuriboh" from your hand and/or field; Special Summon 1 "Kuribabylon" from your hand, Deck, or GY.
target_text: -- Kuribah
  local CARD_ID_0 = 7021574 --Kuriboo
  local CARD_ID_1 = 34419588 --Kuribeh
  local CARD_ID_2 = 71036835 --Kuribee
  local CARD_ID_3 = 40640057 --Kuriboh
  local CARD_ID_4 = 70914287 --Kuribabylon
  local SETCARD_ID_0 = 0xa4 --Kuriboh
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3)
  	--Destroyed
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BATTLE_DESTROYED)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.spcon)
  	c:RegisterEffect(e2)
  	--Special Summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCost(s.spcost2)
  	e3:SetTarget(s.sptg2)
  	e3:SetOperation(s.spop2)
  	c:RegisterEffect(e3)
  end
  s.spchecks = aux.CreateChecks(Card.IsCode, { CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3 })
  function s.spfilter(c, e, tp)
  	return c:IsDefense(200) and c:IsAttack(300) and not c:IsCode(id) 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 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)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsControler(tp) and c:IsPreviousControler(tp) and c:IsPreviousSetCard(SETCARD_ID_0)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.rlfilter(c, tp)
  	return c:IsCode(CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3) and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.rlcheck(sg, c, tp)
  	local g = sg:Clone()
  	g:AddCard(c)
  	return Duel.GetMZoneCount(tp, g) > 0 and Duel.CheckReleaseGroupEx(tp, aux.IsInGroup, #g, REASON_COST, true, nil, g)
  end
  function s.spcost2(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local g = Duel.GetReleaseGroup(tp, true):Filter(s.rlfilter, c, tp)
  	if chk == 0 then
  		return c:IsReleasable() and g:CheckSubGroupEach(s.spchecks, s.rlcheck, c, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  	local rg = g:SelectSubGroupEach(tp, s.spchecks, false, s.rlcheck, c, tp)
  	aux.UseExtraReleaseCount(rg, tp)
  	rg:AddCard(c)
  	Duel.Release(rg, REASON_COST)
  end
  function s.spfilter2(c, e, tp)
  	return c:IsCode(CARD_ID_4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter2), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  