name: Cash
card_text: When your opponent activates a Spell/Trap Card, or monster effect, by paying their Life Points: Negate the activation, and if you do, return it to the Deck.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	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
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_PAY_LPCOST)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local cid = Duel.GetCurrentChain()
  	if cid > 0 then
  		s[0] = Duel.GetChainInfo(cid, CHAININFO_CHAIN_ID)
  	end
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and Duel.GetChainInfo(0, CHAININFO_CHAIN_ID) == s[0] and (re:IsActiveType(TYPE_MONSTER) or re:IsHasType(EFFECT_TYPE_ACTIVATE)) and Duel.IsChainNegatable(ev)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return aux.ndcon(tp, re)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, eg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ec = re:GetHandler()
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		ec:CancelToGrave()
  		Duel.SendtoDeck(ec, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  
source_text: Cash
  When your opponent activates a Spell/Trap Card, or monster effect, by paying their Life Points: Negate the activation, and if you do, return it to the Deck.
target_text: -- Cash
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	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
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_PAY_LPCOST)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local cid = Duel.GetCurrentChain()
  	if cid > 0 then
  		s[0] = Duel.GetChainInfo(cid, CHAININFO_CHAIN_ID)
  	end
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and Duel.GetChainInfo(0, CHAININFO_CHAIN_ID) == s[0] and (re:IsActiveType(TYPE_MONSTER) or re:IsHasType(EFFECT_TYPE_ACTIVATE)) and Duel.IsChainNegatable(ev)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return aux.ndcon(tp, re)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, eg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ec = re:GetHandler()
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		ec:CancelToGrave()
  		Duel.SendtoDeck(ec, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  