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 03-19-2010, 12:51 AM
jkldogg jkldogg is offline
J.Rollin (killaz)
jkldogg's Avatar
Join Date: Feb 2010
Location: USA
Posts: 675
jkldogg can only hope to improve
Send a message via AIM to jkldogg Send a message via MSN to jkldogg
Red face Guild Locked Door

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:

Attached Thumbnails
Click image for larger version

Name:	script.PNG
Views:	1158
Size:	99.5 KB
ID:	50646  
__________________

PSN: jkldogg



The best post ever made on the graal forums.
After playing Graal Online for many years, JKL decides to make a forum account. Isn't life funny?

Last edited by jkldogg; 03-19-2010 at 12:52 AM.. Reason: Message width was insane.
Reply With Quote
  #2  
Old 03-19-2010, 12:57 AM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
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"
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #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
  #4  
Old 03-19-2010, 01:20 AM
jkldogg jkldogg is offline
J.Rollin (killaz)
jkldogg's Avatar
Join Date: Feb 2010
Location: USA
Posts: 675
jkldogg can only hope to improve
Send a message via AIM to jkldogg Send a message via MSN to jkldogg
Wink !

Quote:
Originally Posted by Imperialistic View Post
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 View Post
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!
__________________

PSN: jkldogg



The best post ever made on the graal forums.
After playing Graal Online for many years, JKL decides to make a forum account. Isn't life funny?
Reply With Quote
  #5  
Old 03-19-2010, 01:29 AM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
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);
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #6  
Old 03-19-2010, 01:35 AM
jkldogg jkldogg is offline
J.Rollin (killaz)
jkldogg's Avatar
Join Date: Feb 2010
Location: USA
Posts: 675
jkldogg can only hope to improve
Send a message via AIM to jkldogg Send a message via MSN to jkldogg
!

Quote:
Originally Posted by Imperialistic View Post
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); 
__________________

PSN: jkldogg



The best post ever made on the graal forums.
After playing Graal Online for many years, JKL decides to make a forum account. Isn't life funny?
Reply With Quote
  #7  
Old 03-19-2010, 01:57 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
Quote:
Originally Posted by jkldogg View Post
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.
__________________
Quote:
Reply With Quote
  #8  
Old 03-19-2010, 05:55 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by fowlplay4 View Post
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.
Reply With Quote
  #9  
Old 03-19-2010, 07:20 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
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?
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #10  
Old 03-19-2010, 07:35 PM
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
Personal preference I guess, also lets you wake up your scripts in future/more complex cases.
__________________
Quote:
Reply With Quote
  #11  
Old 03-19-2010, 08:44 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 DrakilorP2P View Post
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");

__________________
Reply With Quote
  #12  
Old 03-19-2010, 10:07 PM
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
Now there's a class-based guild door, as well as the warp. Thread accomplished.
__________________
Quote:
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 05:04 PM.


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