name: B.E.S.
card_text: When this card is Normal Summoned, put 3 counters on it. This card cannot be destroyed by battle. If this card attacks or is attacked, remove 1 counter from this card at the end of the Damage Step. If you cannot, destroy it. Once per turn, during your Main Phase, you can change 1 face-up Attack Position monster your opponent controls to face-up Defense Position.
external_ids: local COUNTER_ID_0 = 0x1f --Counter(B.E.S.)
  
lua: local COUNTER_ID_0 = 0x1f --Counter(B.E.S.)
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x1f)
  	--summon success
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(s.addct)
  	e1:SetOperation(s.addc)
  	c:RegisterEffect(e1)
  	--battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--remove counter
  	aux.EnableBESRemove(c)
  	--pos
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 3))
  	e5:SetCategory(CATEGORY_POSITION)
  	e5:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1)
  	e5:SetTarget(s.postg)
  	e5:SetOperation(s.posop)
  	c:RegisterEffect(e5)
  end
  function s.addct(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 3, 0, 0x1f)
  end
  function s.addc(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsRelateToEffect(e) then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 3)
  	end
  end
  function s.filter(c)
  	return c:IsPosition(POS_FACEUP_ATTACK) and c:IsCanChangePosition()
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsPosition(POS_FACEUP_ATTACK) and tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE)
  	end
  end
  
  
source_text: B.E.S.
  When this card is Normal Summoned, put 3 counters on it. This card cannot be destroyed by battle. If this card attacks or is attacked, remove 1 counter from this card at the end of the Damage Step. If you cannot, destroy it. Once per turn, during your Main Phase, you can change 1 face-up Attack Position monster your opponent controls to face-up Defense Position.
target_text: -- B.E.S.
  local COUNTER_ID_0 = 0x1f --Counter(B.E.S.)
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x1f)
  	--summon success
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(s.addct)
  	e1:SetOperation(s.addc)
  	c:RegisterEffect(e1)
  	--battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--remove counter
  	aux.EnableBESRemove(c)
  	--pos
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 3))
  	e5:SetCategory(CATEGORY_POSITION)
  	e5:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1)
  	e5:SetTarget(s.postg)
  	e5:SetOperation(s.posop)
  	c:RegisterEffect(e5)
  end
  function s.addct(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 3, 0, 0x1f)
  end
  function s.addc(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsRelateToEffect(e) then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 3)
  	end
  end
  function s.filter(c)
  	return c:IsPosition(POS_FACEUP_ATTACK) and c:IsCanChangePosition()
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsPosition(POS_FACEUP_ATTACK) and tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE)
  	end
  end
  
  