name: Dimension
card_text: Activate this card by targeting 1 face-up Attack Position monster you control. Once per battle, during the Battle Step, if it is attacked by an opponent's monster with higher ATK: You can inflict damage to your opponent equal to the difference between the attacking monster's ATK and the targeted monster's. If the targeted monster leaves the field, destroy this card.
lua: 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)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetHintTiming(TIMING_BATTLE_PHASE)
  	e3:SetCondition(s.damcon)
  	e3:SetTarget(s.damtg)
  	e3:SetOperation(s.damop)
  	c:RegisterEffect(e3)
  	--Destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EVENT_LEAVE_FIELD)
  	e4:SetCondition(s.descon)
  	e4:SetOperation(s.desop)
  	c:RegisterEffect(e4)
  end
  function s.filter(c)
  	return c:IsPosition(POS_FACEUP_ATTACK)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		c:SetCardTarget(tc)
  	end
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_BATTLE_STEP
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	local at = Duel.GetAttacker()
  	if chk == 0 then
  		return tc and Duel.GetAttackTarget() == tc and at and at:IsControler(1 - tp) and at:GetAttack() > tc:GetAttack() and c:GetFlagEffect(id) == 0
  	end
  	local dam = math.abs(at:GetAttack() - tc:GetAttack())
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE, 0, 1)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	if not tc then
  		return false
  	end
  	local at = Duel.GetAttacker()
  	if at:IsRelateToBattle() then
  		local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  		Duel.Damage(p, math.abs(at:GetAttack() - tc:GetAttack()), REASON_EFFECT)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  
  
source_text: Dimension
  Activate this card by targeting 1 face-up Attack Position monster you control. Once per battle, during the Battle Step, if it is attacked by an opponent's monster with higher ATK: You can inflict damage to your opponent equal to the difference between the attacking monster's ATK and the targeted monster's. If the targeted monster leaves the field, destroy this card.
target_text: -- Dimension
  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)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetHintTiming(TIMING_BATTLE_PHASE)
  	e3:SetCondition(s.damcon)
  	e3:SetTarget(s.damtg)
  	e3:SetOperation(s.damop)
  	c:RegisterEffect(e3)
  	--Destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EVENT_LEAVE_FIELD)
  	e4:SetCondition(s.descon)
  	e4:SetOperation(s.desop)
  	c:RegisterEffect(e4)
  end
  function s.filter(c)
  	return c:IsPosition(POS_FACEUP_ATTACK)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		c:SetCardTarget(tc)
  	end
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_BATTLE_STEP
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	local at = Duel.GetAttacker()
  	if chk == 0 then
  		return tc and Duel.GetAttackTarget() == tc and at and at:IsControler(1 - tp) and at:GetAttack() > tc:GetAttack() and c:GetFlagEffect(id) == 0
  	end
  	local dam = math.abs(at:GetAttack() - tc:GetAttack())
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE, 0, 1)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	if not tc then
  		return false
  	end
  	local at = Duel.GetAttacker()
  	if at:IsRelateToBattle() then
  		local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  		Duel.Damage(p, math.abs(at:GetAttack() - tc:GetAttack()), REASON_EFFECT)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  
  