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 09-17-2011, 06:34 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Monitoring levels

Just read a few guides on file input/output and came up with this that I thought is pretty cool. Basically you put this in a class and if a player enters that level that isn't allowed, it will send an rc chat alert and also save to logs. (players account, in which level, and at what time)

Comments and criticism welcomed.

PHP Code:
function onCreated()
{
  
this.access = {"pig132"};
}
function 
onPlayerEnters()
{
  if (! (
player.account in this.access))
  {
    
temp.filename "levels/users/pig132/other/levels.txt";
    
    
temp.time convertTimeToString(timevar2);
    
    
temp.lines = {player.account " has illegally entered " player.level.name " on " temp.time};
    
temp.lines.savelines(temp.filename1);
    
    echo(
"Level checking: " player.account " was caught in " player.level.name " (saved to logs)");
  }


Last edited by pig132; 09-17-2011 at 06:56 AM..
Reply With Quote
  #2  
Old 09-17-2011, 06:48 AM
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
Your styling is inconsistent (use of braces on own lines and indentation of braces). You should use account names internally, not community names. Logs should also contain account names (community names are fine in addition). Keep in mind that community names can change and some players have no community name set.

Instead of using a blank if-statement, just do

PHP Code:
if (! (player.account in this.access)) { 
The formatTimeString line doesn't seem to be doing anything.

You should either use SPC or @ with a spaces inside the concatenated strings. Consistency is key.

It looks like it will work, though. Thanks for submitting to the Code Gallery, we need more scripters interested in helping the community. In the future, it would probably be best if you post a thread outside of the Code Gallery first so that you can get feedback. The idea is for this forum to be a repository of high-quality scripts that can either be used or learned from. If you make a thread in the main NPC Scripting forum, there are plenty of scripters who will be happy to give you advice to help you polish it before posting it in the Code Gallery.
__________________
Reply With Quote
  #3  
Old 09-17-2011, 06:54 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
Your styling is inconsistent (use of braces on own lines and indentation of braces). You should use account names internally, not community names. Logs should also contain account names (community names are fine in addition). Keep in mind that community names can change and some players have no community name set.

Instead of using a blank if-statement, just do

PHP Code:
if (! (player.account in this.access)) { 
The formatTimeString line doesn't seem to be doing anything.

You should either use SPC or @ with a spaces inside the concatenated strings. Consistency is key.

It looks like it will work, though. Thanks for submitting to the Code Gallery, we need more scripters interested in helping the community. In the future, it would probably be best if you post a thread outside of the Code Gallery first so that you can get feedback. The idea is for this forum to be a repository of high-quality scripts that can either be used or learned from. If you make a thread in the main NPC Scripting forum, there are plenty of scripters who will be happy to give you advice to help you polish it before posting it in the Code Gallery.
Thank you for the input. I've updated the post with your advice.

As to the community name / account thing, I thought using player.account was inefficient when the community name stuff came out? I could be wrong though, just something I read a while ago.

And on the styling, for me its really just preference, its really easy for me to read/edit this way
Reply With Quote
  #4  
Old 09-17-2011, 07:08 AM
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
Thanks for updating your post.

Quote:
Originally Posted by pig132 View Post
As to the community name / account thing, I thought using player.account was inefficient when the community name stuff came out? I could be wrong though, just something I read a while ago.
The idea is that the account is an internal identifier used only by scripts (and developers/staff). Players should never see another player's account, only their community name and nick name.

The problem is that community names can change, so you shouldn't rely on them. For example, if you have a bank system which uses a database NPC or SQL to store the player's balance based on their community name, that player will lose all their money if they get a new community name.

Similarly, if you assign privileges based on community name, another player could take the previously used community name of the trusted player (which is no longer in use) and gain unauthorized access.

Almost every user management structure in existence uses IDs (accounts) instead of display names for identification. These forums do as well; if you look at my profile, you'll see the URL ends in "?u=2568", which is my user ID. If Darlene were to rename my forum display name (cbk1994), I would keep the same ID. If it was based off of forum display name instead of ID, every instance of cbk1994 would have to be changed to the new value, and old links to my profile (?u=cbk1994) would stop working. It's the same general concept.

Quote:
And on the styling, for me its really just preference, its really easy for me to read/edit this way
The problem isn't your position on the curly brace war but rather the inconsistency (you've fixed it now). It's always good to pick one style and keep it throughout a script.
__________________
Reply With Quote
  #5  
Old 09-17-2011, 07:53 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Ahh, I understand completely now about the accounts/community names.

Thank you again
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 06:57 PM.


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