Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Custom

Quests::Custom Custom Quests here

Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2015, 12:26 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default Perltidy - Automatic Script Formatting for Perl

For anyone that enjoys nicely formatted perl scripts, Perltidy is an extremely useful tool to automatically format perl scripts with extremely flexible settings. I have found that when I open a perl script to fix a bug or resolve a crash issue, I end up spending more time reformatting the script to my own standards than I do actually resolving the issue I opened the script for in the first place. This is particularly bad on really large scripts that are poorly formatted, such as really old script myself or others have written. It is much easier to read and understand a well formatted script than a poorly formatted one and is easier to see and resolve issues (especially with syntax). With Perltidy, I can eliminate the need to reformat Perl scripts manually, which saves me a ton of time. I figured I should share this with the community that aren't already aware of or using it.

You can get Perltidy here:
http://perltidy.sourceforge.net/

And here is the man page that explains all of the options in the current version of perltidy:
http://perltidy.sourceforge.net/perltidy.html

On linux, you can normally install perltidy using aptitude (apt-get install perltidy) or yum depending on which distribution you are on. Though, it may not be the most recent version of perltidy (as is the case for Debiant).

I haven't used Perltidy on Windows, but I am sure it is easy to get setup there as well.

The default formatting of perltidy does not meet my formatting preferences at all, so I spent several hours going through every single option available on the Perltidy man page and creating the .perltidyrc file below to format perl scripts as I prefer them to look. It is not 100% perfect as far as how I would manually format every single line, but it is probably 99% there. It is certainly good enough that I don't feel the need to change anything after I run Perltidy on a script.

On linux, you just create the .perltidyrc file and paste in the config in the code block below. Save the file in your home folder (such as /home/eqemu/.perltidyrc for example). A similar file can be setup for Windows as well.

.perltidyrc
Code:
# This is the .perltidyrc configuration file
# Created for Storm Haven by Trevius

# I/O control
#-o=filename    # --outfile=filename
#-npro  # --noprofile used to ignore this profile file
-b              # --backup-and-modify-in-place
-w              # --warning-output

# Basic Options
#-io    # --indent-only - Good option to use from command line if issues with the rest of these options
-i=1    # --indent-columns=n #Use n columns per indentation level (default n=4).
-l=500  # --maximum-line-length=80 default
#-vmll  # --variable-maximum-line-length - Not supported in the version on Debian?
-et=1   # --entab-leading-whitespace
-t              # --tabs
#-dt=4  # --default-tabsize=8 - Not supported in the version on Debian?
-syn    # --check-syntax - Probably good to leave as optional when ran

# Code Indentation Control
-ci=1   # --continuation-indentation=2
-sil=0  # --starting-indentation-level=n
-cti=0  # no extra indentation (default)
-noll   # --no-outdent-long-lines - same as -nolq and -nolc
-nola   # --no-outdent-labels
#-nolq  # --no-outdent-long-quotes

# Whitespace Control
-pt=2   # --paren-tightness=n
-sbt=2  # --square-bracket-tightness=n
-bt=2   # --brace-tightness=1
#-bbt=0 # --block-brace-tightness=n (default)
#-nsts  # --nospace-terminal-semicolon (default)
-nsfs   # --nospace-for-semicolon
-wls="= + - / *"        # --want-left-space=s  
-wrs="= + - / * ,"      # --want-right-space=s

# Comment Controls
#-nolc  # --outdent-long-comments
#-iscl  # --ignore-side-comment-lengths - Not supported in the version on Debian?


# Line Break Control
-bl             # --opening-brace-on-new-line
-nsbl   # --opening-sub-brace-on-new-line or maybe -sbl if it is just toggling -bl
#-nasbl # --opening-anonymous-sub-brace-on-new-line
#-otr   # --opening-token-right

# Vertical tightness
#-vt=0  # --vertical-tightness=n (default)
#-vtc=0 # --vertical-tightness-closing=n (default)
#-bbvt=0        # --block-brace-vertical-tightness=n (default)

