name: Dispatchparazzi
card_text: 2 Effect Monsters
  When another monster you control is targeted for an attack: You can change the attack target to this card, and perform damage calculation. When this card is destroyed by battle with an opponent's monster: You can destroy that opponent's monster, and if you do, gain LP equal to half that monster's original ATK. You can only use each effect of "Dispatchparazzi" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2, 2)
  	c:EnableReviveLimit()
  	--change target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BE_BATTLE_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.cbcon)
  	e1:SetOperation(s.cbop)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.cbcon(e, tp, eg, ep, ev, re, r, rp)
  	local bt = eg:GetFirst()
  	return r ~= REASON_REPLACE and bt ~= e:GetHandler() and bt:IsControler(tp)
  end
  function s.cbop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local at = Duel.GetAttacker()
  		if at:IsAttackable() and not at:IsImmuneToEffect(e) and not c:IsImmuneToEffect(e) then
  			Duel.CalculateDamage(at, c)
  		end
  	end
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetHandler():GetBattleTarget()
  	if chk == 0 then
  		return bc:IsRelateToBattle() and bc:IsControler(1 - tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, bc, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, math.ceil(bc:GetBaseAttack() / 2))
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetHandler():GetBattleTarget()
  	if bc:IsRelateToBattle() and Duel.Destroy(bc, REASON_EFFECT) > 0 and bc:GetBaseAttack() > 0 then
  		Duel.Recover(tp, math.ceil(bc:GetBaseAttack() / 2), REASON_EFFECT)
  	end
  end
  
  
source_text: Dispatchparazzi
  2 Effect Monsters
  When another monster you control is targeted for an attack: You can change the attack target to this card, and perform damage calculation. When this card is destroyed by battle with an opponent's monster: You can destroy that opponent's monster, and if you do, gain LP equal to half that monster's original ATK. You can only use each effect of "Dispatchparazzi" once per turn.
target_text: -- Dispatchparazzi
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2, 2)
  	c:EnableReviveLimit()
  	--change target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BE_BATTLE_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.cbcon)
  	e1:SetOperation(s.cbop)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.cbcon(e, tp, eg, ep, ev, re, r, rp)
  	local bt = eg:GetFirst()
  	return r ~= REASON_REPLACE and bt ~= e:GetHandler() and bt:IsControler(tp)
  end
  function s.cbop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local at = Duel.GetAttacker()
  		if at:IsAttackable() and not at:IsImmuneToEffect(e) and not c:IsImmuneToEffect(e) then
  			Duel.CalculateDamage(at, c)
  		end
  	end
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetHandler():GetBattleTarget()
  	if chk == 0 then
  		return bc:IsRelateToBattle() and bc:IsControler(1 - tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, bc, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, math.ceil(bc:GetBaseAttack() / 2))
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetHandler():GetBattleTarget()
  	if bc:IsRelateToBattle() and Duel.Destroy(bc, REASON_EFFECT) > 0 and bc:GetBaseAttack() > 0 then
  		Duel.Recover(tp, math.ceil(bc:GetBaseAttack() / 2), REASON_EFFECT)
  	end
  end
  
  