name: Graydle
card_text: If this card in your Monster Zone is destroyed by battle or monster effect and sent to your Graveyard: You can target 1 face-up monster your opponent controls; equip this card to that target. While this card is equipped to a monster by this effect, take control of that monster. When this card leaves the field, destroy the equipped monster.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP + CATEGORY_LEAVE_GRAVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.eqcon)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  end
  function s.eqcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and re:IsActiveType(TYPE_MONSTER)))
  		and c:IsReason(REASON_DESTROY)
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.eqfilter(c, tp)
  	if c:IsFacedown() then
  		return false
  	end
  	if c:IsType(TYPE_TRAPMONSTER) then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE, tp, LOCATION_REASON_CONTROL) > 0 and Duel.GetLocationCount(tp, LOCATION_SZONE, tp, 0) >= 2
  	end
  	return true
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.eqfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.eqfilter, tp, 0, LOCATION_MZONE, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.eqfilter, tp, 0, LOCATION_MZONE, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) and tc:IsControler(1 - tp) then
  		Duel.Equip(tp, c, tc)
  		--Add Equip limit
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(s.eqlimit)
  		e1:SetLabelObject(tc)
  		c:RegisterEffect(e1)
  		--control
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_EQUIP)
  		e2:SetCode(EFFECT_SET_CONTROL)
  		e2:SetValue(tp)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e2)
  		--Destroy
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  		e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e3:SetCode(EVENT_LEAVE_FIELD_P)
  		e3:SetOperation(s.checkop)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e3)
  		local e4 = Effect.CreateEffect(c)
  		e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  		e4:SetCode(EVENT_LEAVE_FIELD)
  		e4:SetOperation(s.desop)
  		e4:SetReset(RESET_EVENT + RESET_OVERLAY + RESET_TOFIELD)
  		e4:SetLabelObject(e3)
  		c:RegisterEffect(e4)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsDisabled() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	e:Reset()
  	if e:GetLabelObject():GetLabel() ~= 0 then
  		return
  	end
  	local tc = e:GetHandler():GetEquipTarget()
  	if tc and tc:IsLocation(LOCATION_MZONE) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  
source_text: Graydle
  If this card in your Monster Zone is destroyed by battle or monster effect and sent to your Graveyard: You can target 1 face-up monster your opponent controls; equip this card to that target. While this card is equipped to a monster by this effect, take control of that monster. When this card leaves the field, destroy the equipped monster.
target_text: -- Graydle
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP + CATEGORY_LEAVE_GRAVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.eqcon)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  end
  function s.eqcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and re:IsActiveType(TYPE_MONSTER)))
  		and c:IsReason(REASON_DESTROY)
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.eqfilter(c, tp)
  	if c:IsFacedown() then
  		return false
  	end
  	if c:IsType(TYPE_TRAPMONSTER) then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE, tp, LOCATION_REASON_CONTROL) > 0 and Duel.GetLocationCount(tp, LOCATION_SZONE, tp, 0) >= 2
  	end
  	return true
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.eqfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.eqfilter, tp, 0, LOCATION_MZONE, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.eqfilter, tp, 0, LOCATION_MZONE, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) and tc:IsControler(1 - tp) then
  		Duel.Equip(tp, c, tc)
  		--Add Equip limit
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(s.eqlimit)
  		e1:SetLabelObject(tc)
  		c:RegisterEffect(e1)
  		--control
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_EQUIP)
  		e2:SetCode(EFFECT_SET_CONTROL)
  		e2:SetValue(tp)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e2)
  		--Destroy
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  		e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e3:SetCode(EVENT_LEAVE_FIELD_P)
  		e3:SetOperation(s.checkop)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e3)
  		local e4 = Effect.CreateEffect(c)
  		e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  		e4:SetCode(EVENT_LEAVE_FIELD)
  		e4:SetOperation(s.desop)
  		e4:SetReset(RESET_EVENT + RESET_OVERLAY + RESET_TOFIELD)
  		e4:SetLabelObject(e3)
  		c:RegisterEffect(e4)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsDisabled() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	e:Reset()
  	if e:GetLabelObject():GetLabel() ~= 0 then
  		return
  	end
  	local tc = e:GetHandler():GetEquipTarget()
  	if tc and tc:IsLocation(LOCATION_MZONE) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  