There is another function I may be putting not be giving this error?
You use the function rid2name, that uses the account id to get the name of the currently logged in character.
If that player is logged out it will fail because the account id isn't online anymore.