name: Ursarctic
card_text: Once per turn, if your "Ursarctic" monster would Tribute a monster(s) to activate its effect, you can banish 1 Level 7 or higher "Ursarctic" monster from your GY instead. Each time a monster(s) is Special Summoned, place 1 counter on this card. Once per turn, if a monster(s) is Special Summoned and an "Ursarctic" Synchro Monster is on the field (except during the Damage Step): You can remove all counters from this card (min. 7), then target 1 monster your opponent controls; take control of it.
external_ids: local SETCARD_ID_0 = 0x163 --Ursarctic
  local COUNTER_ID_0 = 0x5b --Counter(Ursarctic
  
lua: local SETCARD_ID_0 = 0x163 --Ursarctic
  local COUNTER_ID_0 = 0x5b --Counter(Ursarctic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5b)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change cost
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCode(id)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.repfilter)
  	e2:SetTargetRange(LOCATION_GRAVE, 0)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetOperation(s.ctop)
  	c:RegisterEffect(e3)
  	--take control
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_CONTROL)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e4:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.tkccon)
  	e4:SetCost(s.tkccost)
  	e4:SetTarget(s.tkctg)
  	e4:SetOperation(s.tkcop)
  	c:RegisterEffect(e4)
  end
  function s.repfilter(e, c)
  	return c:IsLevelAbove(7) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO)
  end
  function s.tkccon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  end
  function s.tkccost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 7, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, e:GetHandler():GetCounter(COUNTER_ID_0), REASON_COST)
  end
  function s.tkctg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsControlerCanBeChanged()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, nil) and s.tkccon(e, tp, eg, ep, ev, re, r, rp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.tkcop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp)
  	end
  end
  
  
source_text: Ursarctic
  Once per turn, if your "Ursarctic" monster would Tribute a monster(s) to activate its effect, you can banish 1 Level 7 or higher "Ursarctic" monster from your GY instead. Each time a monster(s) is Special Summoned, place 1 counter on this card. Once per turn, if a monster(s) is Special Summoned and an "Ursarctic" Synchro Monster is on the field (except during the Damage Step): You can remove all counters from this card (min. 7), then target 1 monster your opponent controls; take control of it.
target_text: -- Ursarctic
  local SETCARD_ID_0 = 0x163 --Ursarctic
  local COUNTER_ID_0 = 0x5b --Counter(Ursarctic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5b)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change cost
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCode(id)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.repfilter)
  	e2:SetTargetRange(LOCATION_GRAVE, 0)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetOperation(s.ctop)
  	c:RegisterEffect(e3)
  	--take control
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_CONTROL)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e4:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.tkccon)
  	e4:SetCost(s.tkccost)
  	e4:SetTarget(s.tkctg)
  	e4:SetOperation(s.tkcop)
  	c:RegisterEffect(e4)
  end
  function s.repfilter(e, c)
  	return c:IsLevelAbove(7) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO)
  end
  function s.tkccon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  end
  function s.tkccost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 7, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, e:GetHandler():GetCounter(COUNTER_ID_0), REASON_COST)
  end
  function s.tkctg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsControlerCanBeChanged()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, nil) and s.tkccon(e, tp, eg, ep, ev, re, r, rp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.tkcop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp)
  	end
  end
  
  