Your IP : 216.73.216.224


Current Path : /home/mudbot/eggdrop/
Upload File :
Current File : //home/mudbot/eggdrop/dFight.tcl

set myversion	"1.001"

#########################################################################################################################
#########################################################################################################################
##### 
##### greetings and welcome to dFight: a 1 or 2 player fighting game for eggdrop tcl
##### 
##### it has been designed to work in irc chatrooms where the bot is present; it currently does not
##### work in the partyline, but this could change if enuff peopls aks for it.
##### 
##### this script is written by dLux@PhatNet
##### if you need help, you can email questions and comments to dfight@dsub.net
##### or find me on irc PhatNet; i'm generally sitting in #dopeMaster
##### since this is the first public release of this script, it's online home, http://dsub.net/dfight
##### currently lacks content, but should mature with time..
##### 
##### 
##### setup:
##### - add this script to your eggdrop.conf scripts section, as you would any other script, and rehash
##### - add a user named "boss" to your bot, or else the boss's stats won't be recorded.
##### 	do this in the bot console (telnet):
##### 		.+user boss
##### 	set an obscure password for the boss, so nobody causes trouble with this username on ur bot.
##### 	again in the bot console (telnet):
##### 		.chpass boss <password>
##### - get !fhelp and start a !fight
##### 
##### 
##### readme:
##### - this game produces a lot of channel text
##### 	be aware that this could annoy some peopl, so you might direct peopl to a more appropriate room to play.
##### - this game uses the bot's userfile to save player statistics
##### 	for this reason, players must be registered with the bot to play. if you don't want new users
##### 	on your bot, then leave the INTROCMD blank "" below.. ('guest player' is a feature on my todo list)
##### - each user's record is supplemented with 4 additional XTRA fields; mylvl/mywin/mylos/mydra
##### 	you shouldn't need to concern yourself with these, but i'm putting it out in the open in the
##### 	unlikely event your bot's userfile allready contains these XTRAs.
##### - if you have other bots in your bot's user list, you can set their autofighting style so that they may 
##### 	be fought against in an autofight. the following will only work if you have enabled the .tcl command 
##### 	in your eggdrop.conf, which as the .conf suggests, should be safe to do if you choose your owners wisely.
##### 	i endorse this line of thinking, since in this script, the bot owner has the ability to reset the 
##### 	game as well as player stats. perform the following in the bot console (telnet):
##### 		.tcl setuser <username> XTRA myafs random
##### 	replace <username> with the name of the bot whose afs ur trying to set. you may also substitute
##### 	random with one of the following autofighting styles: agro/mello/psycho/safe. to undo this:
##### 		.tcl setuser <username> XTRA myafs ""
##### 	this will set the afs to empty, and the player will not autofight.
##### - review the user configurations settings below. they should work as-is, but u may wish to customize them.
##### 	in my experience, some peopl prefer no color or style, for this reason you can switch to the unstyled
##### 	set of settings below.
##### - changing the color and styles:
##### 	only change a color to another color, and a style to anther style, or else the output could be
##### 	severely mangled due to how styles are toggles, and color needs termination.
##### - "high score" server load:
##### 	this is an unnoticable blip in my environment (around 15 users), but i imagine this might be noticable,
##### 	perhaps even problematic if your bot has hundreds or thousands of users.. try !fhis once, and if it
##### 	is a problem, use this script on a bot with a smaller userlist; be considerate of your bot's host!
##### 
##### 
##### tips for fighting:
##### -	the best way to level up is by fighting the boss, since it's health is up to 25% more than urs,
##### 	however this also makes the boss a formidable opponent.
##### -	the safest way to level up is against a weaker autofighter, but this won't win u as much of a level up
##### - beyond this, everything is random (with variable odds), so i really can't tell you how to be a better
##### 	fighter; there are no secrets that will give you an edge, and in fact the boss has been kicking my ass.
##### 	if you find a strategy that works, share it with me! i'll include it here and give u credit for it.
##### 
##### 
##### todo:
##### -	inform the player at the end of a match if they've set a new high score
##### -	guest fighter: let peopl play if they're not registered with the bot, just don't save their stats
##### -	defensive output could make better sense
##### - powerups
##### 
##### 
##### known bugs:
##### - player 1 can't suicide on 1st turn (they can, but it's not fatal)
##### - player 2's 1st turn suicide isn't reported as intended
##### 
##### 
##### version history:
#####  1.001 - 05.11.08 - first public release
##### 
##### 
##### acknowledgements:
##### 	GOD-EMPEROR for sitestat; urs was the reason i first setup an eggdrop, and ur themeing was an inspiration
##### 	perplexa; ur rss script is aces, and u showed me that one doesn't hafta be a dick to code tcl
##### 
#########################################################################################################################
#########################################################################################################################
##### 
##### DISCLAIMER:
##### 	this script is for entertainment purposes only.
##### 	i accept no liability for damages incurred, however i honestly don't think it's capable of causing any.
##### 	this script has been tested to run safely, but no gaurentee is offered; if you are concerened
##### 		about it's possible affects, test it in a sandbox first.
##### 	the only file this script modifies is the bot's userfile; it does so using the 'setuser' command,
##### 		which seems to be the kosher way to do it. this is my 2nd tcl script; so you tell me where i'm wrong.
##### 	this game will not improve your phsyique, nor will it prepare you for real world fighting. it might
##### 		improve your reaction time and typing skills, but i doubt it =P
##### 	i don't support beating up weaker peopl unless they've genuinely aksed for it.
##### 	lastly, while beating up the boss is fun and challenging, in real life it will almost certainly get 
##### 		you fired, and i won't be held responsible for this outcome.
##### 
#########################################################################################################################
#########################################################################################################################
###
### user configuration settings:
###

set CHALLENGESECS	"20"
set ROUNDLENGSECS	"35"
### CHALLENGESECS "20" ### when a challenge is made, it will last unanswered for 20 secs.
### ROUNDLENGSECS "35" ### when a fight is in progress, there is a 35 sec pause for players to enter their move,
###                        35 ends up being more like 30 secs with the bot's buffered output and irc lag

set INTROCMD		""
### the command used in your eggdrop.conf to introduce urself to the bot, as in:
###  /msg $botname <INTROCMD>
### or in my case:
###  /msg dopeMaster yoyodope
### leave empty "" if u don't want to mention this to folks who are not registered with the bot when they try and fight

set BOSSAFS			"random"
### set the boss's autofighting style. must be one of: random/agro/mello/psycho/safe
### 

#### mirc color legend
### 00 white				06 purple				12 blue
### 01 black				07 orange				13 pink
### 02 dark blue			08 yellow				14 dark grey
### 03 dark green			09 light green			15 light grey
### 04 red					10 teal (medium light blue)
### 05 dark red				11 cyan (light blue)
###
#### eggdrop color & style characters
### \003xx,yy	xx colored text, on a yy colored background
### \003			color off
### \002			bold
### \037			underline

### here's a nice default colored and styled set of options
set FMTBASICCOLOR		"\00315,01"		;# \00315,01 = light grey on black background
set FMTNAMECOLOR		"\00300,01"		;# \00300,01 = white on black
set FMTNAMESTYLE		"\002"			;# \002 = bold
set FMTSTATCOLOR		$FMTNAMECOLOR
set FMTSTATSTYLE		"\002"
set FMTSTATDELTA		"\037"
set FMTCMDCOLOR			"\00311,01"		;# \00311,01 = cyan (light blue) on black
set FMTCMDSTYLE			"\002"
set FMTCOLOROFF			"\003"			;# don't change this except to empty "" when removing all color
set FMTBULLET			"\00314,01\002 -- \002\003"			;# used as a separator for visual style

### use this set instead if you don't want any color or style (bold/underline) at all 
#set FMTBASICCOLOR		""
#set FMTNAMECOLOR		""
#set FMTNAMESTYLE		""
#set FMTSTATCOLOR		""
#set FMTSTATSTYLE		""
#set FMTSTATDELTA		""
#set FMTCMDCOLOR			""
#set FMTCMDSTYLE			""
#set FMTCOLOROFF			""
#set FMTBULLET			" -- "

###
### end of user configuration settings!
### editing below here is discouraged unless you really know what you're doing!
#########################################################################################################################
#########################################################################################################################














#########################################################################################################################
### formatoutput - color/style it and say it
###

