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. (Quick Effect): You can banish this card from your GY, then target 1 "Karakuri" monster you control; change its battle position. You can only use this effect of "Karakuri Gama mdl 4624 "Shirokunishi"" 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)
  	--must attack
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MUST_ATTACK)
  	c:RegisterEffect(e1)
  	--position change
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_POSITION)
  	e2:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_BE_BATTLE_TARGET)
  	e2:SetOperation(s.posop1)
  	c:RegisterEffect(e2)
  	--position change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.postg1)
  	e3:SetOperation(s.posop2)
  	c:RegisterEffect(e3)
  end
  function s.posop1(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
  function s.posfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsCanChangePosition()
  end
  function s.postg1(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.posfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	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)
  end
  function s.posop2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE, POS_FACEUP_DEFENSE, POS_FACEUP_ATTACK, POS_FACEUP_ATTACK)
  	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. (Quick Effect): You can banish this card from your GY, then target 1 "Karakuri" monster you control; change its battle position. You can only use this effect of "Karakuri Gama mdl 4624 "Shirokunishi"" once per turn.
target_text: -- Karakuri
  local SETCARD_ID_0 = 0x11 --Karakuri
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--must attack
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MUST_ATTACK)
  	c:RegisterEffect(e1)
  	--position change
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_POSITION)
  	e2:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_BE_BATTLE_TARGET)
  	e2:SetOperation(s.posop1)
  	c:RegisterEffect(e2)
  	--position change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.postg1)
  	e3:SetOperation(s.posop2)
  	c:RegisterEffect(e3)
  end
  function s.posop1(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
  function s.posfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsCanChangePosition()
  end
  function s.postg1(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.posfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	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)
  end
  function s.posop2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE, POS_FACEUP_DEFENSE, POS_FACEUP_ATTACK, POS_FACEUP_ATTACK)
  	end
  end
  
  