name: Emerging
card_text: If your LP is lower than your opponent's: Reveal 3 Beast monsters with 300 ATK and 100 DEF from your Deck, your opponent chooses 1 for you to add to your hand, and you shuffle the rest back into your Deck. You can only activate 1 "Emerging Emergency Rescute Rescue" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) < Duel.GetLP(1 - tp)
  end
  function s.thfilter(c)
  	return c:IsRace(RACE_BEAST) and c:IsAttack(300) and c:IsDefense(100) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 3, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() >= 3 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 3, 3, nil)
  		Duel.ConfirmCards(1 - tp, sg)
  		Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_ATOHAND)
  		local tg = sg:Select(1 - tp, 1, 1, nil)
  		tg:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Emerging
  If your LP is lower than your opponent's: Reveal 3 Beast monsters with 300 ATK and 100 DEF from your Deck, your opponent chooses 1 for you to add to your hand, and you shuffle the rest back into your Deck. You can only activate 1 "Emerging Emergency Rescute Rescue" per turn.
target_text: -- Emerging
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) < Duel.GetLP(1 - tp)
  end
  function s.thfilter(c)
  	return c:IsRace(RACE_BEAST) and c:IsAttack(300) and c:IsDefense(100) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 3, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() >= 3 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 3, 3, nil)
  		Duel.ConfirmCards(1 - tp, sg)
  		Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_ATOHAND)
  		local tg = sg:Select(1 - tp, 1, 1, nil)
  		tg:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  	end
  end
  
  