Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Level Restriction Script (https://forums.graalonline.com/forums/showthread.php?t=134259470)

cyan3 06-11-2010 05:54 PM

Level Restriction Script
 
1 Attachment(s)
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.
  1. 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.
  2. 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.
  3. 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=0i<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"3030);
  } else {
    
player.say2("You are not allowed to enter!");
   }
  }
 } 


cbk1994 06-11-2010 06:05 PM

Nice. The only thing I notice is the inconsistent formatting; two spaces is the standard indent for Gscript.

Besides that, it looks good. Might be better to use a DB NPC instead of a server flag, but there's not a real advantage to that, mostly just personal preference. I know that's probably not possible with the restrictions you work with on Kingdoms anyway ^^.

Nice work.

xAndrewx 06-11-2010 06:07 PM

Not very practical... it would be better with a level restriction which has its own admins and people that can enter. (individual serverr level flags)

Also, whats the 2nd param do? =o
HTML Code:

{{"cyan3",true}};"

cbk1994 06-11-2010 06:09 PM

Quote:

Originally Posted by xAndrewx (Post 1581397)
Not very practical... it would be better with a level restriction which has its own admins and people that can enter. (individual serverr level flags)

Just a note, it's better to use 'server' for this kind of thing since 'serverr' is sent to every player.

Quote:

Also, whats the 2nd param do? =o
HTML Code:

{{"cyan3",true}};"

Looks like it's whether they're an admin (can add people) or if they just have access.

cyan3 06-11-2010 06:11 PM

Quote:

Originally Posted by cbk1994 (Post 1581398)
Just a note, it's better to use 'server' for this kind of thing since 'serverr' is sent to every player.



Looks like it's whether they're an admin (can add people) or if they just have access.

Correct. I wanted to stick with one server flag instead of two for admin / access.

Tigairius 06-11-2010 06:17 PM

I don't know if this makes it any easier to read or not, but here's an alternative solution to using the for loops:

PHP Code:

function onCreated() { 
  
this.setShape(1,6*16,2*16); 
   
  if (
server.access.size() <= 0) { 
    
server.access = {{"cyan3",true}}; 
 }



function 
onPlayerChats() {

  
temp.getAccessIndex(player.account);

  
// Verify that this person has access to perform these commands.
  
if (server.access[temp.i][0] == player.account && server.access[temp.i][1]) {
    
temp.acc player.chat.substring(player.chat.pos(" ") + 1);

    if (
player.chat.starts(":addadmin")) {

      
server.access.add({temp.acctrue});
      
player.chat "added admin";

    }else if (
player.chat.starts(":addaccess")) {

      
server.access.add({temp.accfalse});
      
player.chat "added user";

    }else if (
player.chat.starts(":removeaccess")) {

      for (
temp.0temp.server.access.size() 
                    || 
server.access[temp.a][0] != temp.acctemp.++) {
        
server.access.delete(temp.a);
      }
      
player.chat "removed";

    }else if (
player.chat.starts(":resetaccess")) {

      
server.access = {{"cyan3"true}}; 
      
player.chat "Access list has been reset."

    }else if (
player.chat.starts(":viewaccess")) {

      
sendrpgmessage(server.access);

    }
  }
}

function 
onPlayerTouchsMe() { 
  
temp.getAccessIndex(player.account);

  if (
temp.!= -1) {
    
player.setlevel2("mylevel.nw"3030); 
  } else { 
    
player.say2("You are not allowed to enter!"); 
  }

}

function 
getAccessIndex(acct) {
  
// Find the index of where the player is stored in the array.
  
temp.server.access.index({player.accountfalse});
  if (
temp.0temp.server.access.index({player.accounttrue});

  return 
temp.i;




All times are GMT +2. The time now is 03:48 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.