# Blank Line Control
#-blbs=2        # --blank-lines-before-subs=n - Not supported in the version on Debian?
#-mbl=2 # --maximum-consecutive-blank-lines=1
-kbl=1  # --keep-old-blank-lines=1
-lbl=0  # --long-block-line-count=8
Perltidy does not change the functionality of Perl scripts, it only cleans up the formatting. It isn't going to fix badly written scripts, it will just make them look better and easier to read :P It can/will, however, check the Perl Syntax and generate a filename.pl.ERR error file if there are syntax issues with compiling of a script. The .ERR files note the syntax errors and make it easy to find an issue and resolve it. It is the same as running perl -c filename.pl on a perl script to check syntax.

You can run perltidy on a single file at a time, or even an entire folder at once if you wish. I would not suggest doing your entire quests folder all at once, but doing a single quests/zonename folder worth of scripts is fine.

Here is an example of what Perltidy with the above settings can do:


Original Perl Script (before Perltidy):
Code:
##6657 Net
##9221 fire
##7757 venom 

sub EVENT_COMBAT {

  if ($combat_state == 1) {
quest::emote("draws her deadly fangs");
quest::settimer("SpiderFire", 15);  
quest::settimer("SpiderNet", 35);  
quest::settimer("SpiderVenom", 10);  
quest::settimer("Add", 40);
quest::settimer("AEDebuff", 10);
}

if ($combat_state == 0) {
quest::emote("calms down");
quest::stoptimer("SpiderFire"); 
quest::stoptimer("SpiderNet");
quest::stoptimer("SpiderVenom");
quest::stoptimer("Add");
quest::stoptimer("AEDebuff");
}
}

sub EVENT_TIMER {

  if ($timer eq "SpiderFire") {
my $Charm = quest::ChooseRandom(20,25,30,35,40);
    quest::stoptimer("SpiderFire");
    quest::settimer("SpiderFire", $Charm);
#quest::emote("FIRE AE");
$npc->CastSpell(9221, $userid);
## Fire AE 1000
  }

  if ($timer eq "SpiderNet") {
my $Charm = quest::ChooseRandom(35,40,45,50,55);
    quest::stoptimer("SpiderNet");
    quest::settimer("SpiderNet", $Charm);
#quest::emote("SNARE AE");
$npc->CastSpell(1110, $userid);
## Snare
  }

  if ($timer eq "SpiderVenom") {
my $Charm = quest::ChooseRandom(80,90,100);
    quest::stoptimer("SpiderVenom");
    quest::settimer("SpiderVenom", $Charm);
quest::emote("sprays poision in every direction");
$npc->CastSpell(7757, $userid);
## venom dot
  }

  if ($timer eq "AEDebuff") {
   quest::stoptimer("AEDebuff");
quest::settimer("AEDebuff", 180); 
$npc->CastSpell(8822, $userid);
# -300 all resists
  }

if ($timer eq "Add") {
my $CharmB = quest::ChooseRandom(30,45,60,75);
    quest::stoptimer("Add");
    quest::settimer("Add", $CharmB);
quest::emote("screeches");
$entity_list->MessageClose($npc, 1, 200, 6, "Walls of the crypt begin to look alive");
my $a = quest::ChooseRandom(1,2,3);
if ($a == 1) {
quest::spawn2(899136,0,0, 529.64, -477,  36.82, $h);
quest::spawn2(899136,0,0, 604.80, -557.96,  36.82, $h);
quest::spawn2(899136,0,0, 579, -477, 36.82, $h);
}
elsif ($a == 2) {
quest::spawn2(899136,0,0, 579, -477, 36.82, $h);
quest::spawn2(899136,0,0, 559, -555, 36.31, $h);
quest::spawn2(899136,0,0, 604.80, -557.96,  36.82, $h);
}
elsif ($a == 3) {
quest::spawn2(899136,0,0, 617.60, -478.21,  36.31, $h);
quest::spawn2(899136,0,0, 513, -558,  36.31, $h);
quest::spawn2(899136,0,0, 529.64, -477,  36.82, $h);
}
}


}

  


sub EVENT_DEATH_COMPLETE {

$timestamp = localtime(time);

quest::write("text_files/dreadspire.txt","[$timestamp]:$mname was killed by $name the $class.");
quest::emote("legs go limp");


}