proc formatoutput {type text} {

	global botnick INTROCMD FMTCMDCOLOR FMTCMDSTYLE FMTBULLET
	global FMTBASICCOLOR FMTCOLOROFF FMTNAMECOLOR FMTNAMESTYLE FMTSTATCOLOR FMTSTATSTYLE FMTSTATDELTA

	set myout ""
	if {$type == "stranger"} {
		set nick	[lindex $text 0]
		set chan	[lindex $text 1]

		set tmessage "$nick, i don't know who you are."
		append myout $FMTBASICCOLOR $tmessage $FMTCOLOROFF
		if {$INTROCMD != ""} {
			append myout " " $FMTCMDCOLOR $FMTCMDSTYLE "/msg $botnick $INTROCMD" $FMTCMDSTYLE $FMTCOLOROFF
		} else {
			append myout "$FMTBASICCOLOR you can't fight until we've been introduced.$FMTCOLOROFF"
		}

	} elseif {$type == "simple"} {
		set nick	[lindex $text 0]
		set chan	[lindex $text 1]
		set info	[lindex $text 2]

		append myout $FMTBASICCOLOR $info $FMTCOLOROFF

	} elseif {$type == "simplecolr"} {
		set nick	[lindex $text 0]
		set chan	[lindex $text 1]
		set info	[lindex $text 2]
		set color	[lindex $text 3]

		append myout $color $info $FMTCOLOROFF

	} elseif {($type == "error")||($type == "sorry")} {
		set nick	[lindex $text 0]
		set chan	[lindex $text 1]
		set info	[lindex $text 2]

		set tmessage "$type $nick, $info"
		append myout $FMTBASICCOLOR $tmessage $FMTCOLOROFF

	} elseif {$type == "stat"} {
		set nick	[lindex [lindex $text 0] 0]
		set chan	[lindex [lindex $text 0] 1]
		set mylvl	[lindex [lindex $text 1] 0]
		set mylvld	[lindex [lindex $text 1] 1]
		set mywin	[lindex [lindex $text 2] 0]
		set mywind	[lindex [lindex $text 2] 1]
		set mylos	[lindex [lindex $text 3] 0]
		set mylosd	[lindex [lindex $text 3] 1]
		set mydra	[lindex [lindex $text 4] 0]
		set mydrad	[lindex [lindex $text 4] 1]
		set myafs	[lindex [lindex $text 5] 0]
		set myafsd	[lindex [lindex $text 5] 1]

		append myout $FMTNAMECOLOR$FMTNAMESTYLE $nick $FMTNAMESTYLE$FMTCOLOROFF " " $FMTSTATCOLOR (
		if {$mylvld != "hide"} { append myout H $FMTSTATSTYLE $mylvl $FMTSTATSTYLE / }
		if {$mywind != "hide"} { append myout $FMTSTATSTYLE $mywin $FMTSTATSTYLE W / }
		if {$mylosd != "hide"} { append myout $FMTSTATSTYLE $mylos $FMTSTATSTYLE L / }
		if {$mydrad != "hide"} { append myout $FMTSTATSTYLE $mydra $FMTSTATSTYLE D }
		if {($myafs != "")&&($myafsd != "hide")&&($myafsd != "solo")} {	append myout / $myafs
		} elseif {$myafsd == "solo"} { append myout $myafs }
		append myout ) $FMTCOLOROFF

	} elseif {$type == "turnsimple"} {
		set chan	[lindex $text 0]

		set p1nick	[lindex $text {1 0}]
		set p1hea	[lindex $text {1 1}]

		set p2nick	[lindex $text {2 0}]
		set p2hea	[lindex $text {2 1}]
		set p2afs	[lindex $text {2 2}]

		append myout $FMTBULLET $FMTNAMECOLOR $FMTNAMESTYLE $p1nick $FMTNAMESTYLE $FMTBASICCOLOR " " ( $FMTSTATCOLOR $FMTSTATSTYLE $p1hea $FMTSTATSTYLE % $FMTBASICCOLOR ) " " $FMTCOLOROFF
		append myout $FMTBULLET $FMTBASICCOLOR "vs" $FMTCOLOROFF $FMTBULLET $FMTNAMECOLOR
		if			{$p2afs != "null"} {append myout $p2afs}
		append myout $FMTNAMESTYLE $p2nick $FMTNAMESTYLE $FMTBASICCOLOR " " ( $FMTSTATCOLOR $FMTSTATSTYLE $p2hea $FMTSTATSTYLE % $FMTBASICCOLOR ) $FMTCOLOROFF $FMTBULLET

	} elseif {$type == "turnstat"} {
		set chan	[lindex $text 0]

		set p1nick	[lindex $text {1 0}]
		set p1lvl	[lindex $text {1 1}]
		set p1lvld	[lindex $text {1 2}]
		set p1win	[lindex $text {1 3}]
		set p1wind	[lindex $text {1 4}]
		set p1los	[lindex $text {1 5}]
		set p1losd	[lindex $text {1 6}]
		set p1dra	[lindex $text {1 7}]
		set p1drad	[lindex $text {1 8}]

		set descrp	[lindex $text 2]

		set p2nick	[lindex $text {3 0}]
		set p2lvl	[lindex $text {3 1}]
		set p2lvld	[lindex $text {3 2}]
		set p2win	[lindex $text {3 3}]
		set p2wind	[lindex $text {3 4}]
		set p2los	[lindex $text {3 5}]
		set p2losd	[lindex $text {3 6}]
		set p2dra	[lindex $text {3 7}]
		set p2drad	[lindex $text {3 8}]
		set p2afs	[lindex $text {3 9}]

		append myout $FMTBULLET $FMTNAMECOLOR $FMTNAMESTYLE $p1nick $FMTNAMESTYLE $FMTBASICCOLOR " " (

		if {$p1lvld == "null"} {
			append myout $FMTSTATCOLOR H $FMTSTATSTYLE $p1lvl $FMTSTATSTYLE $FMTBASICCOLOR /
		} else {
			append myout $FMTSTATCOLOR $p1lvld $FMTSTATDELTA H $FMTSTATSTYLE $p1lvl $FMTSTATSTYLE $FMTSTATDELTA $FMTBASICCOLOR /
		}
		if			{$p1wind == "null"} { append myout $FMTSTATCOLOR $FMTSTATSTYLE $p1win $FMTSTATSTYLE W $FMTBASICCOLOR /
		} elseif	{$p1wind == "diff"} { append myout $FMTSTATCOLOR $FMTSTATDELTA $FMTSTATSTYLE $p1win $FMTSTATSTYLE W $FMTSTATDELTA $FMTBASICCOLOR / }
		if			{$p1losd == "null"} { append myout $FMTSTATCOLOR $FMTSTATSTYLE $p1los $FMTSTATSTYLE L $FMTBASICCOLOR /
		} elseif	{$p1losd == "diff"} { append myout $FMTSTATCOLOR $FMTSTATDELTA $FMTSTATSTYLE $p1los $FMTSTATSTYLE L $FMTSTATDELTA $FMTBASICCOLOR / }
		if			{$p1drad == "null"} { append myout $FMTSTATCOLOR $FMTSTATSTYLE $p1dra $FMTSTATSTYLE D $FMTBASICCOLOR )
		} elseif	{$p1drad == "diff"} { append myout $FMTSTATCOLOR $FMTSTATDELTA $FMTSTATSTYLE $p1dra $FMTSTATSTYLE D $FMTSTATDELTA $FMTBASICCOLOR ) }

		append myout $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "$descrp" $FMTCOLOROFF $FMTBULLET $FMTNAMECOLOR
		if			{$p2afs != "null"} {append myout $p2afs}
		append myout $FMTNAMESTYLE $p2nick $FMTNAMESTYLE $FMTCOLOROFF " " $FMTBASICCOLOR (

		if {$p2lvld == "null"} {
			append myout $FMTSTATCOLOR H $FMTSTATSTYLE $p2lvl $FMTSTATSTYLE $FMTBASICCOLOR / 
		} elseif {$p2lvld == "hide"} {
		} else {
			append myout $FMTSTATCOLOR $p2lvld $FMTSTATDELTA H $FMTSTATSTYLE $p2lvl $FMTSTATSTYLE $FMTSTATDELTA $FMTBASICCOLOR / 
		}
		if			{$p2wind == "null"} { append myout $FMTSTATCOLOR $FMTSTATSTYLE $p2win $FMTSTATSTYLE W $FMTBASICCOLOR /
		} elseif	{$p2wind == "diff"} { append myout $FMTSTATCOLOR $FMTSTATDELTA $FMTSTATSTYLE $p2win $FMTSTATSTYLE W $FMTSTATDELTA $FMTBASICCOLOR / }
		if			{$p2losd == "null"} { append myout $FMTSTATCOLOR $FMTSTATSTYLE $p2los $FMTSTATSTYLE L $FMTBASICCOLOR /
		} elseif	{$p2losd == "diff"} { append myout $FMTSTATCOLOR $FMTSTATDELTA $FMTSTATSTYLE $p2los $FMTSTATSTYLE L $FMTSTATDELTA $FMTBASICCOLOR / }
		if			{$p2drad == "null"} { append myout $FMTSTATCOLOR $FMTSTATSTYLE $p2dra $FMTSTATSTYLE D $FMTBASICCOLOR )
		} elseif	{$p2drad == "diff"} { append myout $FMTSTATCOLOR $FMTSTATDELTA $FMTSTATSTYLE $p2dra $FMTSTATSTYLE D $FMTSTATDELTA $FMTBASICCOLOR ) }
		append myout $FMTCOLOROFF $FMTBULLET 

	} elseif {$type == "roundcmd"} {
		set chan	[lindex $text 0]
		set curr	[lindex $text 1]
		set cmds	[lindex $text {2 0}]
		set cmdsll	[llength [lindex $text {2 0}]]
		set cmdsmo	[expr {$cmdsll - 1}]

		append myout $FMTBULLET $FMTNAMECOLOR $FMTNAMESTYLE "round " $curr ": FIGHT" $FMTNAMESTYLE $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "\[ "
		for {set i 0} {$i < $cmdsll} {incr i} {
			set tdiv " | "
			if {$i == $cmdsmo} {set tdiv " "}
			append myout $FMTCMDCOLOR $FMTCMDSTYLE "!" [lindex $cmds $i] $FMTCMDSTYLE $FMTBASICCOLOR "$tdiv"
		}
		append myout "\]" $FMTCOLOROFF $FMTBULLET

	} elseif {$type == "challenge"} {
		set p1			[lindex $text 0]
		set p2			[lindex $text 1]
		set chan		[lindex $text 2]
		set chalsecs	[lindex $text {3 0}]
		set whatAF		[lindex $text {3 1}]

		append myout $FMTNAMECOLOR $FMTNAMESTYLE $p1 $FMTNAMESTYLE $FMTBASICCOLOR " challenges " $FMTNAMECOLOR $FMTNAMESTYLE $p2 $FMTNAMESTYLE $FMTBASICCOLOR
		if {($whatAF == "noAF")||($whatAF == "thenAF")} {
			append myout ", " $FMTSTATSTYLE $chalsecs $FMTSTATSTYLE " secs to accept " $FMTCMDCOLOR $FMTCMDSTYLE "!fight" $FMTCMDSTYLE $FMTBASICCOLOR
			if {$whatAF == "noAF"} {append myout "."}
			if {$whatAF == "thenAF"} {append myout " before autofight." }
		} elseif {$whatAF == "doAF"}	{ append myout " to an " $FMTNAMECOLOR auto $FMTNAMESTYLE fight $FMTNAMESTYLE $FMTBASICCOLOR "!"
		}
		append myout $FMTCOLOROFF

	}
	puthelp "PRIVMSG $chan :$myout"
}


#########################################################################################################################
### info related
###

