How to avoid doing unpaid work as a writer

A writer is the first person who starts to work in every film or TV production. This creative part of the job is often done before any agreement is reached. We write to fulfill our artistic needs, the same way that dancers dance, painters draw, musicians compose and play music. Even when there is nobody to watch, even when there is no payment promised. Still, a writer has to get paid when his work comes on stage. There are two main scenarios for that: either you manage to promote one of your scripts to production, or a producer/director assigns to you the job.
If you have an idea for a script, write it down as a proposal and use this short version of your script to promote it. You must include a synopsis of the plot and a structure that you plan to follow for the episodes. This, apart from saving you from collecting unwanted scripts in your desktop, will help you foresee if you have enough elements to support your plot until the ending. Many screenwriters write the first 1-2 episodes of a TV series or the complete script for a film and then get in contact with a producer or a director. You can do that if you want of course, but the safe way is to find a producer or a director and discuss your idea before you start writing the script. In any case you must expect their suggestions to alter the plot and be prepared to follow them.
If you are assigned to write a script by a production company or a director you should first agree to the terms of this collaboration. You will be asked to write a short brief of the idea and the one-line structure of your play/script in one or two pages. In any case you must agree to a deadline to deliver the final draft of your script and arrange the payment conditions. It is acceptable for writers to request for an advance payment and a contract. Always remember that without your script there would be no play, film or TV series!