Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Monitoring levels (https://forums.graalonline.com/forums/showthread.php?t=134264575)

pig132 09-17-2011 06:34 AM

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.filename, 1);
    
    echo(
"Level checking: " @ player.account @ " was caught in " @ player.level.name @ " (saved to logs)");
  }
} 


cbk1994 09-17-2011 06:48 AM

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.

pig132 09-17-2011 06:54 AM

Quote:

Originally Posted by cbk1994 (Post 1668406)
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

cbk1994 09-17-2011 07:08 AM

Thanks for updating your post.

Quote:

Originally Posted by pig132 (Post 1668407)
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.

pig132 09-17-2011 07:53 AM

Ahh, I understand completely now about the accounts/community names.

Thank you again


All times are GMT +2. The time now is 12:42 PM.

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