name: Megalith
card_text: You can Ritual Summon this card with a "Megalith" card. If this card is Ritual Summoned: You can target 1 Ritual Monster in your GY; this card's Level becomes the Level of that target, then add that target to your hand. During the Main Phase (Quick Effect): You can activate this effect; Ritual Summon 1 "Megalith" Ritual Monster from your hand or Deck by Tributing monsters from your hand or field whose total Levels equal or exceed the Level of the Ritual Monster. You can only use each effect of "Megalith Phul" once per turn.
external_ids: local SETCARD_ID_0 = 0x138 --Megalith
  
lua: local SETCARD_ID_0 = 0x138 --Megalith
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--ritual summon
  	local e2 = aux.AddRitualProcGreater2(c, s.filter, LOCATION_HAND + LOCATION_DECK, nil, nil, true)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.rscon)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c, lv)
  	return c:IsType(TYPE_RITUAL) and c:IsType(TYPE_MONSTER) and not c:IsLevel(lv) and c:IsAbleToHand()
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	local lv = c:GetLevel()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.thfilter(chkc, lv)
  	end
  	if chk == 0 then
  		return c:IsLevelAbove(1) and c:IsRelateToEffect(e) and Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil, lv)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, lv)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsFaceup() and c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		local lv = tc:GetLevel()
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  		e1:SetRange(LOCATION_MZONE)
  		e1:SetValue(lv)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  		Duel.BreakEffect()
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.filter(c, e, tp, chk)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.rscon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  
  
source_text: Megalith
  You can Ritual Summon this card with a "Megalith" card. If this card is Ritual Summoned: You can target 1 Ritual Monster in your GY; this card's Level becomes the Level of that target, then add that target to your hand. During the Main Phase (Quick Effect): You can activate this effect; Ritual Summon 1 "Megalith" Ritual Monster from your hand or Deck by Tributing monsters from your hand or field whose total Levels equal or exceed the Level of the Ritual Monster. You can only use each effect of "Megalith Phul" once per turn.
target_text: -- Megalith
  local SETCARD_ID_0 = 0x138 --Megalith
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--ritual summon
  	local e2 = aux.AddRitualProcGreater2(c, s.filter, LOCATION_HAND + LOCATION_DECK, nil, nil, true)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.rscon)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c, lv)
  	return c:IsType(TYPE_RITUAL) and c:IsType(TYPE_MONSTER) and not c:IsLevel(lv) and c:IsAbleToHand()
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	local lv = c:GetLevel()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.thfilter(chkc, lv)
  	end
  	if chk == 0 then
  		return c:IsLevelAbove(1) and c:IsRelateToEffect(e) and Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil, lv)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, lv)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsFaceup() and c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		local lv = tc:GetLevel()
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  		e1:SetRange(LOCATION_MZONE)
  		e1:SetValue(lv)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  		Duel.BreakEffect()
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.filter(c, e, tp, chk)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.rscon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  
  