Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-11-2010, 05:54 PM
cyan3 cyan3 is offline
Registered User
cyan3's Avatar
Join Date: Nov 2005
Location: England
Posts: 2,919
cyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant future
Level Restriction Script

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!");
   }
  }
 } 
Attached Files
File Type: txt levelrestrictionscript.txt (1.7 KB, 264 views)
Reply With Quote
  #2  
Old 06-11-2010, 06:05 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #3  
Old 06-11-2010, 06:07 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
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}};"
__________________
Reply With Quote
  #4  
Old 06-11-2010, 06:09 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xAndrewx View Post
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.
__________________
Reply With Quote
  #5  
Old 06-11-2010, 06:11 PM
cyan3 cyan3 is offline
Registered User
cyan3's Avatar
Join Date: Nov 2005
Location: England
Posts: 2,919
cyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #6  
Old 06-11-2010, 06:17 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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;

__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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