name: Ancient
card_text: You must send this card to the GY during your 2nd Standby Phase after activation. Once per turn, during your Main Phase: Toss a coin and if the result is heads, send this card to the GY. If this card is sent from the Spell & Trap Zone to the GY: You can activate this effect; this turn, your opponent cannot activate cards or effects in response to the activation of your "Ancient Warriors" cards and effects, also until the end of the turn, all "Ancient Warriors" Effect Monsters you currently control gain this effect.
  ● When this card declares an attack: You can destroy 1 card your opponent controls.
external_ids: local SETCARD_ID_0 = 0x137 --Ancient
  
lua: local SETCARD_ID_0 = 0x137 --Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetDescription(aux.Stringid(id, 0))
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	e0:SetTarget(s.target)
  	c:RegisterEffect(e0)
  	--coin
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_COIN + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.cointg)
  	e1:SetOperation(s.coinop)
  	c:RegisterEffect(e1)
  	--effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.efcon)
  	e2:SetTarget(s.eftg)
  	e2:SetOperation(s.efop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local c = e:GetHandler()
  	--send to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e1:SetCountLimit(1)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCondition(s.stgcon)
  	e1:SetOperation(s.stgop)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 2)
  	c:SetTurnCounter(0)
  	c:RegisterEffect(e1)
  end
  function s.stgcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.stgop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ct = c:GetTurnCounter()
  	ct = ct + 1
  	c:SetTurnCounter(ct)
  	if ct == 2 then
  		Duel.SendtoGrave(c, REASON_RULE)
  	end
  end
  function s.cointg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGrave()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COIN, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, e:GetHandler(), 0, 0, 0)
  end
  function s.coinop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local res = Duel.TossCoin(tp, 1)
  	if res == 1 then
  		Duel.SendtoGrave(c, REASON_EFFECT)
  	end
  end
  function s.efcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_SZONE)
  end
  function s.effilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_EFFECT)
  end
  function s.eftg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  end
  function s.efop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetOperation(s.chainop)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local g = Duel.GetMatchingGroup(s.effilter, tp, LOCATION_MZONE, 0, nil)
  	local tc = g:GetFirst()
  	while tc do
  		local e2 = Effect.CreateEffect(tc)
  		e2:SetDescription(aux.Stringid(id, 3))
  		e2:SetCategory(CATEGORY_DESTROY)
  		e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  		e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  		e2:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e2:SetTarget(s.destg)
  		e2:SetOperation(s.desop)
  		tc:RegisterEffect(e2)
  		tc = g:GetNext()
  	end
  end
  function s.chainop(e, tp, eg, ep, ev, re, r, rp)
  	if re:GetHandler():IsSetCard(SETCARD_ID_0) and ep == tp then
  		Duel.SetChainLimit(s.chainlm)
  	end
  end
  function s.chainlm(e, ep, tp)
  	return tp == ep
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  
source_text: Ancient
  You must send this card to the GY during your 2nd Standby Phase after activation. Once per turn, during your Main Phase: Toss a coin and if the result is heads, send this card to the GY. If this card is sent from the Spell & Trap Zone to the GY: You can activate this effect; this turn, your opponent cannot activate cards or effects in response to the activation of your "Ancient Warriors" cards and effects, also until the end of the turn, all "Ancient Warriors" Effect Monsters you currently control gain this effect.
  ● When this card declares an attack: You can destroy 1 card your opponent controls.
target_text: -- Ancient
  local SETCARD_ID_0 = 0x137 --Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetDescription(aux.Stringid(id, 0))
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	e0:SetTarget(s.target)
  	c:RegisterEffect(e0)
  	--coin
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_COIN + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.cointg)
  	e1:SetOperation(s.coinop)
  	c:RegisterEffect(e1)
  	--effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.efcon)
  	e2:SetTarget(s.eftg)
  	e2:SetOperation(s.efop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local c = e:GetHandler()
  	--send to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e1:SetCountLimit(1)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCondition(s.stgcon)
  	e1:SetOperation(s.stgop)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 2)
  	c:SetTurnCounter(0)
  	c:RegisterEffect(e1)
  end
  function s.stgcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.stgop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ct = c:GetTurnCounter()
  	ct = ct + 1
  	c:SetTurnCounter(ct)
  	if ct == 2 then
  		Duel.SendtoGrave(c, REASON_RULE)
  	end
  end
  function s.cointg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGrave()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COIN, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, e:GetHandler(), 0, 0, 0)
  end
  function s.coinop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local res = Duel.TossCoin(tp, 1)
  	if res == 1 then
  		Duel.SendtoGrave(c, REASON_EFFECT)
  	end
  end
  function s.efcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_SZONE)
  end
  function s.effilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_EFFECT)
  end
  function s.eftg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  end
  function s.efop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetOperation(s.chainop)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local g = Duel.GetMatchingGroup(s.effilter, tp, LOCATION_MZONE, 0, nil)
  	local tc = g:GetFirst()
  	while tc do
  		local e2 = Effect.CreateEffect(tc)
  		e2:SetDescription(aux.Stringid(id, 3))
  		e2:SetCategory(CATEGORY_DESTROY)
  		e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  		e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  		e2:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e2:SetTarget(s.destg)
  		e2:SetOperation(s.desop)
  		tc:RegisterEffect(e2)
  		tc = g:GetNext()
  	end
  end
  function s.chainop(e, tp, eg, ep, ev, re, r, rp)
  	if re:GetHandler():IsSetCard(SETCARD_ID_0) and ep == tp then
  		Duel.SetChainLimit(s.chainlm)
  	end
  end
  function s.chainlm(e, ep, tp)
  	return tp == ep
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  