name: S-Force
card_text: When this card is activated: You can add 1 "S-Force" monster from your Deck to your hand. When an opponent's monster declares an attack on your "S-Force" monster in its same column: You can activate this effect; that monster you control cannot be destroyed by that battle. You can only use this effect of "S-Force Bridgehead" once per turn. You can only activate 1 "S-Force Bridgehead" per turn.
external_ids: local SETCARD_ID_0 = 0x156 --S-Force
  
lua: local SETCARD_ID_0 = 0x156 --S-Force
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--indes battle
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.indcon)
  	e2:SetTarget(s.indtg)
  	e2:SetOperation(s.indop)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  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() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	local cg = ac:GetColumnGroup()
  	e:SetLabelObject(bc)
  	return ac:IsControler(1 - tp) and cg:IsContains(bc) and bc:IsFaceup() and bc:IsSetCard(SETCARD_ID_0) and bc:IsControler(tp)
  end
  function s.indtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if chk == 0 then
  		return bc and bc:IsRelateToBattle()
  	end
  end
  function s.indop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc and bc:IsRelateToBattle() and bc:IsControler(tp) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  		bc:RegisterEffect(e1)
  	end
  end
  
  
source_text: S-Force
  When this card is activated: You can add 1 "S-Force" monster from your Deck to your hand. When an opponent's monster declares an attack on your "S-Force" monster in its same column: You can activate this effect; that monster you control cannot be destroyed by that battle. You can only use this effect of "S-Force Bridgehead" once per turn. You can only activate 1 "S-Force Bridgehead" per turn.
target_text: -- S-Force
  local SETCARD_ID_0 = 0x156 --S-Force
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--indes battle
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.indcon)
  	e2:SetTarget(s.indtg)
  	e2:SetOperation(s.indop)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  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() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	local cg = ac:GetColumnGroup()
  	e:SetLabelObject(bc)
  	return ac:IsControler(1 - tp) and cg:IsContains(bc) and bc:IsFaceup() and bc:IsSetCard(SETCARD_ID_0) and bc:IsControler(tp)
  end
  function s.indtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if chk == 0 then
  		return bc and bc:IsRelateToBattle()
  	end
  end
  function s.indop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc and bc:IsRelateToBattle() and bc:IsControler(tp) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  		bc:RegisterEffect(e1)
  	end
  end
  
  