Sure, obtain a pointer to the entity, pass it to your function and use it there anywhere you would use "me" in a normal action. Use a while/wait loop in the function.