name: Lovely
card_text: Your opponent cannot activate monster effects in response to the activation of your Normal Trap Cards. You can only use each of the following effects of "Lovely Labrynth of the Silver Castle" once per turn. You can target 1 Normal Trap in your GY; Set it to your field, but it cannot be activated unless you control a Fiend monster. If another monster(s) leaves the field by your Normal Trap effect (except during the Damage Step): You can destroy 1 card in your opponent's hand (at random) or their field.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--act limit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.chainop)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sttg)
  	e2:SetOperation(s.stop)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.chainop(e, tp, eg, ep, ev, re, r, rp)
  	if re:GetHandler():GetType() == TYPE_TRAP and re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:IsActiveType(TYPE_TRAP) and ep == tp then
  		Duel.SetChainLimit(s.chainlm)
  	end
  end
  function s.chainlm(e, rp, tp)
  	return tp == rp or not e:IsActiveType(TYPE_MONSTER)
  end
  function s.stfilter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSSetable()
  end
  function s.sttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.stfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.stfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectTarget(tp, s.stfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.stop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SSet(tp, tc) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_TRIGGER)
  		e1:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  		e1:SetDescription(aux.Stringid(id, 2))
  		e1:SetCondition(s.actcon)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.actfilter(c)
  	return c:IsRace(RACE_FIEND) and c:IsFaceup()
  end
  function s.actcon(e)
  	local tp = e:GetHandlerPlayer()
  	return not e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED) and not Duel.IsExistingMatchingCard(s.actfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.cfilter(c)
  	return c:IsPreviousLocation(LOCATION_MZONE) and c:IsReason(REASON_EFFECT)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return re and rp == tp and re:IsActiveType(TYPE_TRAP) and re:GetHandler():GetOriginalType() == TYPE_TRAP and eg:IsExists(s.cfilter, 1, nil)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD + LOCATION_HAND) > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, nil, 1, 1 - tp, LOCATION_ONFIELD + LOCATION_HAND)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local hg = Duel.GetFieldGroup(tp, 0, LOCATION_HAND)
  	local fg = Duel.GetFieldGroup(tp, 0, LOCATION_ONFIELD)
  	local g
  	if #hg > 0 and (#fg == 0 or Duel.SelectOption(tp, aux.Stringid(id, 3), aux.Stringid(id, 4)) == 0) then
  		g = hg:RandomSelect(tp, 1)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		g = Duel.SelectMatchingCard(tp, nil, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	end
  	if g:GetCount() ~= 0 then
  		Duel.HintSelection(g)
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  
source_text: Lovely
  Your opponent cannot activate monster effects in response to the activation of your Normal Trap Cards. You can only use each of the following effects of "Lovely Labrynth of the Silver Castle" once per turn. You can target 1 Normal Trap in your GY; Set it to your field, but it cannot be activated unless you control a Fiend monster. If another monster(s) leaves the field by your Normal Trap effect (except during the Damage Step): You can destroy 1 card in your opponent's hand (at random) or their field.
target_text: -- Lovely
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--act limit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.chainop)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sttg)
  	e2:SetOperation(s.stop)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.chainop(e, tp, eg, ep, ev, re, r, rp)
  	if re:GetHandler():GetType() == TYPE_TRAP and re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:IsActiveType(TYPE_TRAP) and ep == tp then
  		Duel.SetChainLimit(s.chainlm)
  	end
  end
  function s.chainlm(e, rp, tp)
  	return tp == rp or not e:IsActiveType(TYPE_MONSTER)
  end
  function s.stfilter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSSetable()
  end
  function s.sttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.stfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.stfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectTarget(tp, s.stfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.stop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SSet(tp, tc) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_TRIGGER)
  		e1:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  		e1:SetDescription(aux.Stringid(id, 2))
  		e1:SetCondition(s.actcon)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.actfilter(c)
  	return c:IsRace(RACE_FIEND) and c:IsFaceup()
  end
  function s.actcon(e)
  	local tp = e:GetHandlerPlayer()
  	return not e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED) and not Duel.IsExistingMatchingCard(s.actfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.cfilter(c)
  	return c:IsPreviousLocation(LOCATION_MZONE) and c:IsReason(REASON_EFFECT)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return re and rp == tp and re:IsActiveType(TYPE_TRAP) and re:GetHandler():GetOriginalType() == TYPE_TRAP and eg:IsExists(s.cfilter, 1, nil)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD + LOCATION_HAND) > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, nil, 1, 1 - tp, LOCATION_ONFIELD + LOCATION_HAND)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local hg = Duel.GetFieldGroup(tp, 0, LOCATION_HAND)
  	local fg = Duel.GetFieldGroup(tp, 0, LOCATION_ONFIELD)
  	local g
  	if #hg > 0 and (#fg == 0 or Duel.SelectOption(tp, aux.Stringid(id, 3), aux.Stringid(id, 4)) == 0) then
  		g = hg:RandomSelect(tp, 1)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		g = Duel.SelectMatchingCard(tp, nil, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	end
  	if g:GetCount() ~= 0 then
  		Duel.HintSelection(g)
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  