name: Karakuri
card_text: Activate this card by targeting 1 "Karakuri" monster in your GY; Special Summon it and equip it with this card. Once per turn, if the battle position of a face-up "Karakuri" monster(s) you control is changed: The equipped monster gains 500 ATK/DEF (even if this card is no longer equipped). You can only activate 1 "Karakuri Gama Oil" 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)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--atk/def
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e2:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_CHANGE_POS)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.atkcon)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) == 0 then
  			return
  		end
  		Duel.Equip(tp, c, tc)
  		local e1 = Effect.CreateEffect(tc)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetValue(s.eqlimit)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  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.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetEquipTarget()
  	if ec and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(500)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		ec:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_DEFENSE)
  		ec:RegisterEffect(e2)
  	end
  end
  
  
source_text: Karakuri
  Activate this card by targeting 1 "Karakuri" monster in your GY; Special Summon it and equip it with this card. Once per turn, if the battle position of a face-up "Karakuri" monster(s) you control is changed: The equipped monster gains 500 ATK/DEF (even if this card is no longer equipped). You can only activate 1 "Karakuri Gama Oil" per turn.
target_text: -- Karakuri
  local SETCARD_ID_0 = 0x11 --Karakuri
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--atk/def
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e2:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_CHANGE_POS)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.atkcon)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) == 0 then
  			return
  		end
  		Duel.Equip(tp, c, tc)
  		local e1 = Effect.CreateEffect(tc)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetValue(s.eqlimit)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  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.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetEquipTarget()
  	if ec and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(500)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		ec:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_DEFENSE)
  		ec:RegisterEffect(e2)
  	end
  end
  
  