name: Medium
card_text: If your opponent controls 4 or more cards than you do, you can Special Summon this card (from your hand). Your opponent can only activate 1 Spell/Trap Card each turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	c:RegisterEffect(e1)
  	--effect count
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetOperation(s.count)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_CHAIN_NEGATED)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetOperation(s.rst)
  	c:RegisterEffect(e3)
  	--activate limit
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetTargetRange(0, 1)
  	e4:SetCondition(s.econ)
  	e4:SetValue(s.elimit)
  	c:RegisterEffect(e4)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD) - Duel.GetFieldGroupCount(tp, LOCATION_ONFIELD, 0) >= 4
  end
  function s.count(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp or not re:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		return
  	end
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + 0x3ff0000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.rst(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp or not re:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		return
  	end
  	e:GetHandler():ResetFlagEffect(id)
  end
  function s.econ(e)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.elimit(e, te, tp)
  	return te:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  
  
source_text: Medium
  If your opponent controls 4 or more cards than you do, you can Special Summon this card (from your hand). Your opponent can only activate 1 Spell/Trap Card each turn.
target_text: -- Medium
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	c:RegisterEffect(e1)
  	--effect count
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetOperation(s.count)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_CHAIN_NEGATED)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetOperation(s.rst)
  	c:RegisterEffect(e3)
  	--activate limit
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetTargetRange(0, 1)
  	e4:SetCondition(s.econ)
  	e4:SetValue(s.elimit)
  	c:RegisterEffect(e4)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD) - Duel.GetFieldGroupCount(tp, LOCATION_ONFIELD, 0) >= 4
  end
  function s.count(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp or not re:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		return
  	end
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + 0x3ff0000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.rst(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp or not re:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		return
  	end
  	e:GetHandler():ResetFlagEffect(id)
  end
  function s.econ(e)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.elimit(e, te, tp)
  	return te:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  
  