name: Karakuri
card_text: This card must attack, if able. If this card is targeted for an attack: Change the battle position of this card. If this card is in your hand: You can target 1 "Karakuri" monster you control; change its battle position, and if you do, Special Summon this card as a Tuner, also you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except EARTH Machine monsters. You can only use this effect of "Karakuri Bonze mdl 9763 "Kunamzan"" once per turn.
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)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_POSITION + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--must attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_MUST_ATTACK)
  	c:RegisterEffect(e2)
  	--position change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e3:SetCode(EVENT_BE_BATTLE_TARGET)
  	e3:SetOperation(s.posop)
  	c:RegisterEffect(e3)
  end
  s.treat_itself_tuner = true
  function s.posfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsCanChangePosition()
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.posfilter, tp, LOCATION_MZONE, 0, 1, nil) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectTarget(tp, s.posfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if
  		tc:IsRelateToEffect(e)
  		and Duel.ChangePosition(tc, POS_FACEUP_DEFENSE, POS_FACEUP_DEFENSE, POS_FACEUP_ATTACK, POS_FACEUP_ATTACK) ~= 0
  		and c:IsRelateToEffect(e)
  		and Duel.SpecialSummonStep(c, 0, tp, tp, false, false, POS_FACEUP)
  	then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_ADD_TYPE)
  		e1:SetValue(TYPE_TUNER)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  	Duel.SpecialSummonComplete()
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.splimit(e, c)
  	return (not c:IsAttribute(ATTRIBUTE_EARTH) or not c:IsRace(RACE_MACHINE)) and c:IsLocation(LOCATION_EXTRA)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE, 0, POS_FACEUP_ATTACK, 0)
  	end
  end
  
  
source_text: Karakuri
  This card must attack, if able. If this card is targeted for an attack: Change the battle position of this card. If this card is in your hand: You can target 1 "Karakuri" monster you control; change its battle position, and if you do, Special Summon this card as a Tuner, also you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except EARTH Machine monsters. You can only use this effect of "Karakuri Bonze mdl 9763 "Kunamzan"" once per turn.
target_text: -- Karakuri
  local SETCARD_ID_0 = 0x11 --Karakuri
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_POSITION + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--must attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_MUST_ATTACK)
  	c:RegisterEffect(e2)
  	--position change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e3:SetCode(EVENT_BE_BATTLE_TARGET)
  	e3:SetOperation(s.posop)
  	c:RegisterEffect(e3)
  end
  s.treat_itself_tuner = true
  function s.posfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsCanChangePosition()
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.posfilter, tp, LOCATION_MZONE, 0, 1, nil) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectTarget(tp, s.posfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if
  		tc:IsRelateToEffect(e)
  		and Duel.ChangePosition(tc, POS_FACEUP_DEFENSE, POS_FACEUP_DEFENSE, POS_FACEUP_ATTACK, POS_FACEUP_ATTACK) ~= 0
  		and c:IsRelateToEffect(e)
  		and Duel.SpecialSummonStep(c, 0, tp, tp, false, false, POS_FACEUP)
  	then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_ADD_TYPE)
  		e1:SetValue(TYPE_TUNER)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  	Duel.SpecialSummonComplete()
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.splimit(e, c)
  	return (not c:IsAttribute(ATTRIBUTE_EARTH) or not c:IsRace(RACE_MACHINE)) and c:IsLocation(LOCATION_EXTRA)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE, 0, POS_FACEUP_ATTACK, 0)
  	end
  end
  
  