name: Alpha,
card_text: Cannot be Normal Summoned/Set. Must first be Special Summoned (from your hand) while the total ATK of all monsters your opponent controls is more than that of all monsters you control. You can target any number of Beast, Beast-Warrior, and/or Winged Beast monsters you control; return them to the hand, then, return face-up monsters your opponent controls to the hand, equal to the number of cards you returned to the hand, also for the rest of this turn, "Alpha, the Master of Beasts" you control cannot attack directly. You can only use this effect of "Alpha, the Master of Beasts" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.sprcon)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return false
  	end
  	local g1 = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	return g1:GetSum(Card.GetAttack) < g2:GetSum(Card.GetAttack)
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_BEAST + RACE_BEASTWARRIOR + RACE_WINDBEAST) and c:IsAbleToHand()
  end
  function s.thfilter1(c, e)
  	return s.thfilter(c) and c:IsCanBeEffectTarget(e)
  end
  function s.thfilter2(c)
  	return c:IsFaceup() and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	local ct1 = Duel.GetMatchingGroupCount(s.thfilter1, tp, LOCATION_MZONE, 0, nil, e)
  	local ct2 = Duel.GetMatchingGroupCount(s.thfilter2, tp, 0, LOCATION_MZONE, nil)
  	if chk == 0 then
  		return ct1 > 0 and ct2 > 0
  	end
  	local ct = math.min(ct1, ct2)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_MZONE, 0, 1, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, #g, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		local ct = og:FilterCount(Card.IsLocation, nil, LOCATION_HAND)
  		if ct > 0 and Duel.IsExistingMatchingCard(s.thfilter2, tp, 0, LOCATION_MZONE, ct, nil) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  			local hg = Duel.SelectMatchingCard(tp, s.thfilter2, tp, 0, LOCATION_MZONE, ct, ct, nil)
  			Duel.HintSelection(hg)
  			Duel.SendtoHand(hg, nil, REASON_EFFECT)
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsCode, id))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  
  
source_text: Alpha,
  Cannot be Normal Summoned/Set. Must first be Special Summoned (from your hand) while the total ATK of all monsters your opponent controls is more than that of all monsters you control. You can target any number of Beast, Beast-Warrior, and/or Winged Beast monsters you control; return them to the hand, then, return face-up monsters your opponent controls to the hand, equal to the number of cards you returned to the hand, also for the rest of this turn, "Alpha, the Master of Beasts" you control cannot attack directly. You can only use this effect of "Alpha, the Master of Beasts" once per turn.
target_text: -- Alpha,
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.sprcon)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return false
  	end
  	local g1 = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	return g1:GetSum(Card.GetAttack) < g2:GetSum(Card.GetAttack)
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_BEAST + RACE_BEASTWARRIOR + RACE_WINDBEAST) and c:IsAbleToHand()
  end
  function s.thfilter1(c, e)
  	return s.thfilter(c) and c:IsCanBeEffectTarget(e)
  end
  function s.thfilter2(c)
  	return c:IsFaceup() and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	local ct1 = Duel.GetMatchingGroupCount(s.thfilter1, tp, LOCATION_MZONE, 0, nil, e)
  	local ct2 = Duel.GetMatchingGroupCount(s.thfilter2, tp, 0, LOCATION_MZONE, nil)
  	if chk == 0 then
  		return ct1 > 0 and ct2 > 0
  	end
  	local ct = math.min(ct1, ct2)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_MZONE, 0, 1, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, #g, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		local ct = og:FilterCount(Card.IsLocation, nil, LOCATION_HAND)
  		if ct > 0 and Duel.IsExistingMatchingCard(s.thfilter2, tp, 0, LOCATION_MZONE, ct, nil) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  			local hg = Duel.SelectMatchingCard(tp, s.thfilter2, tp, 0, LOCATION_MZONE, ct, ct, nil)
  			Duel.HintSelection(hg)
  			Duel.SendtoHand(hg, nil, REASON_EFFECT)
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsCode, id))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  
  