###
### fhelp
###
###
proc fhelpmsg {nick host handle text} {
	fhelp $nick $host $handle $nick $text
}
proc fhelp {nick host handle chan text} {
	global FIGHTINPROGRESS PLAYER1 PLAYER2
	if {($FIGHTINPROGRESS == 0)||($FIGHTINPROGRESS == "")} {
		### do help
		fhelpshow $nick $chan $text
	} elseif {$FIGHTINPROGRESS == 1} {
		if {$nick == $PLAYER1} {
			formatoutput sorry "$nick $chan {you have issued a challenge, if you dunno how to fight, pray the challenge remains unanswered and in [lindex [utimers] {0 0}] seconds you can get fhelp.}"
		} elseif {$nick == $PLAYER2} {
			formatoutput sorry "$nick $chan {a challenge is pending against you, if you are uncertain about how to fight you should sit this one out, and in [lindex [utimers] {0 0}] seconds you can get fhelp.}"
		} else {
			formatoutput sorry "$nick $chan {a challenge is pending, if the fight does not start in [lindex [utimers] {0 0}] seconds you can get fhelp.}"
		}
	} elseif {$FIGHTINPROGRESS > 1} {
		### no help, a fight is in progress
		##### UNLESS ur one of the fighters, in which case fhelp fight actions
		formatoutput sorry "$nick $chan {a fight is in progress ($PLAYER1 vs $PLAYER2) when it is finished you can get fhelp.}"
	} else {
		formatoutput sorry "$nick $chan {an error occurred determining the state of the game.}"
	}
}
proc fhelpshow {nick chan text} {
	global botnick owner myversion FMTCMDCOLOR FMTCMDSTYLE FMTBULLET CHALLENGESECS
	global FMTBASICCOLOR FMTCOLOROFF FMTNAMECOLOR FMTNAMESTYLE FMTSTATCOLOR FMTSTATSTYLE FMTSTATDELTA
	if {$text == ""} {
		set chan "$nick"

		set toutput ""
		set toutput [append toutput $FMTNAMECOLOR $FMTNAMESTYLE "dFight $myversion" $FMTNAMESTYLE $FMTBASICCOLOR " by dLux@PhatNet" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE !fhelp $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE fight $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE action $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE basic $FMTCMDSTYLE $FMTBASICCOLOR]
		if {$nick == $owner} {
			set toutput [append toutput " | " $FMTCMDCOLOR $FMTCMDSTYLE admin $FMTCMDSTYLE $FMTBASICCOLOR]
		}
		set toutput [append toutput "\]" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR  "challenge another fighter to a fight, or start an autofight. " $FMTCMDCOLOR $FMTCMDSTYLE "!fhelp fight" $FMTCMDSTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR  "once the fight is underway, use the action commands to fight. " $FMTCMDCOLOR $FMTCMDSTYLE "!fhelp action" $FMTCMDSTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBASICCOLOR  "see also: " $FMTCMDCOLOR $FMTCMDSTYLE !fhelp $FMTCMDSTYLE $FMTBASICCOLOR " <" $FMTCMDCOLOR $FMTCMDSTYLE topic $FMTCMDSTYLE $FMTBASICCOLOR "> " $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBASICCOLOR  " example: " $FMTCMDCOLOR $FMTCMDSTYLE "!fhelp basic" $FMTCMDSTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"


		set toutput ""
		set toutput [append toutput $FMTNAMECOLOR $FMTNAMESTYLE "msg command:" $FMTNAMESTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE "/msg $botnick" $FMTCMDSTYLE $FMTBASICCOLOR " " $FMTCMDCOLOR $FMTCMDSTYLE fhelp $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE topic $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

	} elseif {$text == "fight"} {
		set chan "$nick"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE "!fight nick " $FMTCMDSTYLE $FMTBASICCOLOR "\[" $FMTCMDCOLOR $FMTCMDSTYLE noauto $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "challenge nick to a fight, optionally only if they accept" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR  "when a challenge is issued, the opponent must accept the challenge, by typing " $FMTCMDCOLOR $FMTCMDSTYLE "!fight" $FMTCMDSTYLE $FMTBASICCOLOR " within the time limit, in the same channel." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR  "if nick is a known autofighter and not in the channel, an autofight immediately starts." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR  "if nick is not boss, then the winner gets 10% of loser's starting health." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR  "there is no penalty for losing against anyone other than the boss." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR  "the boss's health is randomly between 100-125% of urs, and the prize/penalty for winning/losing is +/- the boss's advantage." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBASICCOLOR  "see also: " $FMTCMDCOLOR $FMTCMDSTYLE "!fhelp action" $FMTCMDSTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

	} elseif {$text == "basic"} {
		set chan "$nick"

		set toutput ""
		set toutput [append toutput $FMTNAMECOLOR $FMTNAMESTYLE "basic commands:" $FMTNAMESTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE !fstat $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE nick $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "view your own or \[nick\]'s fighting stats" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE !fauto $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE agro $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE mello $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE psycho $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE safe $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE none $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "view \[or set\] your autofighting style" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE !fight $FMTCMDSTYLE $FMTBASICCOLOR $FMTCMDCOLOR $FMTCMDSTYLE " nick " $FMTCMDSTYLE $FMTBASICCOLOR "\[" $FMTCMDCOLOR $FMTCMDSTYLE noauto $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "challenge nick to a fight, optionally only if they accept" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE !fhis $FMTCMDSTYLE $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "view the high scores" $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"


		set toutput ""
		set toutput [append toutput $FMTNAMECOLOR $FMTNAMESTYLE "msg commands:" $FMTNAMESTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE "/msg $botnick" $FMTCMDSTYLE $FMTBASICCOLOR " " $FMTCMDCOLOR $FMTCMDSTYLE fstat $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE nick $FMTCMDSTYLE $FMTBASICCOLOR "\] | " $FMTCMDCOLOR $FMTCMDSTYLE fauto $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE style $FMTCMDSTYLE $FMTBASICCOLOR "\] | " $FMTCMDCOLOR $FMTCMDSTYLE fhis $FMTCMDSTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

	} elseif {$text == "action"} {
		set chan "$nick"

		set toutput ""
		set toutput [append toutput $FMTNAMECOLOR $FMTNAMESTYLE "fight actions:" $FMTNAMESTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR "the effect of an offensive action is randomly up to <damage>% of your starting health." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR "guard and dodge are defensive actions that use the same method to calculate what the opponent's offensive move is reduced by." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set toutput ""
		set toutput [append toutput $FMTBULLET $FMTBASICCOLOR "a lucky strike is an unguarded bonus attack, that is up to 25% of successful damage. you can't be lucky if you aren't successful." $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"

		set cmdshort	[actionlookup all 1]
		set cmdslong	[actionlookup all 0]
		set cmdstype	[actionlookup all 2]
		set cmdspoin	[actionlookup all 3]
		set cmdssucc	[actionlookup all 4]
		set cmdsluck	[actionlookup all 5]
		set cmdsll	[llength $cmdslong]

		for {set i 0} {$i < $cmdsll} {incr i} {
			set toutput ""
			set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE "!" [lindex $cmdshort $i] $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE "!" [lindex $cmdslong $i] $FMTCMDSTYLE $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR]
			if {[lindex $cmdslong $i] != "suicide"} {
				set toutput [append toutput [lindex $cmdspoin $i] "% damage, " [lindex $cmdssucc $i] "% success, " [lindex $cmdsluck $i] "% lucky." $FMTCOLOROFF]
			} else {
				set toutput [append toutput "kamakazi attack; kills urself, lucky damage if successful " [lindex $cmdssucc $i] "% and lucky " [lindex $cmdsluck $i] "%." $FMTCOLOROFF]
			}
			puthelp "PRIVMSG $chan :$toutput"
		}

	} elseif {$text == "admin"} {
		set chan "$nick"

		if {$nick == $owner} {
			set toutput ""
			set toutput [append toutput $FMTNAMECOLOR $FMTNAMESTYLE "admin commands ($owner only):" $FMTNAMESTYLE $FMTCOLOROFF]
			puthelp "PRIVMSG $chan :$toutput"
	
			set toutput ""
			set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE !freset $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE "nick" $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "reset game \[or reset nick's stats to lvl 10, win/los/dra: 0\]" $FMTCOLOROFF]
			puthelp "PRIVMSG $chan :$toutput"
	
			set toutput ""
			set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE !fdebug $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE 1 $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE 2 $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF $FMTBULLET $FMTBASICCOLOR "view verbose math" $FMTCOLOROFF]
			puthelp "PRIVMSG $chan :$toutput"
		
	
			set toutput ""
			set toutput [append toutput $FMTNAMECOLOR $FMTNAMESTYLE "msg commands ($owner only):" $FMTNAMESTYLE $FMTCOLOROFF]
			puthelp "PRIVMSG $chan :$toutput"
	
			set toutput ""
			set toutput [append toutput $FMTCMDCOLOR $FMTCMDSTYLE "/msg $botnick" $FMTCMDSTYLE $FMTBASICCOLOR " " $FMTCMDCOLOR $FMTCMDSTYLE freset $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE nick $FMTCMDSTYLE $FMTBASICCOLOR "\] | " $FMTCMDCOLOR $FMTCMDSTYLE fdebug $FMTCMDSTYLE $FMTBASICCOLOR " \[" $FMTCMDCOLOR $FMTCMDSTYLE 1 $FMTCMDSTYLE $FMTBASICCOLOR "|" $FMTCMDCOLOR $FMTCMDSTYLE 2 $FMTCMDSTYLE $FMTBASICCOLOR "\]" $FMTCOLOROFF]
			puthelp "PRIVMSG $chan :$toutput"
		} else {
			set toutput ""
			set toutput [append toutput $FMTBASICCOLOR "sorry $nick, this command is for bot owners only." $FMTNAMESTYLE $FMTCOLOROFF]
			puthelp "PRIVMSG $chan :$toutput"
		}

	} else {
		set toutput ""
		set toutput [append toutput "sorry $nick, i can not fhelp you with \"$text\". you should start with just " $FMTCMDCOLOR $FMTCMDSTYLE !fhelp $FMTCMDSTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"
	}
}

###
### fhis
###
###
proc fhismsg {nick host handle text} {
	fhis $nick $host $handle $nick $text
}
proc fhis {nick host handle chan text} {
	global FMTCMDCOLOR FMTCMDSTYLE FMTBULLET
	global FMTBASICCOLOR FMTCOLOROFF FMTNAMECOLOR FMTNAMESTYLE FMTSTATCOLOR FMTSTATSTYLE FMTSTATDELTA
	set FIGHTERS [userlist]
	set nFIGHTERS [llength $FIGHTERS]
	
	set TOPAer ""
	set TOPBer ""
	set TOPCer ""

	set TOPAed ""
	set TOPBed ""
	set TOPCed ""

	set MWINer ""
	set MLOSer ""
	set MPLAer ""
	
	set MWINed "0"
	set MLOSed "0"
	set MPLAed "0"
	
	for {set i 0} {$i < $nFIGHTERS} {incr i} {
		set MYNIC [lindex $FIGHTERS $i]
		set MYLVL [getuser [lindex $FIGHTERS $i] XTRA mylvl]
		set MYWIN [getuser [lindex $FIGHTERS $i] XTRA mywin]
		set MYLOS [getuser [lindex $FIGHTERS $i] XTRA mylos]
		set MYDRA [getuser [lindex $FIGHTERS $i] XTRA mydra]

		if {($MYNIC != "boss")&&($MYLVL != "")} {
			if {$MYLVL > $TOPAed} {
				set TOPCer $TOPBer
				set TOPCed $TOPBed
				set TOPBer $TOPAer
				set TOPBed $TOPAed
				set TOPAer [lindex $FIGHTERS $i]
				set TOPAed $MYLVL
			} elseif {($MYLVL <= $TOPAed)&&($MYLVL > $TOPBed)} {
				set TOPCer $TOPBer
				set TOPCed $TOPBed
				set TOPBer [lindex $FIGHTERS $i]
				set TOPBed $MYLVL
			} elseif {($MYLVL <= $TOPBed)&&($MYLVL > $TOPCed)} {
				set TOPCer [lindex $FIGHTERS $i]
				set TOPCed $MYLVL
			}
		}

		if {$MYWIN == ""} {set MYWIN "0"}
		if {$MYLOS == ""} {set MYLOS "0"}
		if {$MYDRA == ""} {set MYDRA "0"}
		set MYPLA [expr {$MYWIN + $MYLOS + $MYDRA}]

		if {$MYWIN > $MWINed} {
			set MWINer [lindex $FIGHTERS $i]
			set MWINed $MYWIN
		}
		if {$MYLOS > $MLOSed} {
			set MLOSer [lindex $FIGHTERS $i]
			set MLOSed $MYLOS
		}
		if {$MYPLA > $MPLAed} {
			set MPLAer [lindex $FIGHTERS $i]
			set MPLAed $MYPLA
		}
	}
	if {$TOPAed != ""} {
		
		set toutput ""
		set toutput [append toutput $FMTBASICCOLOR "strongest fighters:" $FMTNAMESTYLE]
		puthelp "PRIVMSG $chan :$toutput"
		set toutput ""
		set toutput [append toutput $FMTNAMECOLOR "$TOPAed) " $FMTNAMESTYLE $FMTNAMECOLOR "$TOPAer" $FMTNAMESTYLE $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"
		if {$TOPBed != ""} {
			set toutput ""
			set toutput [append toutput $FMTNAMECOLOR "$TOPBed) " $FMTNAMESTYLE $FMTNAMECOLOR "$TOPBer" $FMTNAMESTYLE $FMTCOLOROFF]
			puthelp "PRIVMSG $chan :$toutput"
			if {$TOPCed != ""} {
				set toutput ""
				set toutput [append toutput $FMTNAMECOLOR "$TOPCed) " $FMTNAMESTYLE $FMTNAMECOLOR "$TOPCer" $FMTNAMESTYLE $FMTCOLOROFF]
				puthelp "PRIVMSG $chan :$toutput"
			}
		}
	}
	if {$MPLAed != "0"} {
		set toutput ""
		set toutput [append toutput $FMTBASICCOLOR "most plays: " $FMTNAMECOLOR "$MPLAer " $FMTSTATCOLOR $FMTSTATSTYLE "$MPLAed" $FMTSTATSTYLE x $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"
	}
	if {$MWINed != "0"} {
		set toutput ""
		set toutput [append toutput $FMTBASICCOLOR "most wins: " $FMTNAMECOLOR "$MWINer " $FMTSTATCOLOR $FMTSTATSTYLE "$MWINed" $FMTSTATSTYLE W $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"
	}
	if {$MLOSed != "0"} {
		set toutput ""
		set toutput [append toutput $FMTBASICCOLOR "most losses: " $FMTNAMECOLOR "$MLOSer " $FMTSTATCOLOR $FMTSTATSTYLE "$MLOSed" $FMTSTATSTYLE L $FMTCOLOROFF]
		puthelp "PRIVMSG $chan :$toutput"
	}
}
proc fstatshow {nick chan target} {
	set MYLVL [getuser $target XTRA mylvl]
	set MYWIN [getuser $target XTRA mywin]
	set MYLOS [getuser $target XTRA mylos]
	set MYDRA [getuser $target XTRA mydra]
	set MYAFS [getuser $target XTRA myafs]

	if {$MYLVL == ""} {set MYLVL "10"}
	if {$MYWIN == ""} {set MYWIN "0"}
	if {$MYLOS == ""} {set MYLOS "0"}
	if {$MYDRA == ""} {set MYDRA "0"}

	if {$target == "boss"} {
		set MYAFS $BOSSAFS
		formatoutput stat "{$target $chan} {$MYLVL hide} $MYWIN $MYLOS $MYDRA $MYAFS"
	} else {
		formatoutput stat "{$target $chan} $MYLVL $MYWIN $MYLOS $MYDRA $MYAFS"
	}
}

###
### !fstat [nick]
###
###
proc fstatmsg {nick host handle text} {
	fstat $nick $host $handle $nick $text
}
proc fstat {nick host handle chan text} {
	set STATTARGET ""
	if {[validuser $nick]} {
		set STATTARGET [lindex $text 0]
		if {$STATTARGET != ""} {
			if {[validuser $STATTARGET]} {
				fstatshow $nick $chan $STATTARGET
			} else {
				formatoutput error "$nick $chan {i don't know who \"$STATTARGET\" is.}"
			}
		} else {
		fstatshow $nick $chan $nick
		}
	} else {
		formatoutput stranger "$nick $chan"
	}
}
proc fstatshow {nick chan target} {
	global BOSSAFS
	set MYLVL [getuser $target XTRA mylvl]
	set MYWIN [getuser $target XTRA mywin]
	set MYLOS [getuser $target XTRA mylos]
	set MYDRA [getuser $target XTRA mydra]
	set MYAFS [getuser $target XTRA myafs]

	if {$MYLVL == ""} {set MYLVL "10"}
	if {$MYWIN == ""} {set MYWIN "0"}
	if {$MYLOS == ""} {set MYLOS "0"}
	if {$MYDRA == ""} {set MYDRA "0"}

	if {$target == "boss"} {
		set MYAFS $BOSSAFS
		formatoutput stat "{$target $chan} {$MYLVL hide} $MYWIN $MYLOS $MYDRA $MYAFS"
	} else {
		formatoutput stat "{$target $chan} $MYLVL $MYWIN $MYLOS $MYDRA $MYAFS"
	}
}

###
### !fauto [afs]
###
###
proc fautomsg {nick host handle text} {
	fauto $nick $host $handle $nick $text
}
proc fauto {nick host handle chan text} {
	global FMTBASICCOLOR FMTCMDCOLOR FMTCMDSTYLE FMTCOLOROFF
	if {[validuser $nick]} {
		if {$text != ""} {
			set MYAFS [string tolower [lindex $text 0]]
			switch $MYAFS {
				none		-
				psycho		-
				agro		-
				mello		-
				safe {		setuser $nick XTRA myafs $MYAFS
							set $MYAFS ""
							set MYAFS [getuser $nick XTRA myafs]
							formatoutput stat "{$nick $chan} {lvl hide} {win hide} {los hide} {dra hide} {$MYAFS solo}"
				}
				random {	formatoutput sorry "$nick $chan {the \"$MYAFS\" fighting style is intended for boss and bots only.}"
				}
				default	{	append myout "i'm not familiar with the \"$MYAFS\" fighting style. " $FMTCMDCOLOR $FMTCMDSTYLE !fauto $FMTCMDSTYLE $FMTBASICCOLOR " \[ " $FMTCMDCOLOR $FMTCMDSTYLE psycho $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE agro $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE mello $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE safe $FMTCMDSTYLE $FMTBASICCOLOR " | " $FMTCMDCOLOR $FMTCMDSTYLE none $FMTCMDSTYLE $FMTBASICCOLOR " \]"
							formatoutput error "$nick $chan {$myout}"
				}
			}
		} else {
			set MYAFS [getuser $nick XTRA myafs]
			if {$MYAFS == ""} {
				set MYAFS "unspecified"
			}
			formatoutput stat "{$nick $chan} {lvl hide} {win hide} {los hide} {dra hide} {$MYAFS solo}"
		}
	} else {
		formatoutput stranger "$nick $chan"
	}	
}

#########################################################################################################################
### maintenance
###
proc versioninfo {nick host handle chan text} {
	global myversion
	puthelp "PRIVMSG $chan :dFight $myversion"
}

proc foutput {source chan text} {
	puthelp "PRIVMSG $chan :$text"
}


###
### !freset [nick]
###  reset is used to reinitialize the game, or a player's stats.
###  when called manually it also kills the timer.
###
###
proc fresetmanualmsg {nick host handle text} {
	fresetmanual $nick $host $handle $nick $text
}
proc fresetmanual {nick host handle chan text} {
	global CHALLENGECHAN
	if {$CHALLENGECHAN == ""} {
		set tCHAN $chan
	} else {
		set tCHAN $CHALLENGECHAN
	}
	if {$text == ""} {
		set deathtimer ""
		set deathresult ""
		set deathtimer "[lindex "[lindex "[utimers]" 0]" 2]"
		if {$deathtimer != ""} {
			killutimer $deathtimer
			set deathresult "killutimer($deathtimer) and"
		}
		freset $nick
		set myout [concat "$deathresult" "freset($nick)."]
		formatoutput simple "$nick $tCHAN {$myout}"
	} elseif {[validuser $text]} {
		setuser $text XTRA mylvl 10
		setuser $text XTRA mywin 0
		setuser $text XTRA mylos 0
		setuser $text XTRA mydra 0
		fstat $text $host $handle $chan $text
	}
}
proc freset {nick} {
	global FIGHTINPROGRESS CHALLENGETIMERID CHALLENGECHAN CURRENTROUND ROUNDTIMERID ROUNDWASIDLE 
	global PLA1COM P1FX P1FXB P1HEAMAX P1HEAINI P1HEAVIC PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA P1HEA P1MOD
	global PLA2COM P2FX P2FXB P2HEAMAX P2HEAINI P2HEAVIC PLAYER2 P2AFS P2AFSwr P2LVL P2WIN P2LOS P2DRA P2HEA P2MOD
	global P2Aaction P2Apoints P2Asuccess P2Aluck
	global jlimit plimit klimit ulimit glimit dlimit slimit

	initglobalvars
}

###
### !fdebug [1|2]
###
###
proc fdebugmsg {nick host handle text} {
	fdebug $nick $host $handle $nick $text
}
proc fdebug {nick host handle chan text} {
	global CHALLENGESECS ROUNDLENGSECS
	global FIGHTINPROGRESS CHALLENGETIMERID CHALLENGECHAN CURRENTROUND ROUNDTIMERID ROUNDWASIDLE
	global PLA1COM P1MNAME P1MTYPE P1FX P1FXB P1HEAMAX P1HEAINI P1HEAVIC PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA P1HEA P1MOD
	global PLA2COM P2MNAME P2MTYPE P2FX P2FXB P2HEAMAX P2HEAINI P2HEAVIC PLAYER2 P2AFS P2AFSwr P2LVL P2WIN P2LOS P2DRA P2HEA P2MOD
	global jlimit plimit klimit ulimit glimit dlimit slimit

	set myout1 ""
	set myout2 ""
	set myout3 ""
	set myout4 ""
	set myout5 ""
	set myout6 ""
	if {($text == 1)||($text == "")||($text == "all")} {
	foutput $nick $chan "nick($nick) chan($chan) text($text)"
		lappend myout1 "FIGHTINPROGRESS($FIGHTINPROGRESS)" "CHTIMERID($CHALLENGETIMERID)" "CHCHAN($CHALLENGECHAN)" "CURRENTROUND($CURRENTROUND)" "ROUNDTIMERID($ROUNDTIMERID)" "chsecs($CHALLENGESECS)" "rlsecs($ROUNDLENGSECS)"
		lappend myout2 "PLAYER1($PLAYER1)" "COM($PLA1COM)" "HEA($P1HEA)" "P1MOD($P1MOD)" "P1FX($P1FX)" "P1FXB($P1FXB)" "AFS($P1AFS)" "L($P1LVL)" "($P1WIN)W" "($P1LOS)L" "($P1DRA)D" "HINI($P1HEAINI)" "HMAX($P1HEAMAX)"
		lappend myout3 "PLAYER2($PLAYER2)" "COM($PLA2COM)" "HEA($P2HEA)" "P2MOD($P2MOD)" "P2FX($P2FX)" "P2FXB($P2FXB)" "AFS($P2AFS)" "L($P2LVL)" "($P2WIN)W" "($P2LOS)L" "($P2DRA)D" "HINI($P2HEAINI)" "HMAX($P2HEAMAX)" "P2AFSwr($P2AFSwr)"
	}
	if {($text == "2")||($text == "all")} {
#		lappend myout4 "P2Aaction($P2Aaction)" "P2Apoints($P2Apoints)" "P2Asuccess($P2Asuccess)" "P2Aluck($P2Aluck)"
#		lappend myout5 "com(points/success/luck)" "j($jpoints/$jsuccess/$jluck)" "p($ppoints/$psuccess/$pluck)" "k($kpoints/$ksuccess/$kluck)" "u($upoints/$usuccess/$uluck)" "g($gpoints/$gsuccess/$gluck)" "d($dpoints/$dsuccess/$dluck)" "s($spoints/$ssuccess/$sluck)"
#		lappend myout6 "jlimit($jlimit)" "plimit($plimit)" "klimit($klimit)" "ulimit($ulimit)" "glimit($glimit)" "dlimit($dlimit)" "slimit($slimit)"
		lappend myout4 "$PLAYER1" "COM($PLA1COM)" "MNAME($P1MNAME)" "MTYPE($P1MTYPE)" "HEA($P1HEA)" "MOD($P1MOD)" "FX($P1FX)" "FXB($P1FXB)" "HINI($P1HEAINI)" "HMAX($P1HEAMAX)"
		lappend myout5 "$PLAYER2" "COM($PLA2COM)" "MNAME($P2MNAME)" "MTYPE($P2MTYPE)" "HEA($P2HEA)" "MOD($P2MOD)" "FX($P2FX)" "FXB($P2FXB)" "HINI($P2HEAINI)" "HMAX($P2HEAMAX)"
	}
	if {($myout1 != "")} {foutput $nick $chan "$myout1"}
	if {($myout2 != "")} {foutput $nick $chan "$myout2"}
	if {($myout3 != "")} {foutput $nick $chan "$myout3"}
	if {($myout4 != "")} {foutput $nick $chan "$myout4"}
	if {($myout5 != "")} {foutput $nick $chan "$myout5"}
	if {($myout6 != "")} {foutput $nick $chan "$myout6"}
}

###
### initialize global variables
###
###
proc initglobalvars {} {
	global FIGHTINPROGRESS CHALLENGETIMERID CHALLENGECHAN CURRENTROUND ROUNDTIMERID ROUNDWASIDLE 
	global PLA1COM P1MNAME P1MTYPE P1FX P1FXB P1HEAMAX P1HEAINI P1HEAVIC PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA P1HEA P1MOD
	global PLA2COM P2MNAME P2MTYPE P2FX P2FXB P2HEAMAX P2HEAINI P2HEAVIC PLAYER2 P2AFS P2AFSwr P2LVL P2WIN P2LOS P2DRA P2HEA P2MOD
	global P2Aaction P2Apoints P2Asuccess P2Aluck
	global jlimit plimit klimit ulimit glimit dlimit slimit

	set FIGHTINPROGRESS		""
	set CHALLENGETIMERID	""
	set CHALLENGECHAN		""
	set CURRENTROUND		""
	set ROUNDTIMERID		""
	set ROUNDWASIDLE		""
	
	set PLAYER1			""
	set PLA1COM			""
	set P1MTYPE			""
	set P1MNAME			""
	set P1FX			""
	set P1FXB			""
	set P1HEAMAX		""
	set P1HEAINI		""
	set P1HEAVIC		""
	set P1AFS			""
	set P1LVL			""
	set P1WIN			""
	set P1LOS			""
	set P1DRA			""
	set P1HEA			""
	set P1MOD			""
	
	set PLAYER2			""
	set PLA2COM			""
	set P2MTYPE			""
	set P2MNAME			""
	set P2FX			""
	set P2FXB			""
	set P2HEAMAX		""
	set P2HEAINI		""
	set P2HEAVIC		""
	set P2AFS			""
	set P2AFSwr	""
	set P2LVL			""
	set P2WIN			""
	set P2LOS			""
	set P2DRA			""
	set P2HEA			""
	set P2MOD			""
	
	set P2Aaction	""
	set P2Apoints	""
	set P2Asuccess	""
	set P2Aluck		""
	
	set jlimit ""
	set plimit ""
	set klimit ""
	set ulimit ""
	set glimit ""
	set dlimit ""
	set slimit ""
}

###
### initialize stats and health
###
###
proc initstat {player sname vname} {
	global PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA PLAYER2 P2AFS P2LVL P2WIN P2LOS P2DRA P2HEAVIC BOSSAFS
	if {($player == "boss")&&($sname == "mylvl")} {
		set tbfact [expr {(([rand 25]) * .01 ) + 1}]
		set P2LVL [expr {round ($P1LVL * $tbfact)}]
		set P2HEAVIC [expr {$P2LVL - $P1LVL}]
	} elseif {($player == "boss")&&($sname == "myafs")} {
		set $vname $BOSSAFS
	} else {
		set tempvalue [getuser $player XTRA $sname]
		if {$sname == "myafs"} {
			if {$tempvalue == ""} {
				set $vname "none"
			} else {
				set $vname $tempvalue
			}
		} elseif {$sname == "mylvl"} {
			if {$tempvalue == ""} {
				set $vname "10"
			} else {
				set $vname $tempvalue
			}
		} else {
			if {$tempvalue == ""} {
				set $vname "0"
			} else {
				set $vname $tempvalue
			}
		}
	}
}
proc inithealth {pxnum pxlvl} {
	global P1HEA P2HEA P1HEAINI P2HEAINI P1HEAMAX P2HEAMAX P1HEAVIC P2HEAVIC PLAYER2
	set pxhea ""
	if {($pxlvl == "")||($pxlvl == "0")} {
		set pxhea 10
	} else {
		set pxhea $pxlvl
	}
	if {$pxnum == 1 } {
		set P1HEAMAX [expr {$pxhea * .55}]
		set P1HEAINI $pxhea
		set P1HEA $pxhea
		if {($PLAYER2 != "boss")} {
			set P2HEAVIC [expr {$P1HEAINI * .10}]
		}
	} elseif {$pxnum == 2 } {
		set P2HEAMAX [expr {$pxhea * .55}]
		set P2HEAINI $pxhea
		set P2HEA $pxhea
		set P1HEAVIC [expr {$P2HEAINI * .10}]
	} else {
			formatoutput error "$PLAYER1 $CHALLENGECHAN {an error occured calculating healths.}"
	}
}

#########################################################################################################################
### game-time
###

###
### !fight <nick>
###  initiate a challenge
###
proc fightM {nick host handle chan text} {
	global FIGHTINPROGRESS CHALLENGETIMERID CURRENTROUND CHALLENGESECS CHALLENGECHAN PLAYER1 PLAYER2 P1AFS P2AFS
	if {($FIGHTINPROGRESS == 0)||($FIGHTINPROGRESS == "")} {
		set PLAYER1 $nick
		set PLAYER2 [lindex $text 0]
		set lnick [string tolower $nick]
		set lPLAYER2 [string tolower $PLAYER2]
		set optional [lindex $text 1]
		if {$lPLAYER2 == ""} {
			formatoutput sorry "$PLAYER1 $chan {you did not specify an opponent.}"
		} elseif {$lPLAYER2 == $lnick} {
			formatoutput sorry "$PLAYER1 $chan {you can not fight yourself.}"
		} elseif {([validuser $PLAYER1])&&([validuser $PLAYER2])&&($lPLAYER2 != "boss")} {
			set P1AFS [getuser $PLAYER1 XTRA myafs]
			set P2AFS [getuser $PLAYER2 XTRA myafs]
			if {([onchan $PLAYER2 $chan]) && ($PLAYER2 != "boss")} {
				if {($P2AFS == "none")||($P2AFS == "")||($optional == "noauto")} {
					set CHALLENGECHAN $chan
					set FIGHTINPROGRESS 1
					formatoutput challenge "$PLAYER1 $PLAYER2 $chan {$CHALLENGESECS noAF}"
					set CHALLENGETIMERID [utimer $CHALLENGESECS challengefailA]
				} else {
					set CHALLENGECHAN $chan
					set FIGHTINPROGRESS 1
					formatoutput challenge "$PLAYER1 $PLAYER2 $chan {$CHALLENGESECS thenAF}"
					set CHALLENGETIMERID [utimer $CHALLENGESECS {challengepass 1}]
				}
			} else {	;# p2 isn't onchan
				if {(($P2AFS != "none")&&($P2AFS != ""))&&($optional != "noauto")} {
					set CHALLENGECHAN $chan
					set FIGHTINPROGRESS 3
					formatoutput challenge "$PLAYER1 $PLAYER2 $chan {null doAF}"
					challengepass 1
				} elseif {(($P2AFS == "none")||($P2AFS == ""))||($optional != "noauto")} {
					formatoutput sorry "$PLAYER1 $chan {$PLAYER2 is neither here nor an autofighter.}"
				} else {
					formatoutput sorry "$PLAYER1 $chan {$PLAYER2 is not here.}"
				}
			}
		} elseif {($PLAYER2 == "boss")&&($optional != "noauto")} {
			set CHALLENGECHAN $chan
			set FIGHTINPROGRESS 3
			formatoutput challenge "$PLAYER1 $PLAYER2 $chan {null doAF}"
			challengepass 1
		} elseif {($PLAYER2 == "boss")&&($optional == "noauto")} { 
			formatoutput sorry "$PLAYER1 $chan {$PLAYER2 can only autofight.}"
		} elseif {[validuser $PLAYER1]} {
			formatoutput error "$PLAYER1 $chan {i don't know who \"$PLAYER2\" is.}"
		} else {
			formatoutput stranger "$PLAYER1 $chan"
		}
	} elseif {$FIGHTINPROGRESS == 1} {
		set lnick "[string tolower $nick]"
		set lPLAYER2 "[string tolower $PLAYER2]"
		if {($lPLAYER2 == $lnick)&&($CHALLENGECHAN == $chan)} {
			killutimer $CHALLENGETIMERID
			challengepass 2
		} elseif {($lPLAYER2 == $lnick)&&($CHALLENGECHAN != $chan)} {
			formatoutput sorry "$nick $chan {the challenge was issued in $CHALLENGECHAN.}"
		} elseif {$lPLAYER2 != $lnick} {
			formatoutput sorry "$nick $chan {there is a challenge pending ($PLAYER1 vs. $PLAYER2).}"
		}
	} elseif {$FIGHTINPROGRESS == 2} {
			formatoutput sorry "$nick $chan {one fight at a time ($PLAYER1 vs. $PLAYER2).}"
	}
}

###
### pass or fail the challenge
###
###
proc challengefailA {} {
	global FIGHTINPROGRESS PLAYER1 PLAYER2 CHALLENGECHAN
	formatoutput sorry "$PLAYER1 $CHALLENGECHAN {$PLAYER2 did not accept the challenge.}"
	freset $PLAYER1
	set FIGHTINPROGRESS 0	
}
proc challengepass {fOOT} {
	global FIGHTINPROGRESS FONEORTWO
	set FIGHTINPROGRESS 0
	set FONEORTWO $fOOT
	startfight $FONEORTWO
}

###
### start the fight
###  either by accepting challenge or autofight
###
proc startfight {X} {
	global FMTNAMESTYLE
	global FIGHTINPROGRESS CHALLENGECHAN CURRENTROUND ROUNDTIMERID ROUNDLENGSECS
	global PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA P1HEA PLAYER2 P2AFS P2LVL P2WIN P2LOS P2DRA P2HEA

	initstat $PLAYER1 mylvl P1LVL
	initstat $PLAYER1 mywin P1WIN
	initstat $PLAYER1 mylos P1LOS
	initstat $PLAYER1 mydra P1DRA
	initstat $PLAYER1 myafs P1AFS
	initstat $PLAYER2 mylvl P2LVL
	initstat $PLAYER2 mywin P2WIN
	initstat $PLAYER2 mylos P2LOS
	initstat $PLAYER2 mydra P2DRA
	initstat $PLAYER2 myafs P2AFS
	inithealth 1 $P1LVL
	inithealth 2 $P2LVL

	set CURRENTROUND "1"

	if {$X == 1} {
		set FIGHTINPROGRESS 3
		set tmyout ""
		append tmyout $FMTNAMESTYLE "auto fight!" $FMTNAMESTYLE " auto fight!"
		formatoutput simple "$PLAYER1 $CHALLENGECHAN {$tmyout}"
		formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $P1LVL null $P1WIN null $P1LOS null $P1DRA null} {vs} {$PLAYER2 $P2LVL null $P2WIN null $P2LOS null $P2DRA null $P2AFS}"
	} elseif {$X == 2} {
		set FIGHTINPROGRESS 2
		set tmyout ""
		append tmyout $FMTNAMESTYLE "fight!" $FMTNAMESTYLE " fight fight!"
		formatoutput simple "$PLAYER1 $CHALLENGECHAN {$tmyout}"
		formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $P1LVL null $P1WIN null $P1LOS null $P1DRA null} {vs} {$PLAYER2 $P2LVL null $P2WIN null $P2LOS null $P2DRA null null}"
	} else {
		formatoutput error "$PLAYER1 $CHALLENGECHAN {counting the starting players.}"
		freset $PLAYER1
	}
	formatoutput roundcmd "$CHALLENGECHAN $CURRENTROUND {{[actionlookup all 0]}}"
	set ROUNDTIMERID [utimer $ROUNDLENGSECS startnextturn ]
}

###
###	start next turn
###	 called from timers; this is where most of the magic happens, or is called to happen
###
proc startnextturn {} {
	global FIGHTINPROGRESS CHALLENGECHAN CURRENTROUND ROUNDTIMERID ROUNDLENGSECS 
	global PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA P1HEA P1HEAMAX P1HEAINI P1HEAVIC P1FX P1FXB
	global PLAYER2 P2AFS P2LVL P2WIN P2LOS P2DRA P2HEA P2HEAMAX P2HEAINI P2HEAVIC P2FX P2FXB P2AFSwr
	global ROUNDWASIDLE P1MOD P2MOD PLA1COM P1MNAME P1MTYPE PLA2COM P2MNAME P2MTYPE FONEORTWO
	global FMTCOLOROFF FMTNAMECOLOR FMTNAMESTYLE
	set p1heanew ""
	set p2heanew ""
	if {($FONEORTWO == "2")&&($PLA1COM == "")&&($PLA2COM == "")} {
		formatoutput simple "$PLAYER1 $CHALLENGECHAN {the fight has timed out.}"
		freset $PLAYER1
	} else {
		if {$P1FX  == ""} { set P1FX  "0" }
		if {$P1FXB == ""} { set P1FXB "0" }
		if {$P2FX  == ""} { set P2FX  "0" }
		if {$P2FXB == ""} { set P2FXB "0" }


		if {$P1MTYPE == ""} { set P1MTYPE "non" }
		if {$P2MTYPE == ""} { set P2MTYPE "non" }

		set tp1fx ""
		set tp2fx ""
		set P1FXSUM ""
		set P2FXSUM ""
		
		set p1outcome ""
		set p2outcome ""

		set p1luper ""
		set p2luper ""

##### DAMAGE TO P1'S SELF #####
		if {$P1MTYPE == "off"} {
			if {$P1FX != "0"} {set p1ocper [expr {round(($P1FX / $P2HEAINI) * 100)}] } else { set p1ocper "0"}
			set p1ocper [append p1ocper "%"]
			set p1outcome "$PLAYER1's $P1MNAME"
			if {($P1MOD == "lucky")} {
				if {$P1FXB != "0"} { set p1luper [expr {round(($P1FXB / $P2HEAINI) * 100)}] } else { set p1luper "0"}
				if {$p1luper > 0} {
					set p1luper [append p1luper "%"]
					set p1outcome "$p1outcome caused $p1ocper damage (+lucky strike $p1luper),"
				} else {
					set p1outcome "$p1outcome caused $p1ocper damage,"
				}
			} elseif {($P1MOD == "missed")} {
				set p1outcome "$p1outcome missed,"
			} else {
				set p1outcome "$p1outcome caused $p1ocper damage,"
			}
		} elseif {($P1MTYPE == "sui")} {
			if {($P1MOD == "lucky")} {
				if {$P1FXB != "0"} { set p1luper [expr {round(($P1FXB / $P2HEAINI) * 100)}] } else { set p1luper "0"}
				set p1luper [append p1luper "%"]
				set p1outcome "$p1outcome $PLAYER1's $P1MNAME caused $p1luper damage (+lucky strike $p1luper),"
			} else {
				set p1outcome "$p1outcome $PLAYER1 committed suicide,"
			}
		} elseif {$P1MTYPE == "def"} {
			if {(($P2MTYPE == "def")&&($P2MOD != "lucky"))||(($P2MNAME == "suicide")&&($P2MOD != "lucky"))} {
				set p1deper "100"
			} elseif {($P1FX != "0")&&($P2FX != "0")} {set p1deper [expr {round(($P1FX / $P1HEAINI) * 100)}] } else { set p1deper "0"}
			set p1deper [append p1deper "%"]
			set p1outcome "$PLAYER1's $P1MNAME"
			if {($P1MOD == "lucky")} {
				if {$P1FXB != "0"} { set p1luper [expr {round(($P1FXB / $P2HEAINI) * 100)}] } else { set p1luper "0"}
				if {$p1luper > 0} {
					set p1luper [append p1luper "%"]
					set p1outcome "$p1outcome deflected $p1deper damage (+lucky strike $p1luper),"
				} else {
					set p1outcome "$p1outcome deflected $p1deper damage,"
				}
			} elseif {($P1MOD == "missed")} {
				set p1outcome "$p1outcome missed,"
			} else {
				set p1outcome "$p1outcome deflected $p1deper damage,"
			}
		} else {
			set p1outcome "$PLAYER1 did nothing,"
			if {($FONEORTWO == "1")} {
				calcaction $PLAYER1 non
				fightauto
			}
		}

##### DAMAGE TO P2'S SELF #####
		if {$P2MTYPE == "off"} {
			if {$P2FX != "0"} {set p2ocper [expr {round(($P2FX / $P1HEAINI) * 100)}] } else { set p2ocper "0"}
			set p2ocper [append p2ocper "%"]
			set p2outcome "$PLAYER2's $P2MNAME"
			if {($P2MOD == "lucky")} {
				if {$P2FXB != "0"} { set p2luper [expr {round(($P2FXB / $P1HEAINI) * 100)}] } else { set p2luper "0"}
				if {$p2luper > 0} {
					set p2luper [append p2luper "%"]
					set p2outcome "$p2outcome caused $p2ocper damage (+lucky strike $p2luper)."
				} else {
					set p2outcome "$p2outcome caused $p2ocper damage."
				}
			} elseif {($P2MOD == "missed")} {
				set p2outcome "$p2outcome missed."
			} else {
				set p2outcome "$p2outcome caused $p2ocper damage."
			}
		} elseif {($P2MTYPE == "sui")} {
			if {($P2MOD == "lucky")} {
				if {$P2FXB != "0"} { set p2luper [expr {round(($P2FXB / $P1HEAINI) * 100)}] } else { set p2luper "0"}
				set p2luper [append p2luper "%"]
				set p2outcome "$p2outcome $PLAYER2's $P2MNAME caused $p2luper damage (+lucky strike $p2luper)."
			} else {
				set p2outcome "$p2outcome $PLAYER2 committed suicide."
			}
		} elseif {$P2MTYPE == "def"} {
			if {(($P1MTYPE == "def")&&($P1MOD != "lucky"))||(($P1MNAME == "suicide")&&($P1MOD != "lucky"))} {
				set p2deper "100"
			} elseif {($P2FX != "0")&&($P1FX != "0")} { set p2deper [expr {round(($P2FX / $P2HEAINI) * 100)}] } else { set p2deper "0"}
			set p2deper [append p2deper "%"]
			set p2outcome "$PLAYER2's $P2MNAME"
			if {($P2MOD == "lucky")} {
				if {$P2FXB != "0"} { set p2luper [expr {round(($P2FXB / $P1HEAINI) * 100)}] } else { set p2luper "0"}
				if {$p2luper > 0} {
					set p2luper [append p2luper "%"]
					set p2outcome "$p2outcome deflected $p2deper damage (+lucky strike $p2luper)."
				} else {
					set p2outcome "$p2outcome deflected $p2deper damage."
				}
			} elseif {($P2MOD == "missed")} {
				set p2outcome "$p2outcome missed."
			} else {
				set p2outcome "$p2outcome deflected $p2deper damage."
			}
		} else {
			set p2outcome "$PLAYER2 did nothing."
		}
		formatoutput simple "$PLAYER1 $CHALLENGECHAN {$p1outcome and $p2outcome}"



##### RESULTS FOR P1 #####
		if {
			($P1MTYPE != "sui")&&
			(($P2MNAME == "")||($P2MOD == "missed"))||
			(($P2MTYPE == "def")&&($P2MOD != "lucky"))
			} {
			### if u didn't suicide, they did nothing or missed, or their defense was unlucky, it didn't hurt
			set p1heanew "$P1HEA"
		} elseif {
			($P2MTYPE != "def")||
			(($P2MTYPE == "def")&&($P2MOD == "lucky"))||
			(($P2MTYPE == "sui")&&($P2MOD == "lucky"))||
			($P1MTYPE == "sui")} {
			### ur due for a successful offensive, lucky defensive, lucky suicide, or ur own suicide
			### in other words something happened that will cause u harm
			if {($P1MTYPE == "def")&&($P1MOD != "missed")} {
				### if ur defenseive move didn't miss, reduce their successful effectiveness
				if {$P1FX >= $P2FX} {	;# if urs is bigger, nullify theirs
					set tp2fx "0"
				} else {				;# otherwise reduce their effectiveness
					set tp2fx "[expr {$P2FX - $P1FX}]"
				}
			} elseif {($P2MOD == "missed")} {
				### if theirs missed, don't hurt urself
				set tp2fx "0"
			} else {
				### no defensive effect
				set tp2fx "$P2FX"
			}
			set P2FXSUM "[expr {$tp2fx + $P2FXB}]"
			if {(($P2MTYPE == "off")&&($P1HEA <= $P2FXSUM))||
				((($P2MTYPE == "def")&&($P2MOD == "lucky"))&&($P1HEA <= $P2FXB))||
				($P1MTYPE == "sui")} {
				set p1heanew "0"
				set FIGHTINPROGRESS "0"
				set toutput ""
				set toutput [append toutput $FMTNAMESTYLE $PLAYER1 $FMTNAMESTYLE " is KO!"]
				formatoutput simplecolr "$PLAYER1 $CHALLENGECHAN {$toutput} $FMTNAMECOLOR"
###	PLAYER ONE IS DEAD!!!
			} else {
				### at this point u can honestly and safely do ur own math, cuz it won't kill u
				if {(($P2MTYPE == "def")&&($P2MOD == "lucky"))} {
					### but if theirs was a lucky defensive, do it special
					set p1heanew "[expr {$P1HEA - $P2FXB}]"
				} elseif {(($P2MTYPE == "def")&&($P2MOD != "lucky"))} {
					### if their defensive was not lucky, don't affect urself
					set p1heanew "$P1HEA"
				} else {
					set p1heanew "[expr {$P1HEA - $tp2fx - $P2FXB}]"
				}
			}
		}


##### RESULTS FOR P2 #####
		if {
			($P2MTYPE != "sui")&&
			(($P1MNAME == "")||($P1MOD == "missed"))||
			(($P1MTYPE == "def")&&($P1MOD != "lucky"))
			} {
			set p2heanew "$P2HEA"
		} elseif {
			($P1MTYPE != "def")||
			(($P1MTYPE == "def")&&($P1MOD == "lucky"))||
			(($P1MTYPE == "sui")&&($P1MOD == "lucky"))||
			($P2MTYPE == "sui")} {
			if {($P2MTYPE == "def")&&($P2MOD != "missed")} {
				if {$P2FX >= $P1FX} {
					set tp1fx "0"
				} else {
					set tp1fx "[expr {$P1FX - $P2FX}]"
				}
			} elseif {($P1MOD == "missed")} {
				### if theirs missed, don't hurt urself
				set tp1fx "0"
			} else {
				set tp1fx "$P1FX"
			}
			set P1FXSUM "[expr {$tp1fx + $P1FXB}]"
			if {(($P1MTYPE == "off")&&($P2HEA <= $P1FXSUM))||
				((($P1MTYPE == "def")&&($P1MOD == "lucky"))&&($P2HEA <= $P1FXB))||
				($P2MTYPE == "sui")} {
				set p2heanew "0"
				set FIGHTINPROGRESS "0"
				set toutput ""
				set toutput [append toutput $FMTNAMESTYLE $PLAYER2 $FMTNAMESTYLE " is KO!"]
				formatoutput simplecolr "$PLAYER1 $CHALLENGECHAN {$toutput} $FMTNAMECOLOR"
###	PLAYER TWO IS DEAD!!!
			} else {
				if {(($P1MTYPE == "def")&&($P1MOD == "lucky"))} {
					set p2heanew "[expr {$P2HEA - $P1FXB}]"
				} elseif {(($P1MTYPE == "def")&&($P1MOD != "lucky"))} {
					set p2heanew "$P2HEA"
				} else {
					set p2heanew "[expr {$P2HEA - $tp1fx - $P1FXB}]"
				}
			}
		}



		if {($p1heanew == "0")||($p2heanew == "0")} {
		### STATSAVE HERE
			set mysout1 ""
			set mysout2 ""
			set mysdra1 ""
			set mysdra2 ""
			set myswin1 ""
			set myswin2 ""
			set myslos1 ""
			set myslos2 ""
			set myslvl1 ""
			set myslvl2 ""
			
			if {($FONEORTWO == 1)&&($P2AFSwr == "random")} {
				set P2AFS "random"
			}
			

##### OUTPUT REPORTING #####
			if {($p1heanew == "0")&&($p2heanew == "0")} {
			### p1 & p2 draw
				set mysdra1 [expr {$P1DRA + 1}]
				set mysdra2 [expr {$P2DRA + 1}]
				savestat $PLAYER1 mydra $mysdra1
				savestat $PLAYER2 mydra $mysdra2
				if {$PLAYER2 == "boss"} {
					formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $P1LVL null $P1WIN null $P1LOS null $mysdra1 diff} {tied against} {$PLAYER2 $P2LVL hide $P2WIN null $P2LOS null $mysdra2 diff $P2AFS}"
				} else {
					if {$FONEORTWO == 1 } {
						formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $P1LVL null $P1WIN null $P1LOS null $mysdra1 diff} {tied against} {$PLAYER2 $P2LVL null $P2WIN null $P2LOS null $mysdra2 diff $P2AFS}"
					} elseif {$FONEORTWO == 2} {
						formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $P1LVL null $P1WIN null $P1LOS null $mysdra1 diff} {tied against} {$PLAYER2 $P2LVL null $P2WIN null $P2LOS null $mysdra2 diff null}"
					} else {
						foutputsorry $PLAYER1 "" $CHALLENGECHAN "an error occured counting players for the draw."
					}
				}
			} elseif {($p1heanew == "0")} {
			### p1 lose, p2 win
				set myslos1 [expr {$P1LOS + 1}]
				savestat $PLAYER1 mylos $myslos1
				set myswin2 [expr {$P2WIN + 1}]
				savestat $PLAYER2 mywin $myswin2
				set myhvic ""
				if {$PLAYER2 == "boss"} {
					set myslvl1 [expr {round($P1LVL - $P2HEAVIC)}]
					savestat $PLAYER1 mylvl $myslvl1
					set myhvic $P2HEAVIC
					formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $myslvl1 -$myhvic $P1WIN null $myslos1 diff $P1DRA null} {was defeated by} {$PLAYER2 $P2LVL hide $myswin2 diff $P2LOS null $P2DRA null $P2AFS}"
				} else {
					set myslvl2 [expr {round($P2LVL + $P2HEAVIC)}]
					savestat $PLAYER2 mylvl $myslvl2
					set myhvic $P2HEAVIC
					if {$FONEORTWO == 1 } {
						formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $P1LVL null $P1WIN null $myslos1 diff $P1DRA null} {was defeated by} {$PLAYER2 $myslvl2 +$myhvic $myswin2 diff $P2LOS null $P2DRA null $P2AFS}"
					} elseif {$FONEORTWO == 2} {
						formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $P1LVL null $P1WIN null $myslos1 diff $P1DRA null} {was defeated by} {$PLAYER2 $myslvl2 +$myhvic $myswin2 diff $P2LOS null $P2DRA null null}"
					} else {
						foutputsorry $PLAYER1 "" $CHALLENGECHAN "an error occured counting players, p1 lost/p2 won."
					}
				}
			} elseif {($p2heanew =="0")} {
			### p2 lose, p1 win
			set myswin1 [expr {$P1WIN + 1}]
			set myslos2 [expr {$P2LOS + 1}]
			set myslvl1 [expr {round($P1LVL + $P1HEAVIC)}]
				savestat $PLAYER1 mywin $myswin1
				savestat $PLAYER2 mylos $myslos2
				savestat $PLAYER1 mylvl $myslvl1
				set myhvic ""
				if {$PLAYER2 == "boss"} {
					set myhvic [expr {round ($P2HEAVIC)}]
					formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $myslvl1 +$myhvic $myswin1 diff $P1LOS null $P1DRA null} {was victorious against} {$PLAYER2 $P2LVL hide $P2WIN null $myslos2 diff $P2DRA null $P2AFS}"
				} else {
					set myhvic [expr {round ($P1HEAVIC)}]
					if {$FONEORTWO == 1 } {
						formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $myslvl1 +$myhvic $myswin1 diff $P1LOS null $P1DRA null} {was victorious against} {$PLAYER2 $P2LVL null $P2WIN null $myslos2 diff $P2DRA null $P2AFS}"
					} elseif {$FONEORTWO == 2} {
						formatoutput turnstat "$CHALLENGECHAN {$PLAYER1 $myslvl1 +$myhvic $myswin1 diff $P1LOS null $P1DRA null} {was victorious against} {$PLAYER2 $P2LVL null $P2WIN null $myslos2 diff $P2DRA null null}"
					} else {
						foutputsorry $PLAYER1 "" $CHALLENGECHAN "an error occured counting the players, p1 won/p2 lost."
					}
				}
			}
			freset $PLAYER1
		} else {
			set p1heaper [expr {round($p1heanew / $P1HEAINI * 100)}]
			set p2heaper [expr {round($p2heanew / $P2HEAINI * 100)}]


			incr CURRENTROUND
			if {$FONEORTWO == 1 } {
				formatoutput turnsimple "$CHALLENGECHAN {$PLAYER1 $p1heaper} {$PLAYER2 $p2heaper $P2AFS}"
			} elseif {$FONEORTWO == 2} {
				formatoutput turnsimple "$CHALLENGECHAN {$PLAYER1 $p1heaper} {$PLAYER2 $p2heaper null}"
			} else {
				foutputsorry $PLAYER1 "" $CHALLENGECHAN "an error occured counting the players between rounds."
				freset $PLAYER1
			}
			formatoutput roundcmd "$CHALLENGECHAN $CURRENTROUND {{[actionlookup all 1]}}"
			set P1HEA "$p1heanew"
			set P2HEA "$p2heanew"
			set PLA1COM ""
			set P1MNAME ""
			set P1MTYPE ""
			set PLA2COM ""
			set P2MNAME ""
			set P2MTYPE ""
			set ROUNDTIMERID [utimer $ROUNDLENGSECS startnextturn ]
		}
	}
}


