Lady
While you control a Set card, your opponent cannot target this card with card effects, also it cannot be destroyed by your opponent's card effects. You can only use each of the following effects of "Lady Labrynth of the Silver Castle" once per turn. If a "Labrynth" card or effect or a Normal Trap Card was activated this turn, except "Lady Labrynth of the Silver Castle" (Quick Effect): You can Special Summon this card from your hand in Defense Position. When a Normal Trap Card is activated (Quick Effect): You can Set 1 Normal Trap with a different name directly from your Deck.
local SETCARD_ID_0 = 0x17e --Labrynth

local SETCARD_ID_0 = 0x17e --Labrynth
local s, id, o = GetID()
function s.initial_effect(c)
	--special summon
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_QUICK_O)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
	e1:SetRange(LOCATION_HAND)
	e1:SetCountLimit(1, id)
	e1:SetCondition(s.spcon)
	e1:SetTarget(s.sptg)
	e1:SetOperation(s.spop)
	c:RegisterEffect(e1)
	--cannot be target/effect indestructable
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCondition(s.dcon)
	e2:SetValue(aux.tgoval)
	c:RegisterEffect(e2)
	local e3 = e2:Clone()
	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
	e3:SetValue(aux.indoval)
	c:RegisterEffect(e3)
	--Trap Set
	local e4 = Effect.CreateEffect(c)
	e4:SetDescription(aux.Stringid(id, 1))
	e4:SetType(EFFECT_TYPE_QUICK_O)
	e4:SetCode(EVENT_CHAINING)
	e4:SetRange(LOCATION_MZONE)
	e4:SetCountLimit(1, id + o)
	e4:SetCondition(s.setcon)
	e4:SetTarget(s.settg)
	e4:SetOperation(s.setop)
	c:RegisterEffect(e4)
	--
	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
end
function s.chainfilter(re, tp, cid)
	local rc = re:GetHandler()
	return rc:IsCode(id) or not ((rc:GetType() == TYPE_TRAP and re:IsHasType(EFFECT_TYPE_ACTIVATE)) or (rc:IsSetCard(SETCARD_ID_0)))
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) > 0 or Duel.GetCustomActivityCount(id, 1 - tp, ACTIVITY_CHAIN) > 0
end
function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
	local c = e:GetHandler()
	if chk == 0 then
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if not c:IsRelateToEffect(e) then
		return
	end
	Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
end
function s.dcon(e)
	return Duel.IsExistingMatchingCard(Card.IsFacedown, e:GetHandlerPlayer(), LOCATION_ONFIELD, 0, 1, nil)
end
function s.setcon(e, tp, eg, ep, ev, re, r, rp)
	local rc = re:GetHandler()
	return rc:GetType() == TYPE_TRAP and re:IsHasType(EFFECT_TYPE_ACTIVATE)
end
function s.setfilter(c, rc)
	return not c:IsCode(rc:GetCode()) and c:GetType() == TYPE_TRAP and c:IsSSetable()
end
function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
	local rc = re:GetHandler()
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, nil, rc)
	end
end
function s.setop(e, tp, eg, ep, ev, re, r, rp)
	local rc = re:GetHandler()
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, nil, rc)
	if g:GetCount() > 0 then
		Duel.SSet(tp, g:GetFirst())
	end
end


Lady
While you control a Set card, your opponent cannot target this card with card effects, also it cannot be destroyed by your opponent's card effects. You can only use each of the following effects of "Lady Labrynth of the Silver Castle" once per turn. If a "Labrynth" card or effect or a Normal Trap Card was activated this turn, except "Lady Labrynth of the Silver Castle" (Quick Effect): You can Special Summon this card from your hand in Defense Position. When a Normal Trap Card is activated (Quick Effect): You can Set 1 Normal Trap with a different name directly from your Deck.
-- Lady
local SETCARD_ID_0 = 0x17e --Labrynth
local s, id, o = GetID()
function s.initial_effect(c)
	--special summon
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_QUICK_O)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
	e1:SetRange(LOCATION_HAND)
	e1:SetCountLimit(1, id)
	e1:SetCondition(s.spcon)
	e1:SetTarget(s.sptg)
	e1:SetOperation(s.spop)
	c:RegisterEffect(e1)
	--cannot be target/effect indestructable
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCondition(s.dcon)
	e2:SetValue(aux.tgoval)
	c:RegisterEffect(e2)
	local e3 = e2:Clone()
	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
	e3:SetValue(aux.indoval)
	c:RegisterEffect(e3)
	--Trap Set
	local e4 = Effect.CreateEffect(c)
	e4:SetDescription(aux.Stringid(id, 1))
	e4:SetType(EFFECT_TYPE_QUICK_O)
	e4:SetCode(EVENT_CHAINING)
	e4:SetRange(LOCATION_MZONE)
	e4:SetCountLimit(1, id + o)
	e4:SetCondition(s.setcon)
	e4:SetTarget(s.settg)
	e4:SetOperation(s.setop)
	c:RegisterEffect(e4)
	--
	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
end
function s.chainfilter(re, tp, cid)
	local rc = re:GetHandler()
	return rc:IsCode(id) or not ((rc:GetType() == TYPE_TRAP and re:IsHasType(EFFECT_TYPE_ACTIVATE)) or (rc:IsSetCard(SETCARD_ID_0)))
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) > 0 or Duel.GetCustomActivityCount(id, 1 - tp, ACTIVITY_CHAIN) > 0
end
function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
	local c = e:GetHandler()
	if chk == 0 then
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if not c:IsRelateToEffect(e) then
		return
	end
	Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
end
function s.dcon(e)
	return Duel.IsExistingMatchingCard(Card.IsFacedown, e:GetHandlerPlayer(), LOCATION_ONFIELD, 0, 1, nil)
end
function s.setcon(e, tp, eg, ep, ev, re, r, rp)
	local rc = re:GetHandler()
	return rc:GetType() == TYPE_TRAP and re:IsHasType(EFFECT_TYPE_ACTIVATE)
end
function s.setfilter(c, rc)
	return not c:IsCode(rc:GetCode()) and c:GetType() == TYPE_TRAP and c:IsSSetable()
end
function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
	local rc = re:GetHandler()
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, nil, rc)
	end
end
function s.setop(e, tp, eg, ep, ev, re, r, rp)
	local rc = re:GetHandler()
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, nil, rc)
	if g:GetCount() > 0 then
		Duel.SSet(tp, g:GetFirst())
	end
end

