name: Crusadia
card_text: You can Special Summon this card (from your hand) in Defense Position to your zone a Link Monster points to. You can only Special Summon "Crusadia Arboria" once per turn this way. If a "Crusadia" monster(s) you control would be destroyed by battle or card effect, you can banish this card from your field or GY instead. You can only use this effect of "Crusadia Arboria" once per turn.
external_ids: local SETCARD_ID_0 = 0x116 --Crusadia
  
lua: local SETCARD_ID_0 = 0x116 --Crusadia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE + EFFECT_FLAG_SPSUM_PARAM)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetTargetRange(POS_FACEUP_DEFENSE, 0)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.spcon)
  	e1:SetValue(s.spval)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE + LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local zone = Duel.GetLinkedZone(tp)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone) > 0
  end
  function s.spval(e, c)
  	return 0, Duel.GetLinkedZone(c:GetControler())
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, c, tp) and c:IsAbleToRemove() and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  	end
  	return Duel.SelectEffectYesNo(tp, c, 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  end
  
  
source_text: Crusadia
  You can Special Summon this card (from your hand) in Defense Position to your zone a Link Monster points to. You can only Special Summon "Crusadia Arboria" once per turn this way. If a "Crusadia" monster(s) you control would be destroyed by battle or card effect, you can banish this card from your field or GY instead. You can only use this effect of "Crusadia Arboria" once per turn.
target_text: -- Crusadia
  local SETCARD_ID_0 = 0x116 --Crusadia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE + EFFECT_FLAG_SPSUM_PARAM)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetTargetRange(POS_FACEUP_DEFENSE, 0)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.spcon)
  	e1:SetValue(s.spval)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE + LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local zone = Duel.GetLinkedZone(tp)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone) > 0
  end
  function s.spval(e, c)
  	return 0, Duel.GetLinkedZone(c:GetControler())
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, c, tp) and c:IsAbleToRemove() and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  	end
  	return Duel.SelectEffectYesNo(tp, c, 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  end
  
  