Here is a slightly modified version of a script that I'm using for a restricted store house for the Crescent Pirates on Kingdoms Debug. It probably isn't perfect so I'd be grateful for any comments that could help me improve it.
Installation
To get the script working correctly a few things will have to be edited with the script.
- Change "server.access = {{"cyan3",true}};" on line 8 to another relevant account name. This will automatically add the account as an admin on creation of the script.
- Change "server.access = {{"cyan3",true}};" on line 33 to a relevant account name. This account will stay as an admin when the :resetaccess command is called.
- Change "player.setlevel2("mylevel.nw", 30, 30);" to the levelname and x/y of the level you want to restrict access to.
Script Commands
Commands for admins:
- :addadmin <accountname> - Adds the account as an admin.
- :addaccess <accountname> - Gives account access to the level.
- :removeaccess <accountname> - Removes account from accessing the level.
- :resetaccess - Resets the list of all accounts expect the one specified in the script.
- :viewaccess - Outputs a list admins and accounts with access.
PHP Code:
//Made by Felix Lionheart (*cyan3)
function onCreated() {
this.setShape(1,6*16,2*16);
if (server.access.size() <= 0) {
server.access = {{"cyan3",true}};
}
}
function onPlayerChats() {
// only admins can use these commands
for (temp.access : server.access) {
if (temp.access[0] == player.account) {
if (temp.access[1] == true) {
if (player.chat.starts(":addadmin")) { // add account to admin
server.access.add({player.chat.substring(10),true});
player.say2(player.chat.substring(10) @ " has been added as an" NL "Admin.");
} else if (player.chat.starts(":addaccess")) { // add account to access
server.access.add({player.chat.substring(11),false});
player.say2(player.chat.substring(11) @ " has been added.");
} else if (player.chat.starts(":removeaccess")) { //remove account as access
for (i=0; i<server.access.size(); i++) {
if (server.access[i][0] == player.chat.substring(14)) { temp.index = i;
server.access.delete(i);
player.say2(player.chat.substring(14) @ " has been removed.");
}
}
} else if (player.chat.starts(":resetaccess")) { // resets the access list
server.access = {{"cyan3",true}};
player.say2("Access list has been reset.");
} else if (player.chat.starts(":viewaccess")) { // output list of access
sendrpgmessage("<b>List of accounts with access:<b>");
for (temp.accesslist : server.access) {
sendrpgmessage(accesslist);
player.say2("Text arrived in the RPG console." NL "Press F2 to view it!");
}
}
}
}
}
}
function onPlayerTouchsMe() {
for (temp.access : server.access) {
if (temp.access[0] == player.account) {
player.setlevel2("mylevel.nw", 30, 30);
} else {
player.say2("You are not allowed to enter!");
}
}
}