Generate a YGOPro Lua script for the following Yu-Gi-Oh card effect:
Each time an A-Counter(s) is removed from a card on the field, place 1 A-Counter on this card. If this card is destroyed: Distribute A-Counters among face-up monsters on the field, equal to the number of A-Counters this card had on the field. * The above text is unofficial and describes the card's functionality in the OCG.
--「A」細胞培養装置
--"A" Cell Incubator
local s,id=GetID()
function s.initial_effect(c)
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e1)
	--counter1
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e2:SetRange(LOCATION_SZONE)
	e2:SetCode(EVENT_REMOVE_COUNTER+COUNTER_A)
	e2:SetOperation(s.ctop1)
	c:RegisterEffect(e2)
	--register before leaving
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
	e3:SetCode(EVENT_LEAVE_FIELD_P)
	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e3:SetOperation(s.regop)
	c:RegisterEffect(e3)
	--place counters when leaving
	local e4=Effect.CreateEffect(c)
	e4:SetDescription(aux.Stringid(id,0))
	e4:SetCategory(CATEGORY_COUNTER)
	e4:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)
	e4:SetCode(EVENT_DESTROYED)
	e4:SetCondition(s.ctcon2)
	e4:SetOperation(s.ctop2)
	e4:SetLabelObject(e3)
	c:RegisterEffect(e4)
end
s.counter_place_list={COUNTER_A}
function s.ctop1(e,tp,eg,ep,ev,re,r,rp)
	e:GetHandler():AddCounter(COUNTER_NEED_ENABLE+COUNTER_A,1)
end
function s.regop(e,tp,eg,ep,ev,re,r,rp)
	local ct=e:GetHandler():GetCounter(COUNTER_A)
	e:SetLabel(ct)
end
function s.ctcon2(e,tp,eg,ep,ev,re,r,rp)
	local ct=e:GetLabelObject():GetLabel()
	e:SetLabel(ct)
	return ct>0
end
function s.ctop2(e,tp,eg,ep,ev,re,r,rp)
	local ct=e:GetLabel()
	local g=Duel.GetMatchingGroup(Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,nil)
	if #g==0 then return end
	for i=1,ct do
		Duel.Hint(HINT_SELECTMSG,tp,aux.Stringid(id,1))
		local sg=g:Select(tp,1,1,nil)
		sg:GetFirst():AddCounter(COUNTER_A,1)
	end
end