name: Hexatellarknight
card_text: Each "tellarknight" Xyz Monster gains 200 ATK and DEF for each Xyz Material attached to it. When a "tellarknight" Xyz Monster you control is targeted for an attack: You can send 1 "tellarknight" card from your hand to the Graveyard; negate that attack.
external_ids: local SETCARD_ID_0 = 0x9c --tellarknight
  
lua: local SETCARD_ID_0 = 0x9c --tellarknight
  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)
  	c:RegisterEffect(e1)
  	--atk/def
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(s.atktg)
  	e2:SetValue(s.atkval)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e3)
  	--negate
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetCode(EVENT_BE_BATTLE_TARGET)
  	e4:SetCondition(s.negcon)
  	e4:SetCost(s.negcost)
  	e4:SetOperation(s.negop)
  	c:RegisterEffect(e4)
  end
  function s.atktg(e, c)
  	return c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkval(e, c)
  	return c:GetOverlayCount() * 200
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	return tc:IsFaceup() and tc:IsType(TYPE_XYZ) and tc:IsSetCard(SETCARD_ID_0) and tc:IsControler(tp) and tc:IsLocation(LOCATION_MZONE)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.negcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_COST)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  
source_text: Hexatellarknight
  Each "tellarknight" Xyz Monster gains 200 ATK and DEF for each Xyz Material attached to it. When a "tellarknight" Xyz Monster you control is targeted for an attack: You can send 1 "tellarknight" card from your hand to the Graveyard; negate that attack.
target_text: -- Hexatellarknight
  local SETCARD_ID_0 = 0x9c --tellarknight
  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)
  	c:RegisterEffect(e1)
  	--atk/def
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(s.atktg)
  	e2:SetValue(s.atkval)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e3)
  	--negate
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetCode(EVENT_BE_BATTLE_TARGET)
  	e4:SetCondition(s.negcon)
  	e4:SetCost(s.negcost)
  	e4:SetOperation(s.negop)
  	c:RegisterEffect(e4)
  end
  function s.atktg(e, c)
  	return c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkval(e, c)
  	return c:GetOverlayCount() * 200
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	return tc:IsFaceup() and tc:IsType(TYPE_XYZ) and tc:IsSetCard(SETCARD_ID_0) and tc:IsControler(tp) and tc:IsLocation(LOCATION_MZONE)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.negcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_COST)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  