Updated File (after running Perltidy on it):
Code:
##6657 Net
##9221 fire
##7757 venom

sub EVENT_COMBAT {

	if ($combat_state == 1)
	{
		quest::emote("draws her deadly fangs");
		quest::settimer("SpiderFire",  15);
		quest::settimer("SpiderNet",   35);
		quest::settimer("SpiderVenom", 10);
		quest::settimer("Add",         40);
		quest::settimer("AEDebuff",    10);
	}

	if ($combat_state == 0)
	{
		quest::emote("calms down");
		quest::stoptimer("SpiderFire");
		quest::stoptimer("SpiderNet");
		quest::stoptimer("SpiderVenom");
		quest::stoptimer("Add");
		quest::stoptimer("AEDebuff");
	}
}

sub EVENT_TIMER {

	if ($timer eq "SpiderFire")
	{
		my $Charm = quest::ChooseRandom(20, 25, 30, 35, 40);
		quest::stoptimer("SpiderFire");
		quest::settimer("SpiderFire", $Charm);

		#quest::emote("FIRE AE");
		$npc->CastSpell(9221, $userid);
## Fire AE 1000
	}

	if ($timer eq "SpiderNet")
	{
		my $Charm = quest::ChooseRandom(35, 40, 45, 50, 55);
		quest::stoptimer("SpiderNet");
		quest::settimer("SpiderNet", $Charm);

		#quest::emote("SNARE AE");
		$npc->CastSpell(1110, $userid);
## Snare
	}

	if ($timer eq "SpiderVenom")
	{
		my $Charm = quest::ChooseRandom(80, 90, 100);
		quest::stoptimer("SpiderVenom");
		quest::settimer("SpiderVenom", $Charm);
		quest::emote("sprays poision in every direction");
		$npc->CastSpell(7757, $userid);
## venom dot
	}

	if ($timer eq "AEDebuff")
	{
		quest::stoptimer("AEDebuff");
		quest::settimer("AEDebuff", 180);
		$npc->CastSpell(8822, $userid);

		# -300 all resists
	}

	if ($timer eq "Add")
	{
		my $CharmB = quest::ChooseRandom(30, 45, 60, 75);
		quest::stoptimer("Add");
		quest::settimer("Add", $CharmB);
		quest::emote("screeches");
		$entity_list->MessageClose($npc, 1, 200, 6, "Walls of the crypt begin to look alive");
		my $a = quest::ChooseRandom(1, 2, 3);
		if ($a == 1)
		{
			quest::spawn2(899136, 0, 0, 529.64, -477,    36.82, $h);
			quest::spawn2(899136, 0, 0, 604.80, -557.96, 36.82, $h);
			quest::spawn2(899136, 0, 0, 579,    -477,    36.82, $h);
		}
		elsif ($a == 2)
		{
			quest::spawn2(899136, 0, 0, 579,    -477,    36.82, $h);
			quest::spawn2(899136, 0, 0, 559,    -555,    36.31, $h);
			quest::spawn2(899136, 0, 0, 604.80, -557.96, 36.82, $h);
		}
		elsif ($a == 3)
		{
			quest::spawn2(899136, 0, 0, 617.60, -478.21, 36.31, $h);
			quest::spawn2(899136, 0, 0, 513,    -558,    36.31, $h);
			quest::spawn2(899136, 0, 0, 529.64, -477,    36.82, $h);
		}
	}

}

sub EVENT_DEATH_COMPLETE {

	$timestamp = localtime(time);

	quest::write("text_files/dreadspire.txt", "[$timestamp]:$mname was killed by $name the $class.");
	quest::emote("legs go limp");

}
This example isn't too extreme, but I have seen some scripts that were almost impossible to read due to formatting inconsistencies. After running Perltidy on them, it is as if I manually went through and reformatted the entire thing manually myself.

Of course, the formatting settings above are not going to be perfect for everyone's standards. There are settings for nearly any formatting preference you may have, so you can go through the settings and tweak them as needed.

Hopefully this info is useful to some of you perl script people out there. I wish I had set this up for myself years ago!
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
Reply

Thread Tools
Display Modes

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 -4. The time now is 05:05 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3