Output directional values of a copter

I need the direction values and the speed at which the copter needs to move I’ll use it to control an external setup.

I have tried the roll and pitch values but it outputs the angle, is it possible to get the directional value for different modes like althold or loiter?

I am using lua script but not sure if there are functions that can return these values.