name: Star
card_text: Your opponent cannot target Spellcaster-Type monsters you control with Spell Cards or effects. If a face-up "Magician" Pendulum Monster Card(s) leaves your Monster Zone or Pendulum Zone: Add 1 "Magician" Pendulum Monster from your Deck to your hand. You can only use this effect of "Star Pendulumgraph" once per turn.
external_ids: local SETCARD_ID_0 = 0x98 --Magician
  
lua: local SETCARD_ID_0 = 0x98 --Magician
  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)
  	--Cannot target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_SPELLCASTER))
  	e2:SetValue(s.evalue)
  	c:RegisterEffect(e2)
  	--Search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.evalue(e, re, rp)
  	return re:IsActiveType(TYPE_SPELL) and rp == 1 - e:GetHandlerPlayer()
  end
  function s.thcfilter(c, tp)
  	return c:IsType(TYPE_PENDULUM) and c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousControler(tp) and c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_MZONE + LOCATION_PZONE)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.thcfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Star
  Your opponent cannot target Spellcaster-Type monsters you control with Spell Cards or effects. If a face-up "Magician" Pendulum Monster Card(s) leaves your Monster Zone or Pendulum Zone: Add 1 "Magician" Pendulum Monster from your Deck to your hand. You can only use this effect of "Star Pendulumgraph" once per turn.
target_text: -- Star
  local SETCARD_ID_0 = 0x98 --Magician
  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)
  	--Cannot target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_SPELLCASTER))
  	e2:SetValue(s.evalue)
  	c:RegisterEffect(e2)
  	--Search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.evalue(e, re, rp)
  	return re:IsActiveType(TYPE_SPELL) and rp == 1 - e:GetHandlerPlayer()
  end
  function s.thcfilter(c, tp)
  	return c:IsType(TYPE_PENDULUM) and c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousControler(tp) and c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_MZONE + LOCATION_PZONE)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.thcfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  