name: Training
card_text: If a face-up monster(s) "Fur Hire" you control is destroyed by battle or an opponent's card effect: You can target 1 of those monsters; Special Summon 1 monster "Fur Hire" from your Deck, whose Level is lower than that target's original Level. You can only use this effect of "Training Fur Hire, Fur All Your Training Needs" once per turn.
external_ids: local SETCARD_ID_0 = 0x114 --Fur
  
lua: local SETCARD_ID_0 = 0x114 --Fur
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter1(c, e, tp, rp)
  	local lv = c:GetLevel()
  	return (c:IsReason(REASON_BATTLE) or (rp == 1 - tp and c:IsReason(REASON_EFFECT)))
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_MONSTER)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousControler(tp)
  		and c:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED)
  		and c:IsCanBeEffectTarget(e)
  		and lv > 0
  		and Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_DECK, 0, 1, nil, e, tp, lv)
  end
  function s.spfilter2(c, e, tp, lv)
  	return c:GetLevel() < lv and 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, chkc)
  	if chkc then
  		return eg:IsContains(chkc) and s.spfilter1(chkc, e, tp, rp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and eg:IsExists(s.spfilter1, 1, nil, e, tp, rp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = eg:FilterSelect(tp, s.spfilter1, 1, 1, nil, e, tp, rp)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 or not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter2, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, tc:GetLevel())
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Training
  If a face-up monster(s) "Fur Hire" you control is destroyed by battle or an opponent's card effect: You can target 1 of those monsters; Special Summon 1 monster "Fur Hire" from your Deck, whose Level is lower than that target's original Level. You can only use this effect of "Training Fur Hire, Fur All Your Training Needs" once per turn.
target_text: -- Training
  local SETCARD_ID_0 = 0x114 --Fur
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter1(c, e, tp, rp)
  	local lv = c:GetLevel()
  	return (c:IsReason(REASON_BATTLE) or (rp == 1 - tp and c:IsReason(REASON_EFFECT)))
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_MONSTER)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousControler(tp)
  		and c:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED)
  		and c:IsCanBeEffectTarget(e)
  		and lv > 0
  		and Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_DECK, 0, 1, nil, e, tp, lv)
  end
  function s.spfilter2(c, e, tp, lv)
  	return c:GetLevel() < lv and 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, chkc)
  	if chkc then
  		return eg:IsContains(chkc) and s.spfilter1(chkc, e, tp, rp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and eg:IsExists(s.spfilter1, 1, nil, e, tp, rp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = eg:FilterSelect(tp, s.spfilter1, 1, 1, nil, e, tp, rp)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 or not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter2, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, tc:GetLevel())
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  