###
###	fightaction: triggered from the different bind'ed user fighting commands
###  makes sure the right person is trying to fight at the right time, and advances the game
###
proc fightaction {nick chan action} {
	global FMTSTATSTYLE
	global PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA P1HEA P1HEAINI P1HEAMAX P1MOD P1FX P1FXB
	global PLAYER2 P2AFS P2LVL P2WIN P2LOS P2DRA P2HEA P2HEAINI P2HEAMAX P2MOD P2FX P2FXB
	global FONEORTWO FIGHTINPROGRESS CHALLENGECHAN CHALLENGETIMERID ROUNDTIMERID PLA1COM P1MNAME P1MTYPE PLA2COM P2MNAME P2MTYPE

	set lnick "[string tolower $nick]"
	set lPLAYER1 "[string tolower $PLAYER1]"
	set lPLAYER2 "[string tolower $PLAYER2]"
	if {$FIGHTINPROGRESS == 2} {
		if {$lnick == $lPLAYER1} {
			set PLA1COM $action
			if {$PLA2COM == ""} {
				calcaction $nick $action
				formatoutput simple "$PLAYER1 $CHALLENGECHAN {$PLAYER1 is going to $P1MNAME, $PLAYER2 has <$FMTSTATSTYLE[lindex [utimers] {0 0}]$FMTSTATSTYLE secs to decide.}"
			} else {
				killutimer $ROUNDTIMERID
				calcaction $nick $action
				startnextturn
			}
		} elseif {$lnick == $lPLAYER2} {
			set PLA2COM $action
			if {$PLA1COM == ""} {
				calcaction $nick $action
				formatoutput simple "$PLAYER2 $CHALLENGECHAN {$PLAYER2 is going to $P2MNAME, $PLAYER1 has <$FMTSTATSTYLE[lindex [utimers] {0 0}]$FMTSTATSTYLE secs to decide.}"
			} else {
				killutimer $ROUNDTIMERID
				calcaction $nick $action
				startnextturn
			}
		} else {
			formatoutput sorry "$nick $chan {only 2 peopl to a fight ($PLAYER1 vs. $PLAYER2).}"
		}
	} elseif {$FIGHTINPROGRESS == 3} {
		if {$lnick == $lPLAYER1} {
			killutimer $ROUNDTIMERID
			set PLA1COM $action
			calcaction $nick $action
			fightauto
			calcaction $PLAYER2 $PLA2COM
			startnextturn
		} else {
			formatoutput sorry "$nick $chan {this is not your autofight ($PLAYER1 vs. $PLAYER2).}"
		}
	} elseif {$FIGHTINPROGRESS == 1} {
		if {$lnick == $lPLAYER1} {
			formatoutput sorry "$nick $chan {the fight hasn't started, $PLAYER2 hasn't accepted the challenge.}"
		} elseif {$lnick == $lPLAYER2} {
			killutimer $CHALLENGETIMERID
			set FIGHTINPROGRESS 0
			set FONEORTWO 2
			startfight $FONEORTWO
			set PLA2COM $action
			calcaction $nick $action
			formatoutput simple "$PLAYER2 $CHALLENGECHAN {$PLAYER2 is going to $P2MNAME, $PLAYER1 has <$FMTSTATSTYLE[lindex [utimers] {0 0}]$FMTSTATSTYLE secs to decide.}"
		}
	} elseif {([validuser $nick])} {
		formatoutput sorry "$nick $chan {you need to start a fight.}"
	}
}

