name: Gizmek
card_text: Each time your opponent Normal or Special Summons a monster(s): Inflict 300 damage to them. You can only use each of the following effects of "Gizmek Uka, the Festive Fox of Fecundity" once per turn.
  ● If a monster(s) is Special Summoned from the Main Deck (except during the Damage Step): You can Special Summon this card from your hand.
  ● If this card is Normal or Special Summoned: You can target 1 face-up monster your opponent controls; Special Summon 1 monster from your hand or Deck whose ATK equals its own DEF, with a same Attribute as that monster.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon1
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon1)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--spsummon2
  	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:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetCategory(CATEGORY_DAMAGE)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_SUMMON_SUCCESS)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.damcon)
  	e4:SetTarget(s.damtg)
  	e4:SetOperation(s.damop)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e5)
  end
  function s.filter(c)
  	return c:IsSummonLocation(LOCATION_DECK)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.filter, 1, nil)
  end
  function s.sptg1(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.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, e, tp)
  	return c:IsFaceup() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp, c:GetAttribute())
  end
  function s.spfilter(c, e, tp, attr)
  	return aux.AtkEqualsDef(c) and c:IsAttribute(attr) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.cfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.cfilter, tp, 0, LOCATION_MZONE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.cfilter, tp, 0, LOCATION_MZONE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local attr = tc:GetAttribute()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp, attr)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.damfilter(c, tp)
  	return c:IsSummonPlayer(1 - tp)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.damfilter, 1, nil, tp)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, 300)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Damage(1 - tp, 300, REASON_EFFECT)
  end
  
  
source_text: Gizmek
  Each time your opponent Normal or Special Summons a monster(s): Inflict 300 damage to them. You can only use each of the following effects of "Gizmek Uka, the Festive Fox of Fecundity" once per turn.
  ● If a monster(s) is Special Summoned from the Main Deck (except during the Damage Step): You can Special Summon this card from your hand.
  ● If this card is Normal or Special Summoned: You can target 1 face-up monster your opponent controls; Special Summon 1 monster from your hand or Deck whose ATK equals its own DEF, with a same Attribute as that monster.
target_text: -- Gizmek
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon1
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon1)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--spsummon2
  	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:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetCategory(CATEGORY_DAMAGE)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_SUMMON_SUCCESS)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.damcon)
  	e4:SetTarget(s.damtg)
  	e4:SetOperation(s.damop)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e5)
  end
  function s.filter(c)
  	return c:IsSummonLocation(LOCATION_DECK)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.filter, 1, nil)
  end
  function s.sptg1(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.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, e, tp)
  	return c:IsFaceup() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp, c:GetAttribute())
  end
  function s.spfilter(c, e, tp, attr)
  	return aux.AtkEqualsDef(c) and c:IsAttribute(attr) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.cfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.cfilter, tp, 0, LOCATION_MZONE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.cfilter, tp, 0, LOCATION_MZONE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local attr = tc:GetAttribute()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp, attr)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.damfilter(c, tp)
  	return c:IsSummonPlayer(1 - tp)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.damfilter, 1, nil, tp)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, 300)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Damage(1 - tp, 300, REASON_EFFECT)
  end
  
  