Assuming you are moving along a single linear axis for painting, another approach would be to not use gcode to enable your spray.
Instead fire it using a hal component that monitored axis.L.pos−cmd and had an output pin that enabled the spray based on specific axis coordinates. Eg. turn on at 3" and off at 4". You could still do it for multi axis moves, but there would be a bit more maths involved. This would totally eliminate any possible issue with gcode affecting motion.