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 05-06-2007, 11:26 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
Text Parser

Someone needed this, so I made it.

This reads text, and uses a "Smart Parser" to go through it and change variables to the value. To signal a variable, put @VARNAME@ in the code. GS1 will not work, and things such as servername will also not. I have tested this with clientr, client, player, server, and serverr. They all work. Here are the commands:

PHP Code:
parseFile"path/to/file.txt" );
The way I used this was in a server messageI used Parser.parseFile"data/servermessage.txt" ); This will return an array of the filesimply parsed.

parseTextstring/array )
You can give a string, or an array as a paramaterWill only parse the first param thoughso put things in an array if you want. If you give it an array, it will return an array. If you give it a stringit will return a string
Code for wNPC Parser:
PHP Code:
// Made by Chris Zakuto
function doInit()
{
  
// Must be a single character, sorry!
  
this.sepText "@"// The symbol that seperates variables from text.
}
function 
onCreated()
{
  
doInit();
}

public function 
parseFilefilepath )
{
  if ( 
temp.fileContents != NULL )
  {
    
temp.fileContents NULL;
  }
  
  if ( 
temp.!= NULL )
  {
    
temp.a.clear();
  }
  
temp.fileContents.loadLinesfilepath );
  
  for ( 
temp.ntemp.fileContents )
  {
    
temp.a.addtemp.);
  }
  
  
temp.fileText parseTexttemp.);
  
  return 
temp.fileText;
}
// "Smart Parser" returns the same type (array or string)
public function parseTexttext )
{
  if ( 
temp.returnText != NULL )
  {
    if ( 
temp.returnText.size() > )
    {
      
temp.returnText.clear();
    }
    
    
temp.returnText NULL;
  }
  if ( 
text.size() > )
  {
    for ( 
temp.atext )
    {
      
temp.returnText.addparseLinetemp.) );
    }
  }
  else
  {
    
temp.returnText parseLinetext );
  }
  
  return 
temp.returnText;
}

