name: F.A.
card_text: When an opponent's monster declares a direct attack: You can Special Summon 1 "F.A." monster from your Deck. You can only use this effect of "F.A. Dead Heat" once per turn. Once per battle, if your "F.A." monster battles an opponent's monster, before damage calculation: You can have both players roll a six-sided die. If your result is higher, increase the Level of your battling monster by 4, until the end of this turn (even if this card leaves the field). If your result is lower, destroy your battling monster. If it's a tie, both players roll again.
external_ids: local SETCARD_ID_0 = 0x107 --F.A.
  
lua: local SETCARD_ID_0 = 0x107 --F.A.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--atk up
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DICE + CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_BATTLE_CONFIRM)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.lvlcon)
  	e3:SetOperation(s.lvlop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.lvlcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if tc:IsControler(1 - tp) then
  		bc, tc = tc, bc
  	end
  	return bc:IsFaceup() and tc:IsFaceup() and tc:IsSetCard(SETCARD_ID_0)
  end
  function s.lvlop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if tc:IsControler(1 - tp) then
  		bc, tc = tc, bc
  	end
  	local d1 = 0
  	local d2 = 0
  	while d1 == d2 do
  		d1, d2 = Duel.TossDice(tp, 1, 1)
  	end
  	if d1 > d2 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(4)
  		tc:RegisterEffect(e1)
  	else
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  
source_text: F.A.
  When an opponent's monster declares a direct attack: You can Special Summon 1 "F.A." monster from your Deck. You can only use this effect of "F.A. Dead Heat" once per turn. Once per battle, if your "F.A." monster battles an opponent's monster, before damage calculation: You can have both players roll a six-sided die. If your result is higher, increase the Level of your battling monster by 4, until the end of this turn (even if this card leaves the field). If your result is lower, destroy your battling monster. If it's a tie, both players roll again.
target_text: -- F.A.
  local SETCARD_ID_0 = 0x107 --F.A.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--atk up
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DICE + CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_BATTLE_CONFIRM)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.lvlcon)
  	e3:SetOperation(s.lvlop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.lvlcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if tc:IsControler(1 - tp) then
  		bc, tc = tc, bc
  	end
  	return bc:IsFaceup() and tc:IsFaceup() and tc:IsSetCard(SETCARD_ID_0)
  end
  function s.lvlop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if tc:IsControler(1 - tp) then
  		bc, tc = tc, bc
  	end
  	local d1 = 0
  	local d2 = 0
  	while d1 == d2 do
  		d1, d2 = Duel.TossDice(tp, 1, 1)
  	end
  	if d1 > d2 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(4)
  		tc:RegisterEffect(e1)
  	else
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  