Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 03-19-2010, 01:14 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
When you do comments, you typically comment them above or beside the line of code. Listing them at the bottom (now in a post) of the script is just a bad idea especially when you get into larger scripts, there's already enough jumping back and forth when you're tracing code there's no need to make it even more tedious.

Much like when Imperialistic first posted in the code gallery he made it specific to his cause (clientr.squadName + onActionGrab) as well depending on the context/situation of the script it should be reusable on other servers without much effort.

Here's what I would of considered a proper guild door.

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
// Check if guild access is defined, and default to Staff if not.
  
if (!this.guildaccessthis.guildaccess "Staff";
  
// Assign door image
  
this.image "door.png";
  
// Give door shape (prevents transparent image cheat)
  
this.setshape(13232);
}

function 
onPlayerTouchsMe() {
  
// Check if player's guild can use door
  
if (player.guild == this.guildaccess) {
    
// Player is allowed to enter
    
openDoor();
  } else {
    
// Player is denied access
    
accessDenied();
  }
}

function 
openDoor() {
  
// Hide Door
  
hide();
  
// Wait 3 seconds
  
waitfor(this"WaitEvent"3);
  
// Un-hide Door
  
show();
}

function 
accessDenied() {
  
// Display access denied error
  
player.chat "Access denied!";

That would then be placed in a class called door_guild or so, and be used in a level script like so:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
// Define guild who can access it
  
this.guildaccess "Guild Name";
  
// Inherit Guild Door Class
  
this.join("door_guild");

However that is rather insecure, but more aesthetically pleasing which should be your aim. I would place an NPC in the protected level to only let members of that guild. With code like this:

PHP Code:
/*
    Variables

    this.guildaccess - Guild that can remain in the level
    this.guildexit = {"level.nw", x, y} - Level to warp people who aren't in the guild access
*/
function onCreated() {
  
// Check if guild access is defined
  
if (!this.guildaccess) {
    
// Set guild access to Staff
    
this.guildaccess "Staff";
  }
  
// Check if guild exit is properly defined 
  
if (this.guildexit.size() != 3) {
    
this.guildexit = {"onlinestartlocal.nw"3030};
  }
}

function 
onPlayerEnters() {
  
// Check if player is in guild 
  
if (player.guild != this.guildaccess) {
    
// Warp player to exit if not
    
warpPlayer();
  }
}

function 
warpPlayer() {
  
// Warp player away to guild exit
  
player.setlevel2(this.guildexit[0], this.guildexit[1], this.guildexit[2]);

This would also be placed into a class npc like lock_guild and used like follows:

PHP Code:
function onCreated() {
  
// Define guild that can enter
  
this.guildaccess "Guild Name";
  
// Define exit level for denied players
  
this.guildexit = {
    
"guildfort_exit.nw"3030
  
};
  
// Inherit Guild Lock class
  
this.join("lock_guild");

__________________
Quote:

Last edited by fowlplay4; 03-19-2010 at 01:29 AM..
Reply With Quote
 


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 11:03 AM.


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