The fact: you need to know how many times a given script has been run lately. This task is quite trivial if you keep the number in a given temporary file.
Read it here
What I am going to show you instead, is how to store the number just directly in the same script.
Oh well, not that this is too hard to do but its a nice trick that may give you an idea of how self-extracting script do work (e.g. nvidia official drivers and common linux games are shipped with this type of container).