View Single Post
  #20  
Old 11-25-2003, 04:26 AM
Eglin
Hill Giant
 
Join Date: Nov 2003
Posts: 168
Default

Quote:
Originally Posted by Kroeg
On a few quest files, it left off the ';' before the '}' at the end of the line.. others added the ';' but didn't put a space between ';' and '}'.
Quote:
Originally Posted by mollymillions
it still wont handle more than one function per line though.
Attached is the perlscript that I've been using to convert scripts into perl. Even if you choose to continue using the native scripting engine, I think you may find this useful. It can be easily modified to suit your needs (if it doesn't already). If you don't already have Perl, I recommend getting the Activestate distribution. It is a small, free download.
Code:
#!/usr/bin/perl -w
#convert scripts from .qst to .pl
#usage: ./convert.pl [questdir]
use File::Find;
use strict;
sub convert
{
	my $infile = $_;
	(my $outfile = $infile)=~s/qst$/pl/;
	print "Converting file: $infile -> $outfile\n";
	if(!open IN, "$infile") {
		warn $!;
		return;
	}
	if(!open OUT, ">$outfile") {
		warn $!;
		return;
	}
	while(<IN>)
	{
		#remove stray backslashes
		s|\\|\?|;
		#change /yada yada yada/ comment lines to #yada yada
		s|^/(.*)/\s*$|#($1)|;
		#prefix each event block w/ "sub"
		s/^(EVENT_)/sub $1/;
		#change $1/$1- (etc) notation to instead match against $text
		s/\s*\$\d-?\s*=~\s*\"(.*?)\"/\$text=~\/$1\/i/;
		s/\$\d-?/\$text/;
		#change itemcount syntax
		s/if\(\$itemcount\(\"(\d+)\"\)\s*==/if\(\$itemcount\{$1\} && \$itemcount\{$1\} ==/;
		#change summonitem syntax to seperate args w/ commas
		s/summonitem\((.*?\")\s+(\".*?)\)/summonitem\($1, $2\)/;
		#change commands to have a quest:: prefix and be seperated by semi-colons (;)
		s/(say|emote|shout|spawn|echo|summonitem|castspell|depop|cumflag|flagnpc|flagclient|exp|level|safemove|rain|snow|givecash|pvp|doanim|addskill|me)(\(.*?\))/quest::$1$2;/g;
		print OUT $_;
	}
	close IN;
	close OUT;
}
@ARGV = qw(.) unless @ARGV;
find( sub {/^.*\.qst\z/s && convert("$_")}, @ARGV);
If you need to ensure that quests are using valid database references, you can use something like the following. I used ODBC here, but if you install the DBD::mysql module, you can go directly through mysql.
Code:
#! /usr/bin/perl -w
use strict;
use File::Find ();
use DBI;

my $dbh= DBI->connect("DBI:ODBC:yourdsnname","yourusername","yourpassword") or die "Got error $DBI::errstr when connecting to db\n";
#my $dbh= DBI->connect("DBI:mysql:yourdsnname","yourusername","yourpassword") or die "Got error $DBI::errstr when connecting to db\n";

# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, './quests');
exit;


sub wanted
{
    if(/^.*\.qst\z/s)
	{
		if(!open(SCRIPT, $_))
		{
			warn $!;
			return;
		}
		while(<SCRIPT>)
		{#summonitem("19629");
			if(/summonitem\(\"(\d+)\"\)/)
			{
				my $rv = $dbh->do("select * from items where id = $1");
				if(!$rv)
				{
					warn  "Can't execute query: $dbh->errstr $!";
					return;
				}
				if($rv == 0E0)
				{
					print "Error: summonning non-existant item (#$1) in $File::Find::name\n";
				}
			}
		}
		close SCRIPT;
	}
}
By using the techniques in these two scripts, you should be able to mold your quest scripts to whatever format you desire.
Reply With Quote