There are a number of Flood Protection scripts already done.
Use the Search feature, and also check through Google