LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 510 users online 225725 members 1168 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
the mixed tape
Interests: This mix could burn a hole in anyon...
Mood: Euphoric
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
4 online / 39 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Need simple help with Perl Programming
Replies: 2Last Post July 14 5:36am by libertine
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( Briley 07 )


Guru

Patron
Reply
Since I am a bit of a noob, and don't have time to learn perl right now, I need some help. I have a hunting game on IRC, so when someone types "!hunt" the bot queries them and they catch a random weight and animal.

For example:

In public:


<EgoFreaky[RnR]> !hunt

In a query:


Bilzey You hide in the middle of a field and wait for something to wander by...
Bilzey .
Bilzey ..
Bilzey ...
Bilzey You think you hear something and fire wildly in that direction!
Bilzey Congratulations, EgoFreaky[RnR]! You just bagged yourself a 900kg hunter!

It then posts thge results back in the public chan where EgoFreaky originally used the hunt command.  

Although lately, someone has been abusing the script, they have been logging on as two nicknames, and using a script they wrote, they can lag up the bot for 40+ hours using one !hunt command, since the nicks repeat it after eachother.

What I want, is to be able to block certain nicknames from using the script. Below is the script, could you please let me know what to write and where to write it. Many thanks. :D

Code:
#!/usr/bin/perl
#
# Flashy's bloodsports. http://digdilem.org/ - "Because thems trouts ain't gonna catch themselves!"
# (Credit to the original Eggdrop TCL script by Nerfbendr)
#
# Adds silly !hunt, !fish and !trophy public triggers
# Also !newmonth will clean out the trophy cupboard. (Only if you do it, or the nick in $owner_nick)
#
# Optional Configuration (Will work fine without changing these, but you can if you like)
my $owner_nick='Flash_'; # Your nick - you can only reset the scores remotely if you use this nick.  
my $scale = 'kg'; # Say here whether you want to measure weights in lb or kg.
my $catch_percent=90; # How often you catch or shoot something.
my $trophy_cabinet = Xchat::get_info( 'xchatdir' ) . "\\trophies.txt"; # File to keep the trophies in.
# End user configuration
use strict;
Xchat::register( "Flashy's Huntin' 'n Fishin'", 'v.004', "Hunting", "" );
Xchat::hook_print('Channel Message', "hunting");
Xchat::hook_print('Your Message', "hunting");
Xchat::hook_print('Private Message', "hunting");
Xchat::hook_print('Private Message to Dialog', "hunting");
my $bigfish=0,my $fishman='Nobody',my $bighunt=0,my $huntman='Nobody';  
my $fishtype='Trout',my $fishplace='Pool';
my $hunttype='bear', my $huntplace='Bushes';  
my $last_hunter;
my $last_fisher;

