name: Spear
card_text: FLIP: When this card is sent to the Graveyard after being flipped, each player selects 1 monster from their Graveyard, and Special Summons it in face-up Attack Position or face-down Defense Position.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--flip effect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_FLIP)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetOperation(s.flipop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.flipop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsLocation(LOCATION_MZONE + LOCATION_GRAVE) then
  		c:RegisterFlagEffect(id, RESET_EVENT + 0x57a0000, 0, 1)
  	end
  end
  function s.filter(c, e, tp)
  	return c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) ~= 0
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, e:GetHandler(), e, tp)
  	Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_SPSUMMON)
  	local g2 = Duel.SelectTarget(1 - tp, s.filter, 1 - tp, LOCATION_GRAVE, 0, 1, 1, e:GetHandler(), e, 1 - tp)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, #g1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if sg:GetCount() == 0 then
  		return
  	end
  	local tc = sg:GetFirst()
  	if tc and Duel.GetLocationCount(tc:GetControler(), LOCATION_MZONE) > 0 then
  		local sp = tc:GetControler()
  		if Duel.SpecialSummonStep(tc, 0, sp, sp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) and tc:IsFacedown() then
  			Duel.ConfirmCards(1 - sp, tc)
  		end
  	end
  	tc = sg:GetNext()
  	if tc and Duel.GetLocationCount(tc:GetControler(), LOCATION_MZONE) > 0 then
  		local sp = tc:GetControler()
  		if Duel.SpecialSummonStep(tc, 0, sp, sp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) and tc:IsFacedown() then
  			Duel.ConfirmCards(1 - sp, tc)
  		end
  	end
  	Duel.SpecialSummonComplete()
  end
  
  
source_text: Spear
  FLIP: When this card is sent to the Graveyard after being flipped, each player selects 1 monster from their Graveyard, and Special Summons it in face-up Attack Position or face-down Defense Position.
target_text: -- Spear
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--flip effect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_FLIP)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetOperation(s.flipop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.flipop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsLocation(LOCATION_MZONE + LOCATION_GRAVE) then
  		c:RegisterFlagEffect(id, RESET_EVENT + 0x57a0000, 0, 1)
  	end
  end
  function s.filter(c, e, tp)
  	return c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) ~= 0
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, e:GetHandler(), e, tp)
  	Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_SPSUMMON)
  	local g2 = Duel.SelectTarget(1 - tp, s.filter, 1 - tp, LOCATION_GRAVE, 0, 1, 1, e:GetHandler(), e, 1 - tp)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, #g1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if sg:GetCount() == 0 then
  		return
  	end
  	local tc = sg:GetFirst()
  	if tc and Duel.GetLocationCount(tc:GetControler(), LOCATION_MZONE) > 0 then
  		local sp = tc:GetControler()
  		if Duel.SpecialSummonStep(tc, 0, sp, sp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) and tc:IsFacedown() then
  			Duel.ConfirmCards(1 - sp, tc)
  		end
  	end
  	tc = sg:GetNext()
  	if tc and Duel.GetLocationCount(tc:GetControler(), LOCATION_MZONE) > 0 then
  		local sp = tc:GetControler()
  		if Duel.SpecialSummonStep(tc, 0, sp, sp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) and tc:IsFacedown() then
  			Duel.ConfirmCards(1 - sp, tc)
  		end
  	end
  	Duel.SpecialSummonComplete()
  end
  
  