name: Vijam
card_text: Cannot be destroyed by battle. At the end of the Damage Step, if this card battled an opponent's monster: You can place this card face-up in your Spell & Trap Zone as a Continuous Spell Card, and if you do, place 1 Cubic Counter on that opponent's monster. (Monsters with a Cubic Counter cannot attack, also negate their effects.) If this card is treated as a Continuous Spell Card by this effect, during your Main Phase: You can Special Summon this card from your Spell & Trap Zone.
external_ids: local COUNTER_ID_0 = 0x1038 --Cubic
  
lua: local COUNTER_ID_0 = 0x1038 --Cubic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--battle
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_COUNTER)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DAMAGE_STEP_END)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	if chk == 0 then
  		return bc
  			and bc:IsFaceup()
  			and bc:IsRelateToBattle()
  			and bc:IsCanAddCounter(COUNTER_ID_0, 1)
  			and c:IsLocation(LOCATION_MZONE)
  			and c:IsRelateToBattle()
  			and Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) or c:IsImmuneToEffect(e) or not c:IsLocation(LOCATION_MZONE) then
  		return
  	end
  	if not Duel.MoveToField(c, tp, tp, LOCATION_SZONE, POS_FACEUP, true) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCode(EFFECT_CHANGE_TYPE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
  	e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
  	c:RegisterEffect(e1)
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET, 0, 1)
  	local bc = c:GetBattleTarget()
  	if bc:IsRelateToBattle() and bc:IsFaceup() then
  		bc:AddCounter(COUNTER_ID_0, 1)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_ATTACK)
  		e1:SetCondition(s.condition)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		bc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_DISABLE)
  		bc:RegisterEffect(e2)
  	end
  end
  function s.condition(e)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) > 0
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  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 e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  
source_text: Vijam
  Cannot be destroyed by battle. At the end of the Damage Step, if this card battled an opponent's monster: You can place this card face-up in your Spell & Trap Zone as a Continuous Spell Card, and if you do, place 1 Cubic Counter on that opponent's monster. (Monsters with a Cubic Counter cannot attack, also negate their effects.) If this card is treated as a Continuous Spell Card by this effect, during your Main Phase: You can Special Summon this card from your Spell & Trap Zone.
target_text: -- Vijam
  local COUNTER_ID_0 = 0x1038 --Cubic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--battle
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_COUNTER)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DAMAGE_STEP_END)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	if chk == 0 then
  		return bc
  			and bc:IsFaceup()
  			and bc:IsRelateToBattle()
  			and bc:IsCanAddCounter(COUNTER_ID_0, 1)
  			and c:IsLocation(LOCATION_MZONE)
  			and c:IsRelateToBattle()
  			and Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) or c:IsImmuneToEffect(e) or not c:IsLocation(LOCATION_MZONE) then
  		return
  	end
  	if not Duel.MoveToField(c, tp, tp, LOCATION_SZONE, POS_FACEUP, true) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCode(EFFECT_CHANGE_TYPE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
  	e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
  	c:RegisterEffect(e1)
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET, 0, 1)
  	local bc = c:GetBattleTarget()
  	if bc:IsRelateToBattle() and bc:IsFaceup() then
  		bc:AddCounter(COUNTER_ID_0, 1)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_ATTACK)
  		e1:SetCondition(s.condition)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		bc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_DISABLE)
  		bc:RegisterEffect(e2)
  	end
  end
  function s.condition(e)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) > 0
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  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 e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  