Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Simple level restriction (https://forums.graalonline.com/forums/showthread.php?t=134262999)

Emera 04-27-2011 10:16 AM

Simple level restriction
 
Heya, i was wondering if you guys could help me with this. Im making a simple lvl restriction system, but i want it to be easily editable with account names that can access it. First i thought if i use a weapon as a keycard and if the player doesn't have the weapon, he/she will be warped elsewhere but its not efficient enough. Any ideas?:noob:

TSAdmin 04-27-2011 10:21 AM

Use a database NPC to store flags of rights within the level, including who can access it.

Soala 04-27-2011 10:25 AM

You could simply make a class holding the restriction and a list of accounts, and join it to the level.
EDIT: Or what TSA said

Emera 04-27-2011 04:28 PM

I am new to scripting and, i know what your saying, but i don;t know where to start doing that. I like the use of a database NPC to keep it simple but any advance on that?
Most appreciated.

Bell 04-27-2011 05:20 PM

I'm not positive this is what you're looking for but there is a tutorial in the wiki explaining how to make database NPC's.

http://wiki.graal.net/index.php/Crea..._Communication

cbk1994 04-27-2011 09:57 PM

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(levelNameaccount) {
  
this.access.(@ levelName).add(account);
  
this.save();
}

public function 
removeAccountFromLevel(levelNameaccount) {
  
this.access.(@ levelName).remove(account);
  
this.save();
}

public function 
accountHasAccess(levelNameaccount) {
  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.nameplayer.account)) {
    
player.chat "I'm not allowed here!";
    
player.setLevel2("osl.nw"3232);
  }



Bell 04-28-2011 12:32 AM

Quite alright Chris, I was attempting to guess what he was hunting for. I knew someone would correct me if I was wrong :D.

Emera 04-28-2011 11:26 AM

Thanks CBK. I know know that DPNCS can be used for much more than storing data. Thanks. Im not gonna copy and past the script but use it as a template for my own. That way i will learn more and be happier with the outcome, if any. Thanks guys.


All times are GMT +2. The time now is 06:58 AM.

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