Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Perlscript ➜ Need some help!

Need some help!

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by KorvinKray   (3 posts)  Bio
Date Wed 16 Dec 2009 11:14 AM (UTC)

Amended on Wed 16 Dec 2009 11:15 AM (UTC) by KorvinKray

Message
I have been trying to figure out how to get the working, if possible, in MUSHclient. It works fine in a couple other clients but cannot figure it out here. I keep getting this:

Error number: -2147467259
Event: Execution of line 1 column 0
Description: (in cleanup) Undefined subroutine &main::delAlias called




Called by: Immediate execution



use strict;
use warnings;
no warnings 'redefine';

my %inflictedDamage;
my %takenDamage;
my $lastWeapon="unknown";
my %inflictedWeapons;

sub damageText {
	my $txt='Damage Log:%r%cb%cuDamage inflicted:%cn%r%r';
	my $shots=0;
	my $damage=0;
	foreach my $loc (keys %inflictedDamage) {
		$txt .= sprintf('%20s: %4d damage in %4d shots.%%r',
				$loc,
				$inflictedDamage{$loc}->[1],
				$inflictedDamage{$loc}->[0]);
		$shots+=$inflictedDamage{$loc}->[0];
		$damage+=$inflictedDamage{$loc}->[1];
	}
 	$txt.=sprintf('%%ch%20s: %4d damage in %4d shots.%%cn%%r',
		"Total",$damage,$shots);
		
 	$txt.='%r%cb%cuWeapons hit:%cn%r%r';
	foreach my $loc (keys %inflictedWeapons) {
		$txt .= sprintf('%20s: %4d damage in %4d shots.%%r',
				$loc,
				$inflictedWeapons{$loc}->[1],
				$inflictedWeapons{$loc}->[0]);
	}
	
	$shots=0;
	$damage=0;	
	$txt.='%r%cb%cuDamage taken:%cn%r%r';
	foreach my $loc (keys %takenDamage) {
		$txt .= sprintf('%20s: %4d damage in %4d shots.%%r',
				$loc,
				$takenDamage{$loc}->[1],
				$takenDamage{$loc}->[0]);
		$shots+=$takenDamage{$loc}->[0];
		$damage+=$takenDamage{$loc}->[1];
	
	}
 	$txt.=sprintf('%%ch%20s: %4d damage in %4d shots.%%r%%cn',
		"Total",$damage,$shots);

	$txt=~s/ (?= )/ \%/g;
	return $txt;
}

delAlias(qr/^DAMAGE_/);
addAlias("DAMAGE_RESET",qr/^damagereset\s*$/,sub {
	%inflictedDamage=();
	%inflictedWeapons=();
	%takenDamage=();
	statusWindow->print(ansi('%cbDamage log reset%cn%r'));
	return undef;
	},1);
	
addAlias("DAMAGE_PRINT",qr/^dpr\s*$/,sub {
	statusWindow->print(ansi(damageText));
	return undef;
	},1);

delTrigger(qr/^DAMAGE_/);
addTrigger("DAMAGE_DEAL",qr/You hit for (\d+) points of damage in the ([\w (]+[\w)])/, sub { 
        my $w=$2;
        chomp $w;
	$inflictedDamage{$w}->[0]++;
	$inflictedDamage{$w}->[1]+=$1;
	$inflictedWeapons{$lastWeapon}->[0]++;
	$inflictedWeapons{$lastWeapon}->[1]+=$1;
	return shift;
	});

addTrigger("DAMAGE_TAKE",qr/You have been hit for (\d+) points of damage in the ([\w (]+[\w)])/, sub {
	my $p=$1;
	my $w=$2;
        chomp $w;
	unless ($w=~/transfer/) {
		$takenDamage{$w}->[0]++;
		$takenDamage{$w}->[1]+=$p;
	}
	return shift;
	});

addTrigger("DAMAGE_WEAPON",qr/You fire ([\w\-\/]+) at/, sub {
	$lastWeapon=$1;
	delDelayed(qr/^DAMAGE_WEAPON_RESET$/);
	addDelayed("DAMAGE_WEAPON_RESET",3,sub { $lastWeapon="unknown"; });
	return shift;
});

