Need some help!

Posted by KorvinKray on Wed 16 Dec 2009 11:14 AM — 5 posts, 28,060 views.

#0
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.
Amended on Wed 16 Dec 2009 11:15 AM by KorvinKray
China #1
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
#2
I guess what I am looking for is how do I create and delete aliases from within a script?
Australia Forum Administrator #3
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.

Amended on Thu 17 Dec 2009 07:25 PM by Nick Gammon
#4
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.