###
###	calcaction: called within fightaction
###  to determine the value of ur move, if it was lucky, and if it missed
###
proc calcaction {nick actionid} {
	global PLAYER1 P1MOD P1FX P1FXB P1MTYPE P1MNAME P1HEAINI
	global PLAYER2 P2MOD P2FX P2FXB P2MTYPE P2MNAME P2HEAINI
	set THEMOD ""
	set THEFX "0"
	set THEFXB "0"
	set vsuccess ""
	set rpoints ""
	set vpoints ""
	set lnick [string tolower $nick]
	set lPLAYER1 [string tolower $PLAYER1]
	set lPLAYER2 [string tolower $PLAYER2]

	set taname	""
	set tatype	""
	set points	""
	set success	""
	set luck	""

	if {$actionid == "non"} {
		set taname	""
		set tatype	"non"
		set vsuccess "0"
		set vpoints "0"
		set THEMOD ""
	} else {
		set taname	[actionlookup $actionid 0]
		set tatype	[actionlookup $actionid 2]
		set points	[actionlookup $actionid 3]
		set success	[actionlookup $actionid 4]
		set luck	[actionlookup $actionid 5]
		if {[rand 100] <= $success} {
			set vsuccess "1"
			set rpoints [rand $points]
			set rptsthr [expr {round ($points * .33)}]
			if {$rpoints < $rptsthr} {
				set vpoints $rptsthr
			} else {
				set vpoints $rpoints
			}
			if {[rand 100] <= $luck} {
				set THEMOD "lucky"
				set THEFXB [expr {$vpoints * (([rand 4] +1) * .1)}]
			} else {
				set THEMOD ""
			}
		} else {
			set vsuccess "0"
			set vpoints "0"
			set THEMOD "missed"
		}
	}

	set THEFX $vpoints

	if {$lnick == $lPLAYER1} {
		if {$THEMOD == "missed"} {
			set P1FX "0"
			set P1FXB "0"
		} elseif {$tatype == "off"} {
			set P1FX [expr {$P2HEAINI * ($THEFX * .01)}]
			set P1FXB [expr {$P2HEAINI * ($THEFXB * .01)}]
		} elseif {$tatype == "def"} {
			set P1FX [expr {$P1HEAINI * ($THEFX * .01)}]
			set P1FXB [expr {$P1HEAINI * ($THEFXB * .01)}]
		}
		set P1MOD $THEMOD
		set P1MTYPE $tatype
		set P1MNAME $taname
	} elseif {$lnick == $lPLAYER2} {
		if {$THEMOD == "missed"} {
			set P2FX "0"
			set P2FXB "0"
		} elseif {$tatype == "off"} {
			set P2FX [expr {$P1HEAINI * ($THEFX * .01)}]
			set P2FXB [expr {$P1HEAINI * ($THEFXB * .01)}]
		} elseif {$tatype == "def"} {
			set P2FX [expr {$P2HEAINI * ($THEFX * .01)}]
			set P2FXB [expr {$P2HEAINI * ($THEFXB * .01)}]
		}
		set P2MOD $THEMOD
		set P2MTYPE $tatype
		set P2MNAME $taname
	}
}

