name: Necklace
card_text: When a monster you control that's equipped with this card is destroyed by battle, and this card is sent to the Graveyard, you can either:
  ● Draw 1 card. OR
  ● Discard 1 random card from your opponent's hand.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Equip limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_EQUIP_LIMIT)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--effect
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCondition(s.effcon)
  	e3:SetTarget(s.efftg)
  	e3:SetOperation(s.effop)
  	c:RegisterEffect(e3)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.effcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	return c:IsReason(REASON_LOST_TARGET) and ec:IsReason(REASON_BATTLE) and ec:IsPreviousControler(tp)
  end
  function s.efftg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local opt = 0
  	local b1 = Duel.IsPlayerCanDraw(tp, 1)
  	local b2 = Duel.GetFieldGroupCount(tp, 0, LOCATION_HAND) > 0
  	if b1 and b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	elseif b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	else
  		opt = 2
  	end
  	e:SetLabel(opt)
  	if opt == 0 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetTargetParam(1)
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	elseif opt == 1 then
  		e:SetCategory(CATEGORY_HANDES)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		Duel.SetTargetPlayer(1 - tp)
  		Duel.SetTargetParam(1)
  		Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, 1 - tp, 1)
  	else
  		e:SetCategory(0)
  		e:SetProperty(0)
  	end
  end
  function s.effop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		Duel.Draw(p, d, REASON_EFFECT)
  	elseif e:GetLabel() == 1 then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		local g = Duel.GetFieldGroup(p, LOCATION_HAND, 0):RandomSelect(p, d)
  		Duel.SendtoGrave(g, REASON_EFFECT + REASON_DISCARD)
  	end
  end
  
  
source_text: Necklace
  When a monster you control that's equipped with this card is destroyed by battle, and this card is sent to the Graveyard, you can either:
  ● Draw 1 card. OR
  ● Discard 1 random card from your opponent's hand.
target_text: -- Necklace
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Equip limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_EQUIP_LIMIT)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--effect
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCondition(s.effcon)
  	e3:SetTarget(s.efftg)
  	e3:SetOperation(s.effop)
  	c:RegisterEffect(e3)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.effcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	return c:IsReason(REASON_LOST_TARGET) and ec:IsReason(REASON_BATTLE) and ec:IsPreviousControler(tp)
  end
  function s.efftg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local opt = 0
  	local b1 = Duel.IsPlayerCanDraw(tp, 1)
  	local b2 = Duel.GetFieldGroupCount(tp, 0, LOCATION_HAND) > 0
  	if b1 and b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	elseif b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	else
  		opt = 2
  	end
  	e:SetLabel(opt)
  	if opt == 0 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetTargetParam(1)
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	elseif opt == 1 then
  		e:SetCategory(CATEGORY_HANDES)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		Duel.SetTargetPlayer(1 - tp)
  		Duel.SetTargetParam(1)
  		Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, 1 - tp, 1)
  	else
  		e:SetCategory(0)
  		e:SetProperty(0)
  	end
  end
  function s.effop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		Duel.Draw(p, d, REASON_EFFECT)
  	elseif e:GetLabel() == 1 then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		local g = Duel.GetFieldGroup(p, LOCATION_HAND, 0):RandomSelect(p, d)
  		Duel.SendtoGrave(g, REASON_EFFECT + REASON_DISCARD)
  	end
  end
  
  