name: King
card_text: If a "Red Dragon Archfiend" monster you control battles, during damage calculation: Make that monster you control unable to be destroyed by that battle, and if you do, Special Summon this card as a Normal Monster (Fiend-Type/Tuner/FIRE/Level 1/ATK 0/DEF 0). (This card is also still a Trap Card.)
external_ids: local SETCARD_ID_0 = 0x1045 --Red
  
lua: local SETCARD_ID_0 = 0x1045 --Red
  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:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	if tc:IsControler(1 - tp) then
  		tc = Duel.GetAttackTarget()
  	end
  	return tc and tc:IsSetCard(SETCARD_ID_0) and tc:IsRelateToBattle()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:IsCostChecked()
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_NORMAL_TRAP_MONSTER + TYPE_TUNER, 0, 0, 1, RACE_FIEND, ATTRIBUTE_FIRE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	if tc:IsControler(1 - tp) then
  		tc = Duel.GetAttackTarget()
  	end
  	if not tc or not tc:IsRelateToBattle() then
  		return
  	end
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	tc:RegisterEffect(e1)
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_NORMAL_TRAP_MONSTER + TYPE_TUNER, 0, 0, 1, RACE_FIEND, ATTRIBUTE_FIRE) then
  		return
  	end
  	c:AddMonsterAttribute(TYPE_NORMAL + TYPE_TUNER + TYPE_TRAP)
  	Duel.SpecialSummon(c, 0, tp, tp, true, false, POS_FACEUP)
  end
  
  
source_text: King
  If a "Red Dragon Archfiend" monster you control battles, during damage calculation: Make that monster you control unable to be destroyed by that battle, and if you do, Special Summon this card as a Normal Monster (Fiend-Type/Tuner/FIRE/Level 1/ATK 0/DEF 0). (This card is also still a Trap Card.)
target_text: -- King
  local SETCARD_ID_0 = 0x1045 --Red
  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:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	if tc:IsControler(1 - tp) then
  		tc = Duel.GetAttackTarget()
  	end
  	return tc and tc:IsSetCard(SETCARD_ID_0) and tc:IsRelateToBattle()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:IsCostChecked()
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_NORMAL_TRAP_MONSTER + TYPE_TUNER, 0, 0, 1, RACE_FIEND, ATTRIBUTE_FIRE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	if tc:IsControler(1 - tp) then
  		tc = Duel.GetAttackTarget()
  	end
  	if not tc or not tc:IsRelateToBattle() then
  		return
  	end
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	tc:RegisterEffect(e1)
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_NORMAL_TRAP_MONSTER + TYPE_TUNER, 0, 0, 1, RACE_FIEND, ATTRIBUTE_FIRE) then
  		return
  	end
  	c:AddMonsterAttribute(TYPE_NORMAL + TYPE_TUNER + TYPE_TRAP)
  	Duel.SpecialSummon(c, 0, tp, tp, true, false, POS_FACEUP)
  end
  
  