Puppet
When this card is Normal Summoned: You can change this card to Defense Position, and if you do, send 1 EARTH Warrior monster from your Deck to your GY. Monsters your opponent controls that can attack must attack this card. Once per turn, when this card is targeted for an attack: You can target 1 Level 6 or higher EARTH Warrior monster in your GY; send this card from the field to the GY, and if you do, Special Summon that monster, then change the attack target to it.
local s, id, o = GetID()
function s.initial_effect(c)
	--to grave
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_POSITION + CATEGORY_TOGRAVE)
	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetTarget(s.tgtg)
	e1:SetOperation(s.tgop)
	c:RegisterEffect(e1)
	--must attack
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_MUST_ATTACK)
	e2:SetRange(LOCATION_MZONE)
	e2:SetTargetRange(0, LOCATION_MZONE)
	c:RegisterEffect(e2)
	local e3 = e2:Clone()
	e3:SetCode(EFFECT_MUST_ATTACK_MONSTER)
	e3:SetValue(s.atklimit)
	c:RegisterEffect(e3)
	--castling
	local e4 = Effect.CreateEffect(c)
	e4:SetCategory(CATEGORY_TOGRAVE + CATEGORY_SPECIAL_SUMMON)
	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e4:SetCode(EVENT_BE_BATTLE_TARGET)
	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e4:SetCountLimit(1)
	e4:SetTarget(s.cltg)
	e4:SetOperation(s.clop)
	c:RegisterEffect(e4)
end
function s.tgfilter(c)
	return c:IsRace(RACE_WARRIOR) and c:IsAttribute(ATTRIBUTE_EARTH) and c:IsAbleToGrave()
end
function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return e:GetHandler():IsAttackPos() and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
	end
	Duel.SetOperationInfo(0, CATEGORY_POSITION, e:GetHandler(), 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
end
function s.tgop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local g = Duel.GetMatchingGroup(s.tgfilter, tp, LOCATION_DECK, 0, nil)
	if c:IsFaceup() and c:IsAttackPos() and c:IsRelateToEffect(e) and Duel.ChangePosition(c, POS_FACEUP_DEFENSE) and #g > 0 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
		local sg = g:Select(tp, 1, 1, nil)
		Duel.SendtoGrave(sg, REASON_EFFECT)
	end
end
function s.atklimit(e, c)
	return c == e:GetHandler()
end
function s.clfilter(c, e, tp)
	return c:IsRace(RACE_WARRIOR) and c:IsAttribute(ATTRIBUTE_EARTH) and c:IsLevelAbove(6) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.cltg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	local c = e:GetHandler()
	if chkc then
		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.clfilter(chkc, e, tp)
	end
	if chk == 0 then
		return Duel.GetMZoneCount(tp, c) > 0 and c:IsAbleToGrave() and Duel.IsExistingTarget(s.clfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectTarget(tp, s.clfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, c, 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
	Duel.GetAttacker():CreateEffectRelation(e)
end
function s.clop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local tc = Duel.GetFirstTarget()
	if
		c:IsRelateToEffect(e)
		and Duel.SendtoGrave(c, REASON_EFFECT) > 0
		and c:IsLocation(LOCATION_GRAVE)
		and tc:IsRelateToEffect(e)
		and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0
	then
		local a = Duel.GetAttacker()
		if a:IsAttackable() and a:IsRelateToEffect(e) and not a:IsImmuneToEffect(e) then
			Duel.BreakEffect()
			Duel.ChangeAttackTarget(tc)
		end
	end
end


Puppet
When this card is Normal Summoned: You can change this card to Defense Position, and if you do, send 1 EARTH Warrior monster from your Deck to your GY. Monsters your opponent controls that can attack must attack this card. Once per turn, when this card is targeted for an attack: You can target 1 Level 6 or higher EARTH Warrior monster in your GY; send this card from the field to the GY, and if you do, Special Summon that monster, then change the attack target to it.
-- Puppet
local s, id, o = GetID()
function s.initial_effect(c)
	--to grave
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_POSITION + CATEGORY_TOGRAVE)
	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetTarget(s.tgtg)
	e1:SetOperation(s.tgop)
	c:RegisterEffect(e1)
	--must attack
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_MUST_ATTACK)
	e2:SetRange(LOCATION_MZONE)
	e2:SetTargetRange(0, LOCATION_MZONE)
	c:RegisterEffect(e2)
	local e3 = e2:Clone()
	e3:SetCode(EFFECT_MUST_ATTACK_MONSTER)
	e3:SetValue(s.atklimit)
	c:RegisterEffect(e3)
	--castling
	local e4 = Effect.CreateEffect(c)
	e4:SetCategory(CATEGORY_TOGRAVE + CATEGORY_SPECIAL_SUMMON)
	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e4:SetCode(EVENT_BE_BATTLE_TARGET)
	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e4:SetCountLimit(1)
	e4:SetTarget(s.cltg)
	e4:SetOperation(s.clop)
	c:RegisterEffect(e4)
end
function s.tgfilter(c)
	return c:IsRace(RACE_WARRIOR) and c:IsAttribute(ATTRIBUTE_EARTH) and c:IsAbleToGrave()
end
function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return e:GetHandler():IsAttackPos() and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
	end
	Duel.SetOperationInfo(0, CATEGORY_POSITION, e:GetHandler(), 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
end
function s.tgop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local g = Duel.GetMatchingGroup(s.tgfilter, tp, LOCATION_DECK, 0, nil)
	if c:IsFaceup() and c:IsAttackPos() and c:IsRelateToEffect(e) and Duel.ChangePosition(c, POS_FACEUP_DEFENSE) and #g > 0 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
		local sg = g:Select(tp, 1, 1, nil)
		Duel.SendtoGrave(sg, REASON_EFFECT)
	end
end
function s.atklimit(e, c)
	return c == e:GetHandler()
end
function s.clfilter(c, e, tp)
	return c:IsRace(RACE_WARRIOR) and c:IsAttribute(ATTRIBUTE_EARTH) and c:IsLevelAbove(6) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.cltg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	local c = e:GetHandler()
	if chkc then
		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.clfilter(chkc, e, tp)
	end
	if chk == 0 then
		return Duel.GetMZoneCount(tp, c) > 0 and c:IsAbleToGrave() and Duel.IsExistingTarget(s.clfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectTarget(tp, s.clfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, c, 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
	Duel.GetAttacker():CreateEffectRelation(e)
end
function s.clop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local tc = Duel.GetFirstTarget()
	if
		c:IsRelateToEffect(e)
		and Duel.SendtoGrave(c, REASON_EFFECT) > 0
		and c:IsLocation(LOCATION_GRAVE)
		and tc:IsRelateToEffect(e)
		and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0
	then
		local a = Duel.GetAttacker()
		if a:IsAttackable() and a:IsRelateToEffect(e) and not a:IsImmuneToEffect(e) then
			Duel.BreakEffect()
			Duel.ChangeAttackTarget(tc)
		end
	end
end