addTrigger("DAMAGE_WEAPON_KICK",qr/You try to kick/, sub {
	$lastWeapon="Kick";	
	delDelayed(qr/^DAMAGE_WEAPON_RESET$/);
	addDelayed("DAMAGE_WEAPON_RESET",3,sub { $lastWeapon="unknown"; });
	return shift;
});

addTrigger("DAMAGE_WEAPON_PUNCH",qr/You try to punch/, sub {
	$lastWeapon="Punch";	
	delDelayed(qr/^DAMAGE_WEAPON_RESET$/);
	addDelayed("DAMAGE_WEAPON_RESET",3,sub { $lastWeapon="unknown"; });
	return shift;
});

addTrigger("DAMAGE_WEAPON_CLUB",qr/You try to club/, sub {
	$lastWeapon="Club";	
	delDelayed(qr/^DAMAGE_WEAPON_RESET$/);
	addDelayed("DAMAGE_WEAPON_RESET",3,sub { $lastWeapon="unknown"; });
	return shift;
});


addTrigger("DAMAGE_WEAPON_AXE",qr/You try to axe/, sub {
	$lastWeapon="Axe";	
	delDelayed(qr/^DAMAGE_WEAPON_RESET$/);
	addDelayed("DAMAGE_WEAPON_RESET",3,sub { $lastWeapon="unknown"; });
	return shift;
});


addTrigger("DAMAGE_WEAPON_DFA",qr/You land on your target/, sub {
	$lastWeapon="Death From Above";	
	delDelayed(qr/^DAMAGE_WEAPON_RESET$/);
	addDelayed("DAMAGE_WEAPON_RESET",3,sub { $lastWeapon="unknown"; });
	return shift;
});


addAlias("DAMAGE_INSERT",qr/\@DAMAGE\@/,sub {
	my $t=damageText;
	my $l=shift;
	$l=~ s/\@DAMAGE\@/$t/;
	return $l;
});


As I said, this works in a couple other clients, here is the link to a screenshot I took of what it is supposed to look like.

http://i221.photobucket.com/albums/dd134/mark_perryman/BTMux%20Stuff/test.jpg

Thank you, any help is greatly appreciated.
Top

Posted by Ron   China  (15 posts)  Bio
Date Reply #1 on Wed 16 Dec 2009 11:50 AM (UTC)
Message
The problem is Mush didn't have this function "delAlias".

Is that yourself defined function?

If so . please "require" the file that include sub delAlias first.

Ron
Top

Posted by KorvinKray   (3 posts)  Bio
Date Reply #2 on Thu 17 Dec 2009 05:30 PM (UTC)
Message
I guess what I am looking for is how do I create and delete aliases from within a script?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 17 Dec 2009 07:17 PM (UTC)

Amended on Thu 17 Dec 2009 07:25 PM (UTC) by Nick Gammon

Message
Template:function=AddAlias AddAlias

The documentation for the AddAlias script function is available online. It is also in the MUSHclient help file.


Template:function=DeleteAlias DeleteAlias

The documentation for the DeleteAlias script function is available online. It is also in the MUSHclient help file.



KorvinKray said:


addTrigger("DAMAGE_WEAPON_AXE",qr/You try to axe/, sub {
	$lastWeapon="Axe";	
	delDelayed(qr/^DAMAGE_WEAPON_RESET$/);
	addDelayed("DAMAGE_WEAPON_RESET",3,sub { $lastWeapon="unknown"; });
	return shift;
});



This isn't exactly how MUSHclient handles scripts. You can't put a Perl script in as the argument to AddTrigger. You have two options - put in the name of a script in your script file (the function name) or you use "send to script" and put the commands to be done (outside a function) in the "send" field.

See http://www.mushclient.com/scripting for a lengthy discussion about this.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by KorvinKray   (3 posts)  Bio
Date Reply #4 on Fri 18 Dec 2009 10:12 PM (UTC)

Amended on Fri 18 Dec 2009 10:14 PM (UTC) by KorvinKray

Message
Oh well, seems more complicated than I thought, I will just have to forget about it for now and keep using XpertMud till I can figure it out.

Thanks for the replies.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,198 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.