name: Deskbot
card_text: Pendulum Scale = 10
  [ Pendulum Effect ]
  You cannot Pendulum Summon monsters, except "Deskbot" monsters. This effect cannot be negated.
  ----------------------------------------
  [ Monster Effect ]
  If this card is Normal or Special Summoned: You can target 1 Spell/Trap Card on the field; destroy it. This card gains 500 ATK for each face-up "Deskbot" monster in your Extra Deck. If this card in the Pendulum Zone is destroyed: You can target 1 "Deskbot" monster in your Graveyard; Special Summon it. You can only use this effect of "Deskbot 005" once per turn.
external_ids: local SETCARD_ID_0 = 0xab --Deskbot
  
lua: local SETCARD_ID_0 = 0xab --Deskbot
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--splimit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_CAN_FORBIDDEN)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--atk up
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetCode(EFFECT_UPDATE_ATTACK)
  	e5:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetValue(s.atkval)
  	c:RegisterEffect(e5)
  	--spsummon
  	local e6 = Effect.CreateEffect(c)
  	e6:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e6:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e6:SetCode(EVENT_DESTROYED)
  	e6:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e6:SetCountLimit(1, id)
  	e6:SetCondition(s.spcon)
  	e6:SetTarget(s.sptg)
  	e6:SetOperation(s.spop)
  	c:RegisterEffect(e6)
  end
  function s.splimit(e, c, tp, sumtp, sumpos)
  	return not c:IsSetCard(SETCARD_ID_0) and bit.band(sumtp, SUMMON_TYPE_PENDULUM) == SUMMON_TYPE_PENDULUM
  end
  function s.desfilter(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and s.desfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(s.cfilter, c:GetControler(), LOCATION_EXTRA, 0, nil) * 500
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_PZONE)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Deskbot
  Pendulum Scale = 10
  [ Pendulum Effect ]
  You cannot Pendulum Summon monsters, except "Deskbot" monsters. This effect cannot be negated.
  ----------------------------------------
  [ Monster Effect ]
  If this card is Normal or Special Summoned: You can target 1 Spell/Trap Card on the field; destroy it. This card gains 500 ATK for each face-up "Deskbot" monster in your Extra Deck. If this card in the Pendulum Zone is destroyed: You can target 1 "Deskbot" monster in your Graveyard; Special Summon it. You can only use this effect of "Deskbot 005" once per turn.
target_text: -- Deskbot
  local SETCARD_ID_0 = 0xab --Deskbot
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--splimit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_CAN_FORBIDDEN)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--atk up
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetCode(EFFECT_UPDATE_ATTACK)
  	e5:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetValue(s.atkval)
  	c:RegisterEffect(e5)
  	--spsummon
  	local e6 = Effect.CreateEffect(c)
  	e6:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e6:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e6:SetCode(EVENT_DESTROYED)
  	e6:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e6:SetCountLimit(1, id)
  	e6:SetCondition(s.spcon)
  	e6:SetTarget(s.sptg)
  	e6:SetOperation(s.spop)
  	c:RegisterEffect(e6)
  end
  function s.splimit(e, c, tp, sumtp, sumpos)
  	return not c:IsSetCard(SETCARD_ID_0) and bit.band(sumtp, SUMMON_TYPE_PENDULUM) == SUMMON_TYPE_PENDULUM
  end
  function s.desfilter(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and s.desfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(s.cfilter, c:GetControler(), LOCATION_EXTRA, 0, nil) * 500
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_PZONE)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  