name: Rescue-ACE
card_text: While you control a "Rescue-ACE" monster other than "Rescue-ACE Hydrant", your opponent's monsters cannot target this card for attacks, also your opponent cannot target this card with card effects. You can only use each of the following effects of "Rescue-ACE Hydrant" once per turn. You can activate a Quick-Play Spell, or Trap Card, that was Set by the effect of your "Rescue-ACE" card, the turn it was Set. During your Main Phase: You can add 1 "Rescue-ACE" monster from your Deck to your hand, except "Rescue-ACE Hydrant".
external_ids: local SETCARD_ID_0 = 0x18b --Rescue-ACE
  
lua: local SETCARD_ID_0 = 0x18b --Rescue-ACE
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot be battle and effect target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e1:SetCondition(s.atkcon)
  	e1:SetValue(aux.imval1)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  	--quick activate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_TRAP_ACT_IN_SET_TURN)
  	e3:SetTargetRange(LOCATION_SZONE, 0)
  	e3:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.qfilter)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_QP_ACT_IN_SET_TURN)
  	c:RegisterEffect(e4)
  	--search
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1, id + o)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_SSET)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if not re or not re:GetHandler():IsSetCard(SETCARD_ID_0) then
  		return
  	end
  	local tc = eg:GetFirst()
  	while tc do
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  		tc = eg:GetNext()
  	end
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id)
  end
  function s.atkcon(e)
  	return Duel.IsExistingMatchingCard(s.atkfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
  end
  function s.qfilter(e, c)
  	return c:GetFlagEffect(id) > 0
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and not c:IsCode(id)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Rescue-ACE
  While you control a "Rescue-ACE" monster other than "Rescue-ACE Hydrant", your opponent's monsters cannot target this card for attacks, also your opponent cannot target this card with card effects. You can only use each of the following effects of "Rescue-ACE Hydrant" once per turn. You can activate a Quick-Play Spell, or Trap Card, that was Set by the effect of your "Rescue-ACE" card, the turn it was Set. During your Main Phase: You can add 1 "Rescue-ACE" monster from your Deck to your hand, except "Rescue-ACE Hydrant".
target_text: -- Rescue-ACE
  local SETCARD_ID_0 = 0x18b --Rescue-ACE
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot be battle and effect target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e1:SetCondition(s.atkcon)
  	e1:SetValue(aux.imval1)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  	--quick activate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_TRAP_ACT_IN_SET_TURN)
  	e3:SetTargetRange(LOCATION_SZONE, 0)
  	e3:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.qfilter)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_QP_ACT_IN_SET_TURN)
  	c:RegisterEffect(e4)
  	--search
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1, id + o)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_SSET)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if not re or not re:GetHandler():IsSetCard(SETCARD_ID_0) then
  		return
  	end
  	local tc = eg:GetFirst()
  	while tc do
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  		tc = eg:GetNext()
  	end
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id)
  end
  function s.atkcon(e)
  	return Duel.IsExistingMatchingCard(s.atkfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
  end
  function s.qfilter(e, c)
  	return c:GetFlagEffect(id) > 0
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and not c:IsCode(id)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  