name: Gorz
card_text: When you take damage from a card in your opponent's possession: You can Special Summon this card from your hand. You must control no cards to activate and to resolve this effect. When this card is Special Summoned by its effect: Activate the appropriate effect, based on the type of damage;
  ● Battle damage: Special Summon 1 "Emissary of Darkness Token" (Fairy/LIGHT/Level 7/ATK ?/DEF ?). Its ATK/DEF are each equal to the amount of battle damage you took.
  ● Effect damage: Inflict damage to your opponent equal to the damage you took.
external_ids: local CARD_ID_0 = 44330099 --Emissary of Darkness Token
  
lua: local CARD_ID_0 = 44330099 --Emissary of Darkness Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCode(EVENT_DAMAGE)
  	e1:SetCondition(s.sumcon)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--special summon success
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetCondition(s.sumcon2)
  	e2:SetTarget(s.sumtg2)
  	e2:SetOperation(s.sumop2)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetCondition(s.sumcon3)
  	e3:SetTarget(s.sumtg3)
  	e3:SetOperation(s.sumop3)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  end
  function s.filter(c)
  	return not c:IsStatus(STATUS_LEAVE_CONFIRMED)
  end
  function s.sumcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp and 1 - tp == rp and not Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.sumop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local typ = bit.band(r, REASON_BATTLE) ~= 0 and 1 or 2
  	e:SetLabel(typ, ev)
  	Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, false, false, POS_FACEUP)
  end
  function s.sumcon2(e, tp, eg, ep, ev, re, r, rp)
  	local typ, val = e:GetLabelObject():GetLabel()
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and typ == 1
  end
  function s.sumtg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.sumop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local typ, val = e:GetLabelObject():GetLabel()
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, -2, -2, 7, RACE_FAIRY, ATTRIBUTE_LIGHT) then
  		return
  	end
  	local token = Duel.CreateToken(tp, id + 1)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SET_ATTACK)
  	e1:SetValue(val)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TOFIELD)
  	token:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_SET_DEFENSE)
  	e2:SetValue(val)
  	e2:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TOFIELD)
  	token:RegisterEffect(e2)
  	Duel.SpecialSummon(token, 0, tp, tp, false, false, POS_FACEUP)
  end
  function s.sumcon3(e, tp, eg, ep, ev, re, r, rp)
  	local typ, val = e:GetLabelObject():GetLabel()
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and typ == 2
  end
  function s.sumtg3(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local typ, d = e:GetLabelObject():GetLabel()
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(d)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, d)
  end
  function s.sumop3(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  
  
source_text: Gorz
  When you take damage from a card in your opponent's possession: You can Special Summon this card from your hand. You must control no cards to activate and to resolve this effect. When this card is Special Summoned by its effect: Activate the appropriate effect, based on the type of damage;
  ● Battle damage: Special Summon 1 "Emissary of Darkness Token" (Fairy/LIGHT/Level 7/ATK ?/DEF ?). Its ATK/DEF are each equal to the amount of battle damage you took.
  ● Effect damage: Inflict damage to your opponent equal to the damage you took.
target_text: -- Gorz
  local CARD_ID_0 = 44330099 --Emissary of Darkness Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCode(EVENT_DAMAGE)
  	e1:SetCondition(s.sumcon)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--special summon success
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetCondition(s.sumcon2)
  	e2:SetTarget(s.sumtg2)
  	e2:SetOperation(s.sumop2)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetCondition(s.sumcon3)
  	e3:SetTarget(s.sumtg3)
  	e3:SetOperation(s.sumop3)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  end
  function s.filter(c)
  	return not c:IsStatus(STATUS_LEAVE_CONFIRMED)
  end
  function s.sumcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp and 1 - tp == rp and not Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.sumop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local typ = bit.band(r, REASON_BATTLE) ~= 0 and 1 or 2
  	e:SetLabel(typ, ev)
  	Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, false, false, POS_FACEUP)
  end
  function s.sumcon2(e, tp, eg, ep, ev, re, r, rp)
  	local typ, val = e:GetLabelObject():GetLabel()
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and typ == 1
  end
  function s.sumtg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.sumop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local typ, val = e:GetLabelObject():GetLabel()
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, -2, -2, 7, RACE_FAIRY, ATTRIBUTE_LIGHT) then
  		return
  	end
  	local token = Duel.CreateToken(tp, id + 1)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SET_ATTACK)
  	e1:SetValue(val)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TOFIELD)
  	token:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_SET_DEFENSE)
  	e2:SetValue(val)
  	e2:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TOFIELD)
  	token:RegisterEffect(e2)
  	Duel.SpecialSummon(token, 0, tp, tp, false, false, POS_FACEUP)
  end
  function s.sumcon3(e, tp, eg, ep, ev, re, r, rp)
  	local typ, val = e:GetLabelObject():GetLabel()
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and typ == 2
  end
  function s.sumtg3(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local typ, d = e:GetLabelObject():GetLabel()
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(d)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, d)
  end
  function s.sumop3(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  
  