alternatively, sidestepping the function idea, call the following script -
;stick like glue
dist_warn = false
#loop
? (player distance lead_unit_name >= 100) and (not (dist_warn)): goto "warning"
? (player distance lead_unit_name >= 150) and dist_warn: goto "court_martial"
~0.5
goto "loop"
#warning
player sidechat format ["Hey %1! Get your ass back here or there'll be trouble!",name player]
dist_warn = true
goto "loop"
#court_martial
;all the great stuff in here
exit
just to clarify what it does -
it sets a variable to say whether or not the player has been warned. if the player hasn't been warned and gets over 100 meters away, a warning is issued, and the warning variable is set to true. this ensures that the warning doesn't repeat over and over.
if the player then gets over 150 meters away, the court martial begins.
untested, but i think that should do it.