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.guildaccess) this.guildaccess = "Staff";
// Assign door image
this.image = "door.png";
// Give door shape (prevents transparent image cheat)
this.setshape(1, 32, 32);
}
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", 30, 30};
}
}
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", 30, 30
};
// Inherit Guild Lock class
this.join("lock_guild");
}