name: Utopia
card_text: If you control a "Utopia" monster: Destroy the 1 face-up monster your opponent controls that has the lowest ATK (your choice, if tied), and if you do, inflict damage to your opponent equal to the destroyed monster's ATK on the field.
external_ids: local SETCARD_ID_0 = 0x107f --Utopia
  
lua: local SETCARD_ID_0 = 0x107f --Utopia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.filter(c)
  	return c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	local tg = g:GetMinGroup(Card.GetAttack)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, tg:GetFirst():GetAttack())
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	if g:GetCount() > 0 then
  		local tc = nil
  		local tg = g:GetMinGroup(Card.GetAttack)
  		if tg:GetCount() > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local sg = tg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(sg)
  			tc = sg:GetFirst()
  		else
  			tc = tg:GetFirst()
  		end
  		local atk = tc:GetAttack()
  		if Duel.Destroy(tc, REASON_EFFECT) > 0 then
  			Duel.Damage(1 - tp, atk, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Utopia
  If you control a "Utopia" monster: Destroy the 1 face-up monster your opponent controls that has the lowest ATK (your choice, if tied), and if you do, inflict damage to your opponent equal to the destroyed monster's ATK on the field.
target_text: -- Utopia
  local SETCARD_ID_0 = 0x107f --Utopia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.filter(c)
  	return c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	local tg = g:GetMinGroup(Card.GetAttack)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, tg:GetFirst():GetAttack())
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	if g:GetCount() > 0 then
  		local tc = nil
  		local tg = g:GetMinGroup(Card.GetAttack)
  		if tg:GetCount() > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local sg = tg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(sg)
  			tc = sg:GetFirst()
  		else
  			tc = tg:GetFirst()
  		end
  		local atk = tc:GetAttack()
  		if Duel.Destroy(tc, REASON_EFFECT) > 0 then
  			Duel.Damage(1 - tp, atk, REASON_EFFECT)
  		end
  	end
  end
  
  