name: Triamid
card_text: Cannot be Normal Summoned/Set. Must be Special Summoned with the effect of a "Triamid" card, and cannot be Special Summoned by other ways. If a face-up "Triamid" card(s) you control, except "Triamid Sphinx", is destroyed by battle or card effect: You can Special Summon this card from your hand. While you control another "Triamid" card, this card gains 500 ATK and DEF for each Field Spell Card with a different name in your Graveyard, also monsters your opponent controls cannot attack, except to attack "Triamid Sphinx".
external_ids: local SETCARD_ID_0 = 0xe2 --Triamid
  
lua: local SETCARD_ID_0 = 0xe2 --Triamid
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetCondition(s.efcon)
  	e3:SetValue(s.atkval)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e4)
  	--only be attacked
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetTargetRange(0, LOCATION_MZONE)
  	e5:SetCondition(s.efcon)
  	e5:SetValue(s.atklimit)
  	c:RegisterEffect(e5)
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD)
  	e6:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetTargetRange(0, LOCATION_MZONE)
  	e6:SetCondition(s.efcon)
  	c:RegisterEffect(e6)
  end
  function s.splimit(e, se, sp, st)
  	return se:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.spfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsSetCard(SETCARD_ID_0)
  		and not c:IsCode(id)
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_ONFIELD)
  		and c:IsPreviousPosition(POS_FACEUP)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, true)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(c, 0, tp, tp, false, true, POS_FACEUP) ~= 0 then
  		c:CompleteProcedure()
  	end
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.efcon(e)
  	return Duel.IsExistingMatchingCard(s.cfilter, e:GetHandlerPlayer(), LOCATION_ONFIELD, 0, 1, e:GetHandler())
  end
  function s.atkval(e, c)
  	local g = Duel.GetMatchingGroup(Card.IsType, c:GetControler(), LOCATION_GRAVE, 0, nil, TYPE_FIELD)
  	return g:GetClassCount(Card.GetCode) * 500
  end
  function s.atklimit(e, c)
  	return not c:IsCode(id)
  end
  
  
source_text: Triamid
  Cannot be Normal Summoned/Set. Must be Special Summoned with the effect of a "Triamid" card, and cannot be Special Summoned by other ways. If a face-up "Triamid" card(s) you control, except "Triamid Sphinx", is destroyed by battle or card effect: You can Special Summon this card from your hand. While you control another "Triamid" card, this card gains 500 ATK and DEF for each Field Spell Card with a different name in your Graveyard, also monsters your opponent controls cannot attack, except to attack "Triamid Sphinx".
target_text: -- Triamid
  local SETCARD_ID_0 = 0xe2 --Triamid
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetCondition(s.efcon)
  	e3:SetValue(s.atkval)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e4)
  	--only be attacked
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetTargetRange(0, LOCATION_MZONE)
  	e5:SetCondition(s.efcon)
  	e5:SetValue(s.atklimit)
  	c:RegisterEffect(e5)
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD)
  	e6:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetTargetRange(0, LOCATION_MZONE)
  	e6:SetCondition(s.efcon)
  	c:RegisterEffect(e6)
  end
  function s.splimit(e, se, sp, st)
  	return se:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.spfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsSetCard(SETCARD_ID_0)
  		and not c:IsCode(id)
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_ONFIELD)
  		and c:IsPreviousPosition(POS_FACEUP)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, true)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(c, 0, tp, tp, false, true, POS_FACEUP) ~= 0 then
  		c:CompleteProcedure()
  	end
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.efcon(e)
  	return Duel.IsExistingMatchingCard(s.cfilter, e:GetHandlerPlayer(), LOCATION_ONFIELD, 0, 1, e:GetHandler())
  end
  function s.atkval(e, c)
  	local g = Duel.GetMatchingGroup(Card.IsType, c:GetControler(), LOCATION_GRAVE, 0, nil, TYPE_FIELD)
  	return g:GetClassCount(Card.GetCode) * 500
  end
  function s.atklimit(e, c)
  	return not c:IsCode(id)
  end
  
  