it's based on guild id .... read flagemblem ...
getcastledate with parameter of 1 return the guild id of that particular guild who owned the castle....
official Emperium Behaviours only applicable to Guild Castle ..
anyway i remember AnnieRuru has made a patch for it somewhere in her KOE topic ...
check her topic and grab the patch file and apply it.