###
### fightauto: choose a move on behalf of player 2
###		called at the end of an autofight turn
###
proc fightauto {} {
	global P1MNAME P2MNAME P2MTYPE
	global PLAYER2 PLA2COM P2AFS P2AFSwr

	set autoaidra "[rand 99]"
	set autoactid "[expr {$autoaidra + 1}]"

	set THEAID ""
	set jlimit ""
	set plimit ""
	set klimit ""
	set ulimit ""
	set glimit ""
	set dlimit ""
	set slimit ""

	if {$P2AFS == "random"} {
		set P2AFSwr "random"
		set p2afsrand "[rand 4]"
		if {$p2afsrand < 1} {
			set P2AFS "psycho"
		} elseif {($p2afsrand >= 1)&&($p2afsrand < 2)} {
			set P2AFS "agro"
		} elseif {($p2afsrand >= 2)&&($p2afsrand < 3)} {
			set P2AFS "mello"
		} elseif {$p2afsrand >= 3} {
			set P2AFS "safe"
		}
	}
	if {$P2AFS == "psycho"} {
# 15 13 15 20 10 20 7
		set jlimit "15"
		set plimit "28"
		set klimit "43"
		set ulimit "63"
		set glimit "73"
		set dlimit "93"
		set slimit "100"
	} elseif {$P2AFS == "agro"} {
# 21 21 21 20 8 8 1
		set jlimit "21"
		set plimit "42"
		set klimit "63"
		set ulimit "83"
		set glimit "91"
		set dlimit "99"
		set slimit "100"
	} elseif {$P2AFS == "mello"} {
# 35 15 5 1 35 8 1
		set jlimit "35"
		set plimit "50"
		set klimit "55"
		set ulimit "56"
		set glimit "91"
		set dlimit "99"
		set slimit "100"
	} elseif {$P2AFS == "safe"} {
# 33 10 5 1 33 17 1
		set jlimit "33"
		set plimit "43"
		set klimit "48"
		set ulimit "49"
		set glimit "82"
		set dlimit "99"
		set slimit "100"
	}

	if {$autoactid < $jlimit} {										set THEAID		"0"
	} elseif {($autoactid >= $jlimit)&&($autoactid < $plimit)} {	set THEAID		"1"
	} elseif {($autoactid >= $plimit)&&($autoactid < $klimit)} {	set THEAID		"2"
	} elseif {($autoactid >= $klimit)&&($autoactid < $ulimit)} {	set THEAID		"3"
	} elseif {($autoactid >= $ulimit)&&($autoactid < $glimit)} {	set THEAID		"4"
	} elseif {($autoactid >= $glimit)&&($autoactid < $dlimit)} {	set THEAID		"5"
	} elseif {($autoactid >= $dlimit)} {							set THEAID		"6"
	}

	set PLA2COM $THEAID
}

