For starters, you never move from State 1 to State 2, which means the light (assuming it turns on) never turns off.
Secondly, even if you did move to State 2, you never set Activated to 1. This means that if you move to State 3, the light will never turn off.
Thirdly, you aren't checking for states correctly. It should be state=0, not state0.
And although you didn't explain what the problem was, the above 3 points clarify why your script doesn't work. Simply put, there are too many errors in your script for it to work. I applaud you for taking the time to at least try to script (and trust me, it gets easier). Try the following and let us know if this works (I'm not at my home pc, so I may miss a command or two):
;Artificial Intelligence Script
;Header
desc = Motion Light
:state=0,plrdistwithin=300:lighton
:state=0,plrdistfurther=300:lightoff
Priest of the Church of Joe Wood