name: B-Buster
card_text: Once per turn, you can either: Target 1 LIGHT Machine monster you control; equip this card to that target, OR: Unequip this card and Special Summon it. A monster equipped with this card is unaffected by your opponent's Spell effects, also if the equipped monster would be destroyed by battle or card effect, destroy this card instead. If this card is sent from the field to the GY: You can add 1 Union monster from your Deck to your hand.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.EnableUnionAttribute(c, s.filter)
  	--immune
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_EQUIP)
  	e4:SetCode(EFFECT_IMMUNE_EFFECT)
  	e4:SetValue(s.efilter)
  	c:RegisterEffect(e4)
  	--to hand
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetCondition(s.thcon)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  end
  s.has_text_type = TYPE_UNION
  function s.filter(c)
  	return c:IsRace(RACE_MACHINE) and c:IsAttribute(ATTRIBUTE_LIGHT)
  end
  function s.efilter(e, te)
  	return te:GetOwnerPlayer() ~= e:GetHandlerPlayer() and te:GetOwner() ~= e:GetOwner() and te:IsActiveType(TYPE_SPELL)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_UNION) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: B-Buster
  Once per turn, you can either: Target 1 LIGHT Machine monster you control; equip this card to that target, OR: Unequip this card and Special Summon it. A monster equipped with this card is unaffected by your opponent's Spell effects, also if the equipped monster would be destroyed by battle or card effect, destroy this card instead. If this card is sent from the field to the GY: You can add 1 Union monster from your Deck to your hand.
target_text: -- B-Buster
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.EnableUnionAttribute(c, s.filter)
  	--immune
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_EQUIP)
  	e4:SetCode(EFFECT_IMMUNE_EFFECT)
  	e4:SetValue(s.efilter)
  	c:RegisterEffect(e4)
  	--to hand
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetCondition(s.thcon)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  end
  s.has_text_type = TYPE_UNION
  function s.filter(c)
  	return c:IsRace(RACE_MACHINE) and c:IsAttribute(ATTRIBUTE_LIGHT)
  end
  function s.efilter(e, te)
  	return te:GetOwnerPlayer() ~= e:GetHandlerPlayer() and te:GetOwner() ~= e:GetOwner() and te:IsActiveType(TYPE_SPELL)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_UNION) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  