#########################################################################################################################
### action points
###
### points	- max attack % possible
### success	- % chance of not missing
### luck	- % chance of lucky strike
###
proc actionlookup {actionid actionix} {

	set action(0) {	jab			fj	off	20	85	33	}
	set action(1) {	punch		fp	off	40	70	20	}
	set action(2) {	kick		fk	off	60	55	15	}
	set action(3) {	uppercut	fu	off	90	40	10	}
	set action(4) {	guard		fg	def	75	99	33	}
	set action(5) {	dodge		fd	def	99	75	50	}
	set action(6) {	suicide		fs	sui	66	66	66	}

	if {$actionid == "all"} {
		if {$actionix == ""} {set $actionix 0}
		set myout " "
		for {set i 0} {$i < [array size action]} {incr i} {
			append myout [lindex $action($i) $actionix] " "
		}
	} else {
		append myout [lindex $action($actionid) $actionix]
	}
	return $myout
}

proc fightjab {nick host handle chan text} {
	fightaction $nick $chan 0
}
proc fightpunch {nick host handle chan text} {
	fightaction $nick $chan 1
}
proc fightkick {nick host handle chan text} {
	fightaction $nick $chan 2
}
proc fightuppercut {nick host handle chan text} {
	fightaction $nick $chan 3
}
proc fightguard {nick host handle chan text} {
	fightaction $nick $chan 4
}
proc fightdodge {nick host handle chan text} {
	fightaction $nick $chan 5
}
proc fightsuicide {nick host handle chan text} {
	fightaction $nick $chan 6
}


