name: Karakuri
card_text: 1 Tuner + 1+ non-Tuner Machine monsters
  If this card is Synchro Summoned: You can Special Summon 1 "Karakuri" monster from your Deck. Monsters you control in Defense Position cannot be destroyed by battle. Once per turn, if the battle position of a face-up "Karakuri" monster(s) you control is changed (except during the Damage Step): You can target 1 card your opponent controls; banish it.
external_ids: local SETCARD_ID_0 = 0x11 --Karakuri
  
lua: local SETCARD_ID_0 = 0x11 --Karakuri
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(Card.IsRace, RACE_MACHINE), 1)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsDefensePos))
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--remove
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_CHANGE_POS)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.rmcon)
  	e3:SetTarget(s.rmtg)
  	e3:SetOperation(s.rmop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  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)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, tp)
  	local np = c:GetPosition()
  	local pp = c:GetPreviousPosition()
  	return c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp) and ((pp == 0x1 and np == 0x4) or (pp == 0x4 and np == 0x1))
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  
source_text: Karakuri
  1 Tuner + 1+ non-Tuner Machine monsters
  If this card is Synchro Summoned: You can Special Summon 1 "Karakuri" monster from your Deck. Monsters you control in Defense Position cannot be destroyed by battle. Once per turn, if the battle position of a face-up "Karakuri" monster(s) you control is changed (except during the Damage Step): You can target 1 card your opponent controls; banish it.
target_text: -- Karakuri
  local SETCARD_ID_0 = 0x11 --Karakuri
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(Card.IsRace, RACE_MACHINE), 1)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsDefensePos))
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--remove
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_CHANGE_POS)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.rmcon)
  	e3:SetTarget(s.rmtg)
  	e3:SetOperation(s.rmop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  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)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, tp)
  	local np = c:GetPosition()
  	local pp = c:GetPreviousPosition()
  	return c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp) and ((pp == 0x1 and np == 0x4) or (pp == 0x4 and np == 0x1))
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  