name: Sinister
card_text: When a monster you control is destroyed by a battle in which you took damage, and it was in face-up Attack Position at the start of the Damage Step and when it was destroyed: Special Summon 1 "Sinister Seed Token" (Plant-Type/DARK/Level 1/ATK 100/DEF 100) for every 500 points of battle damage you took from that battle.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 60406592 --Sinister Seed Token
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 60406592 --Sinister Seed Token
  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_BATTLE_DESTROYED)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	if not s.global_check then
  		s.global_check = true
  		s[0] = nil
  		s[1] = nil
  		s[2] = nil
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_BATTLE_DAMAGE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  		local ge2 = Effect.CreateEffect(c)
  		ge2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge2:SetCode(EVENT_PHASE_START + PHASE_DRAW)
  		ge2:SetOperation(s.clear)
  		Duel.RegisterEffect(ge2, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = ep
  	s[1] = math.floor(ev / 500)
  	s[2] = eg:GetFirst():GetBattleTarget()
  end
  function s.clear(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = nil
  	s[1] = nil
  	s[2] = nil
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return s[0] == tp and eg:GetCount() == 1 and eg:GetFirst() == s[2]
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = s[1]
  	if chk == 0 then
  		return ct > 0
  			and (ct == 1 or not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0))
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) >= ct
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_PLANT, ATTRIBUTE_DARK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, ct, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, ct, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ct = s[1]
  	if
  		(ct > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0))
  		or Duel.GetLocationCount(tp, LOCATION_MZONE) < ct
  		or not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_PLANT, ATTRIBUTE_DARK)
  	then
  		return
  	end
  	for i = 1, ct do
  		local token = Duel.CreateToken(tp, id + 1)
  		Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP)
  	end
  	Duel.SpecialSummonComplete()
  end
  
  
source_text: Sinister
  When a monster you control is destroyed by a battle in which you took damage, and it was in face-up Attack Position at the start of the Damage Step and when it was destroyed: Special Summon 1 "Sinister Seed Token" (Plant-Type/DARK/Level 1/ATK 100/DEF 100) for every 500 points of battle damage you took from that battle.
target_text: -- Sinister
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 60406592 --Sinister Seed Token
  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_BATTLE_DESTROYED)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	if not s.global_check then
  		s.global_check = true
  		s[0] = nil
  		s[1] = nil
  		s[2] = nil
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_BATTLE_DAMAGE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  		local ge2 = Effect.CreateEffect(c)
  		ge2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge2:SetCode(EVENT_PHASE_START + PHASE_DRAW)
  		ge2:SetOperation(s.clear)
  		Duel.RegisterEffect(ge2, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = ep
  	s[1] = math.floor(ev / 500)
  	s[2] = eg:GetFirst():GetBattleTarget()
  end
  function s.clear(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = nil
  	s[1] = nil
  	s[2] = nil
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return s[0] == tp and eg:GetCount() == 1 and eg:GetFirst() == s[2]
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = s[1]
  	if chk == 0 then
  		return ct > 0
  			and (ct == 1 or not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0))
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) >= ct
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_PLANT, ATTRIBUTE_DARK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, ct, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, ct, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ct = s[1]
  	if
  		(ct > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0))
  		or Duel.GetLocationCount(tp, LOCATION_MZONE) < ct
  		or not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_PLANT, ATTRIBUTE_DARK)
  	then
  		return
  	end
  	for i = 1, ct do
  		local token = Duel.CreateToken(tp, id + 1)
  		Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP)
  	end
  	Duel.SpecialSummonComplete()
  end
  
  