#########################################################################################################################
### binds
###

bind pub - !fight		fightM

bind pub - !jab			fightjab
bind pub - !fj			fightjab
bind pub - !punch		fightpunch
bind pub - !fp			fightpunch
bind pub - !kick		fightkick
bind pub - !fk			fightkick
bind pub - !uppercut	fightuppercut
bind pub - !fu			fightuppercut
bind pub - !guard		fightguard
bind pub - !fg			fightguard
bind pub - !dodge		fightdodge
bind pub - !fd			fightdodge
bind pub - !suicide		fightsuicide
bind pub - !fs			fightsuicide

bind pub - !fstat		fstat
bind msg - fstat		fstatmsg
bind pub - !fauto		fauto
bind msg - fauto		fautomsg

bind pub - !fversion	versioninfo
bind pub - !fv			versioninfo
bind pub o !fdebug		fdebug
bind msg o fdebug		fdebugmsg
bind pub o !freset		fresetmanual
bind msg o freset		fresetmanualmsg

bind pub - !fhelp		fhelp
bind msg - fhelp		fhelpmsg

bind pub - !fhis		fhis
bind msg - fhis			fhismsg

#########################################################################################################################
### save stats
###
proc savestat {player sname vname} {
	global PLAYER1 P1AFS P1LVL P1WIN P1LOS P1DRA PLAYER2 P2AFS P2LVL P2WIN P2LOS P2DRA
	setuser $player XTRA $sname $vname
}	



#########################################################################################################################
### end: script loaded
###

initglobalvars
putlog "dFight $myversion loaded"