I see a few annoying logic issues with scripting if its even possible... I would personally recommend using a COA (Change of Authorization) request sent to Mikrotik. This is better 1) you would have a real language to work with, and 2) its a very similar process to the radius handshake that set the rate limit.
http://wiki.mikrotik.com/wiki/Manual:RADIUS_Client#Change_of_Authorization
I think a script would have to use the queues vs the rate limit in the hotspot since this would be set from the radius request not the "user" profile. you will also have to tell when an account has already been set, how many times, and what to do when "a" gets off and only "b" is online... lots of room for error.
With the COA you can just query for the original rate limits divide by active sessions in rad act and spit the values out.