name: Lyrilusc
card_text: 2+ Level 1 monsters
  Gains 500 ATK for each material attached to it. If your opponent Special Summons a monster(s) (except during the Damage Step): You can detach 1 material from this card, then target 1 of those Special Summoned monsters; return it to the hand. If this card in your possession is sent to your GY by an opponent's card: You can target 1 other "Lyrilusc" monster in your GY; add it to your hand.
external_ids: local SETCARD_ID_0 = 0xf7 --Lyrilusc
  
lua: local SETCARD_ID_0 = 0xf7 --Lyrilusc
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddXyzProcedure(c, nil, 1, 2, nil, nil, 99)
  	--ATK Up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(s.atkval)
  	c:RegisterEffect(e1)
  	--to hand
  	local custom_code = aux.RegisterMergedDelayedEvent_ToSingleCard(c, id, EVENT_SPSUMMON_SUCCESS)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(custom_code)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e2:SetCondition(s.thcon)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	--recover
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.recon)
  	e3:SetTarget(s.retg)
  	e3:SetOperation(s.reop)
  	c:RegisterEffect(e3)
  end
  function s.atkval(e, c)
  	return c:GetOverlayCount() * 500
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsSummonPlayer, 1, nil, 1 - tp)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.thfilter(c, tp)
  	return c:IsSummonPlayer(1 - tp) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local g = eg:Filter(s.thfilter, nil, tp)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and aux.IsInGroup(chkc, g)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.IsInGroup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, g)
  	end
  	local sg
  	if g:GetCount() == 1 then
  		sg = g:Clone()
  		Duel.SetTargetCard(sg)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  		sg = Duel.SelectTarget(tp, aux.IsInGroup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, g)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, sg, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.recon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return rp == 1 - tp and c:IsPreviousControler(tp)
  end
  function s.filter2(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.retg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter2(chkc) and chkc ~= e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter2, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_GRAVE, 0, 1, 1, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.reop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Lyrilusc
  2+ Level 1 monsters
  Gains 500 ATK for each material attached to it. If your opponent Special Summons a monster(s) (except during the Damage Step): You can detach 1 material from this card, then target 1 of those Special Summoned monsters; return it to the hand. If this card in your possession is sent to your GY by an opponent's card: You can target 1 other "Lyrilusc" monster in your GY; add it to your hand.
target_text: -- Lyrilusc
  local SETCARD_ID_0 = 0xf7 --Lyrilusc
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddXyzProcedure(c, nil, 1, 2, nil, nil, 99)
  	--ATK Up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(s.atkval)
  	c:RegisterEffect(e1)
  	--to hand
  	local custom_code = aux.RegisterMergedDelayedEvent_ToSingleCard(c, id, EVENT_SPSUMMON_SUCCESS)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(custom_code)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e2:SetCondition(s.thcon)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	--recover
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.recon)
  	e3:SetTarget(s.retg)
  	e3:SetOperation(s.reop)
  	c:RegisterEffect(e3)
  end
  function s.atkval(e, c)
  	return c:GetOverlayCount() * 500
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsSummonPlayer, 1, nil, 1 - tp)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.thfilter(c, tp)
  	return c:IsSummonPlayer(1 - tp) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local g = eg:Filter(s.thfilter, nil, tp)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and aux.IsInGroup(chkc, g)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.IsInGroup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, g)
  	end
  	local sg
  	if g:GetCount() == 1 then
  		sg = g:Clone()
  		Duel.SetTargetCard(sg)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  		sg = Duel.SelectTarget(tp, aux.IsInGroup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, g)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, sg, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.recon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return rp == 1 - tp and c:IsPreviousControler(tp)
  end
  function s.filter2(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.retg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter2(chkc) and chkc ~= e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter2, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_GRAVE, 0, 1, 1, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.reop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  