name: Madolche
card_text: During your Main Phase, you can Normal Summon 1 "Madolche" monster in addition to your Normal Summon/Set. (You can only gain this effect once per turn.) If another "Madolche" card(s) you control or in your GY is added to your hand or shuffled into your Main Deck by a card effect: Set 1 "Madolche" Spell/Trap directly from your Deck, except "Madolche Salon". You can only use this effect of "Madolche Salon" once per turn.
external_ids: local SETCARD_ID_0 = 0x71 --Madolche
  
lua: local SETCARD_ID_0 = 0x71 --Madolche
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--extra summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_HAND + LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_TO_HAND)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.secon)
  	e3:SetOperation(s.seop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_TO_DECK)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsControler(tp)
  		and c:IsPreviousControler(tp)
  		and (c:IsPreviousLocation(LOCATION_GRAVE) or (c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousPosition(POS_FACEUP)))
  		and c:IsSetCard(SETCARD_ID_0)
  		and not c:IsLocation(LOCATION_EXTRA)
  end
  function s.secon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.sefilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsSSetable() and not c:IsCode(id)
  end
  function s.seop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.sefilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SSet(tp, g)
  	end
  end
  
  
source_text: Madolche
  During your Main Phase, you can Normal Summon 1 "Madolche" monster in addition to your Normal Summon/Set. (You can only gain this effect once per turn.) If another "Madolche" card(s) you control or in your GY is added to your hand or shuffled into your Main Deck by a card effect: Set 1 "Madolche" Spell/Trap directly from your Deck, except "Madolche Salon". You can only use this effect of "Madolche Salon" once per turn.
target_text: -- Madolche
  local SETCARD_ID_0 = 0x71 --Madolche
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--extra summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_HAND + LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_TO_HAND)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.secon)
  	e3:SetOperation(s.seop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_TO_DECK)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsControler(tp)
  		and c:IsPreviousControler(tp)
  		and (c:IsPreviousLocation(LOCATION_GRAVE) or (c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousPosition(POS_FACEUP)))
  		and c:IsSetCard(SETCARD_ID_0)
  		and not c:IsLocation(LOCATION_EXTRA)
  end
  function s.secon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.sefilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsSSetable() and not c:IsCode(id)
  end
  function s.seop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.sefilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SSet(tp, g)
  	end
  end
  
  