my @hunts = ( [Random hunting stuff goes here]
my @fish = ( [Random fishing stuff here]
my @huntplaces = ("Random hunting places here]
my @fishplaces = ("Random fishing places here");  

Xchat::print("Path=($trophy_cabinet");

if (open (DH,"<$trophy_cabinet")) {  
($bigfish,$fishman,$fishtype,$fishplace) = split(/\|/,<DH>);
chomp($fishplace);
($bighunt,$huntman,$hunttype,$huntplace) = split(/\|/,<DH>);
close (DH);  
Xchat::print("Peered in the trophy cabinet: ($bigfish$scale $fishtype by $fishman) ($bighunt$scale $hunttype by $huntman)");  
} else {  
Xchat::print("\002Woo, looks like we've not gone hunting before. Let's make a trophy cabinet...");
save_trophy();
}

Xchat::print("\002Loaded Flash's Huntin' 'n Fishin'\002 (!hunt, !fish !trophy - Current records are $bigfish$scale and $bighunt$scale)");  

sub hunting {
my @pubwords = split(/ /,$_[0][1]);
my $hunter = Xchat::strip_code($_[0][0]);  
my $channel = Xchat::get_info('channel');  
if (lc($pubwords[0]) eq '!hunt') {
if ($hunter eq $last_hunter) {  
Xchat::command("say Stop hogging all the best pitches $hunter, let someone else try first!");  
return Xchat::EAT_NONE;
} else {
$last_hunter = $hunter;  
}
my $huntplace = @huntplaces[rand(scalar @huntplaces)];
my $hunt = @hunts[rand(scalar @hunts)];
my $weight = 1+int(rand($bighunt+10));  
Xchat::command("msg $hunter You hide $huntplace and wait for something to wander by...");
Xchat::command("msg $hunter .");
Xchat::command("msg $hunter ..");
Xchat::command("msg $hunter ...");
Xchat::command("msg $hunter You think you hear something and fire wildly in that direction!");
if (rand(100)<$catch_percent) {  
Xchat::command("msg $hunter Congratulations, $hunter! You just bagged yourself a $weight$scale $hunt!");  
Xchat::command("msg $channel $hunter just bagged a $weight$scale $hunt.");  
if ($weight > $bighunt) {
Xchat::command("msg $hunter Wow!!! That's a new record! Way to go, $hunter! Type !trophy to see it!");  
Xchat::command("msg $channel Wow! That breaks the old record of a $bighunt$scale $hunttype! $hunter is amazing!");  
$bighunt=$weight;  
$huntman=$hunter;
$hunttype=$hunt;
save_trophy();  
}
} else {
Xchat::command("msg $hunter Rats...you missed it, $hunter! Better luck next time!");  
Xchat::command("msg $channel $hunter is useless, they missed by a mile!");
}
}
if (lc($pubwords[0]) eq '!fish') {  
$fishplace = @fishplaces[rand(scalar @fishplaces)];  
my $fishy = @fish[rand(scalar @fish)];
my $weight = 1+int(rand($bigfish+10));
if ($hunter eq $last_fisher) {  
Xchat::command("say Stop hogging all the best pitches $hunter, let someone else try first!");  
return Xchat::EAT_NONE;
} else {
$last_fisher = $hunter;  
}
Xchat::command("msg $hunter You cast your line into a $fishplace and wait for a bite...");
Xchat::command("msg $hunter .");
Xchat::command("msg $hunter ..");  
Xchat::command("msg $hunter ...");  
Xchat::command("msg $hunter You feel a tug on your line and reel it in...");
if (rand(100)<$catch_percent) {  
Xchat::command("msg $hunter Congratulations, $hunter! You just caught yourself a $weight$scale $fishy!");  
Xchat::command("msg $channel $hunter just caught a $weight$scale $fishy");
if ($weight > $bigfish) {  
Xchat::command("msg $hunter Wow!!! That's a new record! Way to go, $hunter! Type !trophy to see it!");
Xchat::command("msg $channel Brilliant! That breaks the old record of a $bigfish$scale $fishtype! $hunter is the world's best!");  
$fishman=$hunter;  
$bigfish=$weight;
$fishtype=$fishy;  
save_trophy();  
}
} else {
Xchat::command("msg $hunter Rats...it got away, $hunter! Better luck next time!");  
Xchat::command("msg $channel $hunter is useless, they failed to catch anything!");
}
}
if (lc($pubwords[0]) eq '!trophy') {
Xchat::command("say $fishman holds the fishing record when they caught a $bigfish$scale $fishtype");  
Xchat::command("say $huntman holds the hunting record when they bagged a $bighunt$scale $hunttype");
}

if (lc($pubwords[0]) eq '!newmonth') {
my $curnick = Xchat::get_info('nick');  
if ((lc($hunter) eq lc($owner_nick)) or ($hunter eq Xchat::get_info('nick'))) {
$bigfish=0; $fishman='Nobody'; $fishtype='Tiddler'; $fishplace='Toilet';  
$bighunt=0; $huntman='Nobody'; $hunttype='Haggis'; $huntplace='Bush';
save_trophy();  
Xchat::command("say It's a new month, all existing huntin' 'n fishin' records are reset!");
} else { Xchat::command("say Who are you, $hunter to tell me to change the month?"); }
}  
}

sub save_trophy {  
open (DH, ">$trophy_cabinet") or die("Bah! Can't open the trophy cabinet to push this 'ere trophy in!");  
print (DH "$bigfish|$fishman|$fishtype|$fishplace\n");
print (DH "$bighunt|$huntman|$hunttype|$huntplace");
close (DH);
}

Post edited at 5:08 am on July 14, 2009 by Briley 07

-------
♥ Love you Jadeeyy Babeeyy forever ♥
Juspam!
Final Fantasy Fans Group!


5:06 am on July 14, 2009 | Joined: Feb. 2007 | Days Active: 627
Join to learn more about Briley 07 England, United Kingdom | Straight Male | Posts: 11,612 | Points: 23,308
LiveWire Humor
Zack Attack

Dairy Product Addict
Reply
O.o nice avatar.

-------
Every rose has its thorn.

5:08 am on July 14, 2009 | Joined: June 2009 | Days Active: 35
Join to learn more about Zack Attack Texas, United States | Bisexual Male | Posts: 1,073 | Points: 1,501
libertine


Omnipotent One

Patron
Reply
I think at the beginning of the hunting subroutine (where it says sub hunting) is where you need to put it.
after the line where the variable $hunter is defined (my $hunter = Xchat::strip_code($_[0][0]);), you'll probably want something along the lines of

Code:
if ($hunter eq "nickname1" || $hunter eq "nickname2")
{
 Xchat::command("say you're not allowed here, spammer!");
}
else
{
 (rest of subroutine)
}

Post edited at 5:37 am on July 14, 2009 by libertine

-------
Incidentally this signature is available in the foyer.


5:36 am on July 14, 2009 | Joined: May 2006 | Days Active: 937
Join to learn more about libertine England, United Kingdom | Straight Male | Posts: 11,084 | Points: 18,725
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic