name: Tri-Brigade
card_text: If a Beast, Beast-Warrior, or Winged Beast monster is Special Summoned to your field (except during the Damage Step): You can target 1 of your banished "Tri-Brigade" monsters; add it to your hand. After damage calculation, if your "Tri-Brigade" monster battled an opponent's monster: You can return the opponent's monster to the hand. You can only use each effect of "Tri-Brigade Showdown" once per turn.
external_ids: local SETCARD_ID_0 = 0x14d --Tri-Brigade
  
lua: local SETCARD_ID_0 = 0x14d --Tri-Brigade
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--tohand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--battle
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.bacon)
  	e2:SetTarget(s.batg)
  	e2:SetOperation(s.baop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, tp)
  	return c:IsFaceup() and c:IsRace(RACE_BEAST + RACE_BEASTWARRIOR + RACE_WINDBEAST) and c:IsControler(tp)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.bacon(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if not ac:IsControler(tp) then
  		ac, bc = bc, ac
  	end
  	e:SetLabelObject(bc)
  	return ac:IsFaceup() and ac:IsControler(tp) and ac:IsSetCard(SETCARD_ID_0) and bc:IsControler(1 - tp)
  end
  function s.batg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if not bc then
  		return false
  	end
  	if chk == 0 then
  		return bc:IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, bc, 1, 0, 0)
  end
  function s.baop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc and bc:IsRelateToBattle() and bc:IsControler(1 - tp) then
  		Duel.SendtoHand(bc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Tri-Brigade
  If a Beast, Beast-Warrior, or Winged Beast monster is Special Summoned to your field (except during the Damage Step): You can target 1 of your banished "Tri-Brigade" monsters; add it to your hand. After damage calculation, if your "Tri-Brigade" monster battled an opponent's monster: You can return the opponent's monster to the hand. You can only use each effect of "Tri-Brigade Showdown" once per turn.
target_text: -- Tri-Brigade
  local SETCARD_ID_0 = 0x14d --Tri-Brigade
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--tohand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--battle
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.bacon)
  	e2:SetTarget(s.batg)
  	e2:SetOperation(s.baop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, tp)
  	return c:IsFaceup() and c:IsRace(RACE_BEAST + RACE_BEASTWARRIOR + RACE_WINDBEAST) and c:IsControler(tp)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.bacon(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if not ac:IsControler(tp) then
  		ac, bc = bc, ac
  	end
  	e:SetLabelObject(bc)
  	return ac:IsFaceup() and ac:IsControler(tp) and ac:IsSetCard(SETCARD_ID_0) and bc:IsControler(1 - tp)
  end
  function s.batg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if not bc then
  		return false
  	end
  	if chk == 0 then
  		return bc:IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, bc, 1, 0, 0)
  end
  function s.baop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc and bc:IsRelateToBattle() and bc:IsControler(1 - tp) then
  		Duel.SendtoHand(bc, nil, REASON_EFFECT)
  	end
  end
  
  