There are many books and different approaches to “playing jazz” but when you boil it down what you are trying to do is improvise melodies which emphasize within their construction the same harmony that is being emphasized in the rest of the band. When playing on tonal music which I define here as moving through different tonalities consistent with western common movements, one must construct melodies which cadence in harmonic rhythm. This can be easier said than done.
One way which Lee Konitz showed me as a young student was to improvise off of the melody, primarily embellishing the melody melodically and rhythmically. This is also a great way to practice creativity.
To become more familiar with the underlying harmony so as to be able to create more sophisticated melodies and become “freer” within the parameters of the song, I recommend a process of recognizing tonalities and movements as opposed to individual chords shown to me by Barry Harris.
Learning which chords are “moving” you from one place to another and which chords are your “destinations” gives you a takeoff and landing target. When it comes to scales I believe in using as few scales as possible and knowing in great depth how to organize the notes in order that they define the tonalities you are improvising through. Doing this can be a challenge and take a while. Study of historical language and how jazz musicians throughout history have organized their melodies gives you a starting point. Just like a language its virtually impossible to speak well without hearing it so…listen listen listen!