// Actually parse the text.
function parseLinerealText )
{
    if ( 
temp.chars != NULL )
  {
    
temp.chars.clear();
  }
  
  for ( 
temp.0temp.realText.length(); temp.++ )
  {
    
temp.chars.addrealText.substringtemp.i) );
  }
  
  if ( 
temp.isVar != false )
  {
    
temp.isVar false;
  }
  for ( 
temp.ntemp.chars )
  {
    if ( 
temp.isVar == false // Variable has not been detected.
    
{
      if ( 
temp.== this.sepText // Start of a variable.
      
{
        
temp.isVar true;
      }
      else
      {
        
temp.parsedText temp.parsedText temp.n;
      }
    }
    else
    {
      if ( 
temp.!= this.sepText )
      {
        
temp.varAdd temp.varAdd temp.n;
      }
      else
      {
        
temp.isVar false;
        
temp.finalVar makevartemp.varAdd );
        
temp.parsedText temp.parsedText temp.finalVar;
        
temp.varAdd "";
      }
    }
  }
  
  
// temp.parsedText is final output.
  
return temp.parsedText;

To use this, input text like this:
PHP Code:
Welcome to @serverr.servername@, @player.account@:@player.nickof @player.guild@! You currently have @clientr.moneymoney, and you have been online for @player.onlinetimeseconds! If we had a player.ip variableyours would be @player.ip@. 
Have fun, please leave comments.
__________________
Reply With Quote
  #2  
Old 05-07-2007, 12:19 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
I've always wondered what the hell parsing even is.
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #3  
Old 05-07-2007, 12:55 AM
Sum41Freeeeek Sum41Freeeeek is offline
Future Coder
Join Date: Feb 2004
Location: New York
Posts: 376
Sum41Freeeeek is on a distinguished road
Send a message via AIM to Sum41Freeeeek
this is pretty neat, good job
__________________
Frankie Cassini: ex-Era LAT
Quote:
Originally Posted by brakk View Post
omg just go to your room and draw a pony then

**** the chicken wings!
Reply With Quote
  #4  
Old 05-07-2007, 01:35 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
Quote:
Originally Posted by Sum41Freeeeek View Post
this is pretty neat, good job
ego ++; thanks.
__________________
Reply With Quote
  #5  
Old 05-07-2007, 02:35 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
An alternative is that you can use a substring to find the length of 'sepText' meaning that it can be more than one character, this is important because if there is are @'s in the file then they can easily be screwed up by this parser. I would make the 'sepText' something like '###obj.var###'
Reply With Quote
  #6  
Old 05-07-2007, 03: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
Quote:
Originally Posted by Rapidwolve View Post
An alternative is that you can use a substring to find the length of 'sepText' meaning that it can be more than one character, this is important because if there is are @'s in the file then they can easily be screwed up by this parser. I would make the 'sepText' something like '###obj.var###'
Well, you can always find something fancy. ` is hardly used, for example.

` (squiggly key)
__________________
Reply With Quote
  #7  
Old 05-07-2007, 03:09 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Or you can script it so its compatible with tags.
HTML Code:
<variable>player.nick</variable>
Reply With Quote
  #8  
Old 05-07-2007, 02:17 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
True, maybe I'll make an update for that.
__________________
Reply With Quote
  #9  
Old 05-07-2007, 03:04 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Wouldn't it be better to use format(); ?
Reply With Quote
  #10  
Old 05-07-2007, 08:39 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by Twinny View Post
Wouldn't it be better to use format(); ?
What does format() have to do with this? We're talking about concatination in text files.
Reply With Quote
  #11  
Old 05-07-2007, 08:57 PM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Hmm. It may be better to do something like:

PHP Code:
while (temp.something.pos("@") > 0)
{
  
// stuff here.

Either way, cool
__________________
- Zidane / Zidaya
Reply With Quote
  #12  
Old 05-07-2007, 08:59 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by Deadly_Killer View Post
Hmm. It may be better to do something like:

PHP Code:
while (temp.something.pos("@") > 0)
{
  
// stuff here.

Either way, cool
Didn't think of it like that thats a good idea. Could save alot of time too
Reply With Quote
  #13  
Old 05-08-2007, 01:26 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
Quote:
Originally Posted by Rapidwolve View Post
Didn't think of it like that thats a good idea. Could save alot of time too
I don't tend to trust while() in GS2. Never has worked right for me.
__________________
Reply With Quote
  #14  
Old 05-08-2007, 02:39 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by cbkbud View Post
I don't tend to trust while() in GS2. Never has worked right for me.
Most likely because you forgot to use the sleep function so you dont crash yourself. I've never liked using while() either
Reply With Quote
  #15  
Old 05-08-2007, 03:11 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
You guys must not realize that this:
for (i = 0; i < j; i++) {
func();
}
is simply:
i = 0;
while (i < j) {
func();
i++;
}

Also, checking every single letters seems to be A LOT of work. Much more effcient if you just found the first position of "@" and just moved like such. Hell, you could even tokenize("@") the whole thing and just do a for loop through the tokens (changing the mode of "variable" or "text" on every other token).
__________________
Do it with a DON!
Reply With Quote
  #16  
Old 05-08-2007, 04:20 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
PHP Code:
function onCreated()
{
  
temp.txt "Hello <variable>player.account</variable>. How are you doing on this fine day?";
  
  
this.parseText(temp.txt);
}

function 
parseText(buf)
{
  
temp.tok buf.tokenize(" ");
  
temp.hld temp.tok;
  
  for (
temp.0temp.temp.tok.size(); temp.I++)
  {
    
temp.var = temp.tok[temp.I];
    
    if (
temp.var.starts("<variable>"))
    {
      
temp.str temp.var.substring(10temp.var.pos("</variable>") - 10);
      
      
temp.hld[temp.I] = makevar(temp.str);
    }
  }
  
  for (
temp.var : temp.hldtemp.@= temp.var @ " ";
  
  return 
temp.r;

I made something real quick.
__________________
- Zidane / Zidaya
Reply With Quote
  #17  
Old 05-08-2007, 04:51 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
Quote:
Originally Posted by Deadly_Killer View Post
PHP Code:
function onCreated()
{
  
temp.txt "Hello <variable>player.account</variable>. How are you doing on this fine day?";
  
  
this.parseText(temp.txt);
}

function 
parseText(buf)
{
  
temp.tok buf.tokenize(" ");
  
temp.hld temp.tok;
  
  for (
temp.0temp.temp.tok.size(); temp.I++)
  {
    
temp.var = temp.tok[temp.I];
    
    if (
temp.var.starts("<variable>"))
    {
      
temp.str temp.var.substring(10temp.var.pos("</variable>") - 10);
      
      
temp.hld[temp.I] = makevar(temp.str);
    }
  }
  
  for (
temp.var : temp.hldtemp.@= temp.var @ " ";
  
  return 
temp.r;

I made something real quick.
eww makevar.
__________________
Reply With Quote
  #18  
Old 05-08-2007, 07:02 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Quote:
Originally Posted by cbkbud View Post
eww makevar.
A) makevar is good.
B) Please don't get me started... especially for someone who abuses his space bar badly.

Oh, and if you didn't know.. you used it in your OWN SCRIPT as well.
__________________
- Zidane / Zidaya
Reply With Quote
  #19  
Old 05-08-2007, 08:40 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Deadly_Killer View Post
Oh, and if you didn't know.. you used it in your OWN SCRIPT as well.
Classic example of being owned.
However, his script is a case where it is necessary.
__________________
Reply With Quote
  #20  
Old 05-08-2007, 01:12 PM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Quote:
Originally Posted by Inverness View Post
Classic example of being owned.
However, his script is a case where it is necessary.
I used makevar once, and the same way he used it.

And i always use makevar anyway, it is a lot better then lolz@(osldol @ "lolz");
__________________
- Zidane / Zidaya
Reply With Quote
  #21  
Old 05-08-2007, 01:49 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 Deadly_Killer View Post
A) makevar is good.
B) Please don't get me started... especially for someone who abuses his space bar badly.

Oh, and if you didn't know.. you used it in your OWN SCRIPT as well.
Please try not to be an ass when posting in my thread. If you don't want to help, by all means don't!

makevar() is untidy, it is much better in most cases to use var.( @ "lol" ); Skyld will probably be on to rave about that soon anyway.

Second, we have all already had a discussion about formatting of code. If you did not listen to any of it, that is not a problem of mine. I made a post, called Clean Coding: Common Sense which would explain to you exactly why I format the way I do. I did not rave about your code, because I realize that you have your own way of coding. Please do not try to tell me that the way I use spaces is wrong. There is nothing wrong with what I do. All it does is make it easier for me to read, and for the fellow scripters on servers I work on (any scripters I have worked with have all complimented on my formatting).

Please stay out of this thread if you do not wish to contribute something helpful.
__________________
Reply With Quote
  #22  
Old 05-08-2007, 02:45 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
Please try not to be an ass when posting in my thread. If you don't want to help, by all means don't!

makevar() is untidy, it is much better in most cases to use var.( @ "lol" ); Skyld will probably be on to rave about that soon anyway.

Second, we have all already had a discussion about formatting of code. If you did not listen to any of it, that is not a problem of mine. I made a post, called Clean Coding: Common Sense which would explain to you exactly why I format the way I do. I did not rave about your code, because I realize that you have your own way of coding. Please do not try to tell me that the way I use spaces is wrong. There is nothing wrong with what I do. All it does is make it easier for me to read, and for the fellow scripters on servers I work on (any scripters I have worked with have all complimented on my formatting).

Please stay out of this thread if you do not wish to contribute something helpful.
Explain how makevar() is untidy..
It's way easier to locate makevars then a bunch of () and @ etc..

I don't see why you think makevar() is untidy...

Btw;

use of obj.positions() would be more effective then obj.pos() if you ask me..
__________________
Reply With Quote
  #23  
Old 05-08-2007, 11:06 PM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Quote:
Originally Posted by cbkbud View Post
Please try not to be an ass when posting in my thread. If you don't want to help, by all means don't!

makevar() is untidy, it is much better in most cases to use var.( @ "lol" ); Skyld will probably be on to rave about that soon anyway.

Second, we have all already had a discussion about formatting of code. If you did not listen to any of it, that is not a problem of mine. I made a post, called Clean Coding: Common Sense which would explain to you exactly why I format the way I do. I did not rave about your code, because I realize that you have your own way of coding. Please do not try to tell me that the way I use spaces is wrong. There is nothing wrong with what I do. All it does is make it easier for me to read, and for the fellow scripters on servers I work on (any scripters I have worked with have all complimented on my formatting).

Please stay out of this thread if you do not wish to contribute something helpful.
Why do you try to provoke a fight? You even called something ugly that you used in your OWN script.

They can compliment it because they lack being able to script, any scripter will tell you that your script is a mess. Besides, please stop being jealous that I created a 20-30 line script to do what your 150-200 line script does and faster.

Refer to below about makevar:

Quote:
Originally Posted by Chompy View Post
Explain how makevar() is untidy..
It's way easier to locate makevars then a bunch of () and @ etc..

I don't see why you think makevar() is untidy...
__________________
- Zidane / Zidaya
Reply With Quote
  #24  
Old 05-08-2007, 11:57 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 Deadly_Killer View Post
Why do you try to provoke a fight? You even called something ugly that you used in your OWN script.

They can compliment it because they lack being able to script, any scripter will tell you that your script is a mess. Besides, please stop being jealous that I created a 20-30 line script to do what your 150-200 line script does and faster.

Refer to below about makevar:
Please refrain from posting in my threads if this is how you are going to act.
__________________
Reply With Quote
  #25  
Old 05-09-2007, 03:07 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Quote:
Originally Posted by cbkbud View Post
Please refrain from posting in my threads if this is how you are going to act.
Do you not understand that I was only contributing when you attempted to attack me?

You should most likely refrain yourself from posting -period- if this is how you are going to act.
__________________
- Zidane / Zidaya
Reply With Quote
  #26  
Old 05-09-2007, 03:09 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
I'd prefer using:
PHP Code:
this.(@ obj) = value
Rather then using:
PHP Code:
makevar("this." obj) = value
I just think its a matter of scripting preference.
Reply With Quote
  #27  
Old 05-09-2007, 03:14 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Quote:
Originally Posted by Rapidwolve View Post
I'd prefer using:
PHP Code:
this.(@ obj) = value
Rather then using:
PHP Code:
makevar("this." obj) = value
I just think its a matter of scripting preference.
This isn't about that at all. He attacked me for using makevar, and when I attacked him back he went all pissy on me... and all I did was try to contribute something that works pretty much the same way but uses tags.
__________________
- Zidane / Zidaya
Reply With Quote
  #28  
Old 05-09-2007, 03:50 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
Okay, let's just stop this fight. It obviously started with a misunderstanding on both sides, so let's just stop it now.
__________________
Reply With Quote
  #29  
Old 05-09-2007, 03:59 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Quote:
Originally Posted by cbkbud View Post
Okay, let's just stop this fight. It obviously started with a misunderstanding on both sides, so let's just stop it now.
Way to go .
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 09:38 PM.


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