Ignore Bell's post (sorry Bell), that's not relevant to what you want to do.
If you create a database NPC named, say, AccessControl, you can access public functions in the script simply by calling them from any serverside script:
PHP Code:
AccessControl.myFunction();
Inside the AccessControl script, you'd want to have something like this:
PHP Code:
public function addAccountToLevel(levelName, account) {
this.access.(@ levelName).add(account);
this.save();
}
public function removeAccountFromLevel(levelName, account) {
this.access.(@ levelName).remove(account);
this.save();
}
public function accountHasAccess(levelName, account) {
return (account in this.access.(@ levelName));
}
// this seems to prevent the DB NPC from rolling back
function save() {
this.trigger("update");
}
Now you'll want to place a script inside the level that allows you to control this. You don't have to do it by level, either, as long as you're using something consistent like "house_cbk1994" throughout all levels you want to have the same access.
An example of the level script:
PHP Code:
function onPlayerEnters() {
if (! AccessControl.accountHasAccess(this.level.name, player.account)) {
player.chat = "I'm not allowed here!";
player.setLevel2("osl.nw", 32, 32);
}
}