name: Dinomists
card_text: When this card is activated: You can place 1 or 2 "Dinomist" Pendulum Monster(s) from your Deck in your Pendulum Zone, but you cannot Pendulum Summon monsters until the end of the next turn, except "Dinomist" monsters (even if this card leaves the field). Once per turn, if this card is already face-up in your Spell & Trap Zone: You can Tribute 1 "Dinomist" monster, then target 1 card your opponent controls; return it to the hand.
external_ids: local SETCARD_ID_0 = 0xd8 --Dinomist
  
lua: local SETCARD_ID_0 = 0xd8 --Dinomist
  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)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--return
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsSetCard(SETCARD_ID_0) and not c:IsForbidden()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil)
  	local ct = 0
  	if Duel.CheckLocation(tp, LOCATION_PZONE, 0) then
  		ct = ct + 1
  	end
  	if Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  		ct = ct + 1
  	end
  	if ct > 0 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local sg = g:Select(tp, 1, ct, nil)
  		local sc = sg:GetFirst()
  		while sc do
  			Duel.MoveToField(sc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  			sc = sg:GetNext()
  		end
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetTargetRange(1, 0)
  		e1:SetTarget(s.splimit)
  		e1:SetReset(RESET_PHASE + PHASE_END, 2)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.splimit(e, c, sump, sumtype, sumpos, targetp, se)
  	return not c:IsSetCard(SETCARD_ID_0) and bit.band(sumtype, SUMMON_TYPE_PENDULUM) == SUMMON_TYPE_PENDULUM
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsSetCard, 1, nil, 0xd8)
  	end
  	local g = Duel.SelectReleaseGroup(tp, Card.IsSetCard, 1, 1, nil, 0xd8)
  	Duel.Release(g, REASON_COST)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if e:GetHandler():IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Dinomists
  When this card is activated: You can place 1 or 2 "Dinomist" Pendulum Monster(s) from your Deck in your Pendulum Zone, but you cannot Pendulum Summon monsters until the end of the next turn, except "Dinomist" monsters (even if this card leaves the field). Once per turn, if this card is already face-up in your Spell & Trap Zone: You can Tribute 1 "Dinomist" monster, then target 1 card your opponent controls; return it to the hand.
target_text: -- Dinomists
  local SETCARD_ID_0 = 0xd8 --Dinomist
  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)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--return
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsSetCard(SETCARD_ID_0) and not c:IsForbidden()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil)
  	local ct = 0
  	if Duel.CheckLocation(tp, LOCATION_PZONE, 0) then
  		ct = ct + 1
  	end
  	if Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  		ct = ct + 1
  	end
  	if ct > 0 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local sg = g:Select(tp, 1, ct, nil)
  		local sc = sg:GetFirst()
  		while sc do
  			Duel.MoveToField(sc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  			sc = sg:GetNext()
  		end
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetTargetRange(1, 0)
  		e1:SetTarget(s.splimit)
  		e1:SetReset(RESET_PHASE + PHASE_END, 2)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.splimit(e, c, sump, sumtype, sumpos, targetp, se)
  	return not c:IsSetCard(SETCARD_ID_0) and bit.band(sumtype, SUMMON_TYPE_PENDULUM) == SUMMON_TYPE_PENDULUM
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsSetCard, 1, nil, 0xd8)
  	end
  	local g = Duel.SelectReleaseGroup(tp, Card.IsSetCard, 1, 1, nil, 0xd8)
  	Duel.Release(g, REASON_COST)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if e:GetHandler():IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  