Start with a simple text description of what you want to happen. Then start adding logic functions that perform the actions dictated by these steps, one at a time. Don't try to figure out the whole thing at once - break it down to simple tasks, and as you accomplish one add others. Understand that as you add new steps you may have to go back and revise the previous "done" steps to work with the new ones.
Post your trial code here, including the model and manufacturer of the PLC and the software you are using.