Maybe a bit ugly, but here we use rle() to find the runs of TRUE values. Then use seq.int() to index the groups (which would also make groups for FALSE), but we multiply by the value so the FALSE indexes are turned to 0.
x <- c(FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE)
with(rle(x), unlist(Map(`*`, sapply(lengths, seq.int), values)))
# [1] 0 0 1 2 3 0 1 0 1 2 0