Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Guild Locked Door (https://forums.graalonline.com/forums/showthread.php?t=134258431)

jkldogg 03-19-2010 12:51 AM

Guild Locked Door
 
1 Attachment(s)
My First Post in the Code Gallery! ^^

Very Simple Guild door script. Just Place it in an NPC on the GraalEditor, save it and upload it to your server.
You must also use an image and upload that as well. You must have your own clientr.gangname

This script is very useful for like gang locked doors or staff locked doors.
So like you must be wearing the guild tag in order to enter the door, if you're not wearing the tag, you'll be warped to the else location.

Forum PM me any questions you may have.

Helpful Comments:
NPC Code:
line 2, you need your own script for a clientr.gangname or something.  
You can easily find a stafftag script in the code gallery and edit it.
It won't work without the clientr. part in the server options and weapon for the player.

line 2, you can also use a guild setter script. like :guild account "guild name", that will also work

line 3, the level to warp the player to when door is grabbed when wearing guild tag specified in line 2

line 5, the level to warp the player to if they aren't in that guild specified in line 2



Here's the full code:
PHP Code:

function onActionGrab() {
  if (
clientr.SquadName == "Guild Name") {
    
setlevel2("levelnamehere.nw"xy);
  } else {
    
setlevel2("levelnamehere.nw"xy);
  }


If you can't click the attachment, or just don't want to(^^), here's the example:

http://forums.graalonline.com/forums...1&d=1268952059

Imperialistic 03-19-2010 12:57 AM

You don't really have to set it in the players attributes if it's just the guild name, makes you go out of the way to set clientr.squadname.

You can just simplify it:

PHP Code:

if (player.guild == "GUILD_NAME"


fowlplay4 03-19-2010 01:14 AM

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");



jkldogg 03-19-2010 01:20 AM

!
 
Quote:

Originally Posted by Imperialistic (Post 1563451)
You don't really have to set it in the players attributes if it's just the guild name, makes you go out of the way to set clientr.squadname.

You can just simplify it:

PHP Code:

if (player.guild == "GUILD_NAME"


Okay, thanks.

Quote:

Originally Posted by fowlplay4 (Post 1563456)
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() {
  
// Define guild that can use door
  
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");




That looks Extremely complicated/boring to use. Mine is fun! You get warped somewhere else when it you're not in the guild.
+ mine is small, compact, and simple! :)

Imperialistic 03-19-2010 01:29 AM

You're not showing any willingness to learn, you should take seriously to what fowlplay4 is telling you, if you want to be warped just replace:

hide(); --> setlevel2("blah.nw", x , y);
and
player.chat = "Access Denied!"; --> setlevel2("blah2.nw", x, y);

jkldogg 03-19-2010 01:35 AM

!
 
Quote:

Originally Posted by Imperialistic (Post 1563459)
You're not showing any willingness to learn, you should take seriously to what fowlplay4 is telling you, if you want to be warped just replace:

hide(); --> setlevel2("blah.nw", x , y);
and
player.chat = "Access Denied!"; --> setlevel2("blah2.nw", x, y);

okay, fine i want to learn

I don't understand this part:

PHP Code:

// Define guild that can use door 
  
if (!this.guildaccessthis.guildaccess "Staff"
  
// Give door shape (prevents transparent image cheat) 
  
this.setshape(13232); 


fowlplay4 03-19-2010 01:57 AM

Quote:

Originally Posted by jkldogg (Post 1563462)
okay, fine i want to learn
I don't understand this part: code..

Those are fail-safes.

if (!this.guildaccess) - Checks if the this.guildaccess is not 0

this.guildaccess = "Guild Name" - Sets this.guildaccess to a default value if it's not defined or equals 0.

this.setshape(1, 32, 32); - My example sets the size of the npc to a blocking type (1), and to block 32 by 32 pixels (or 2 by 2 tiles since tiles are 16 pixels in width and height).

Also, yes your script is relatively small, simple, quick but lacks reuse-ability and will be a pain to have to go and replace it everywhere it's used if you want to change it's behavior.

P.S. Don't leave the code in PHP tags in your quotes, just makes it easier on people tbh.

DrakilorP2P 03-19-2010 05:55 PM

Quote:

Originally Posted by fowlplay4 (Post 1563456)
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.


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


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:


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

That's so complicated. The original is much easier to use and roughly equivalent in security.

Deas_Voice 03-19-2010 07:20 PM

hey jerret, what's wrong with sleep()?
you're all waitfor()'ish..

sure, i heard that sleep() break's loops, but for events?
or is this just a personal preference?

fowlplay4 03-19-2010 07:35 PM

Personal preference I guess, also lets you wake up your scripts in future/more complex cases.

cbk1994 03-19-2010 08:44 PM

Quote:

Originally Posted by DrakilorP2P (Post 1563560)
That's so complicated. The original is much easier to use and roughly equivalent in security.

All it really needed was

PHP Code:

// class 'door'
function onPlayerTouchsMe() {
  if (
player.guild == this.guild || this.guild == null) {
    
player.setLevel2(this.newLevelthis.newXthis.newY);
  }


PHP Code:

// level script
function onCreated() {
  
this.guild "My Guild";
  
  
this.newLevel "level.nw";
  
this.newX 32;
  
this.newY 32;
  
  
this.join("door");



fowlplay4 03-19-2010 10:07 PM

Now there's a class-based guild door, as well as the warp. Thread accomplished.


All times are GMT +2. The time now is 10:35 AM.

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