name: Gandora-X
card_text: When this card is Normal or Special Summoned from the hand: You can destroy as many other monsters on the field as possible, and if you do, inflict damage to your opponent equal to the highest original ATK on the field among those destroyed monsters (your choice, if tied). This card's ATK becomes equal to the damage inflicted to your opponent by this effect. Once per turn, during your End Phase: Halve your LP.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE + CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--halve LP
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.hvcon)
  	e3:SetOperation(s.hvop)
  	c:RegisterEffect(e3)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_HAND)
  end
  function s.damfilter(c)
  	if c:IsFaceup() then
  		return math.max(c:GetTextAttack(), 0)
  	else
  		return 0
  	end
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, e:GetHandler())
  	end
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	local mg, atk = g:GetMaxGroup(s.damfilter)
  	if atk > 0 then
  		Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, atk)
  	end
  end
  function s.filter(c)
  	return math.max(c:GetTextAttack(), 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, aux.ExceptThisCard(e))
  	if g:GetCount() > 0 and Duel.Destroy(g, REASON_EFFECT) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		local mg, atk = og:GetMaxGroup(s.filter)
  		local dam = Duel.Damage(1 - tp, atk, REASON_EFFECT)
  		if c:IsFaceup() and c:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(dam)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  			c:RegisterEffect(e1)
  		end
  	end
  end
  function s.hvcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.hvop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SetLP(tp, math.ceil(Duel.GetLP(tp) / 2))
  end
  
  
source_text: Gandora-X
  When this card is Normal or Special Summoned from the hand: You can destroy as many other monsters on the field as possible, and if you do, inflict damage to your opponent equal to the highest original ATK on the field among those destroyed monsters (your choice, if tied). This card's ATK becomes equal to the damage inflicted to your opponent by this effect. Once per turn, during your End Phase: Halve your LP.
target_text: -- Gandora-X
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE + CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--halve LP
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.hvcon)
  	e3:SetOperation(s.hvop)
  	c:RegisterEffect(e3)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_HAND)
  end
  function s.damfilter(c)
  	if c:IsFaceup() then
  		return math.max(c:GetTextAttack(), 0)
  	else
  		return 0
  	end
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, e:GetHandler())
  	end
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	local mg, atk = g:GetMaxGroup(s.damfilter)
  	if atk > 0 then
  		Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, atk)
  	end
  end
  function s.filter(c)
  	return math.max(c:GetTextAttack(), 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, aux.ExceptThisCard(e))
  	if g:GetCount() > 0 and Duel.Destroy(g, REASON_EFFECT) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		local mg, atk = og:GetMaxGroup(s.filter)
  		local dam = Duel.Damage(1 - tp, atk, REASON_EFFECT)
  		if c:IsFaceup() and c:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(dam)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  			c:RegisterEffect(e1)
  		end
  	end
  end
  function s.hvcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.hvop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SetLP(tp, math.ceil(Duel.GetLP(tp) / 2))
  end
  
  