//------------------------------BAT CODE

action BATSLEEPDYING 27 4 1 1 10
action BATSLEEPBURNING -264 8 1 1 10
action BATSLEEPBURNED -256 1 1 1 1

eventloadactor BATSLEEP 
setactor[THISACTOR].xrepeat 35
setactor[THISACTOR].yrepeat 35

setactor[THISACTOR].extra BATSTRENGTH

enda

spriteshadow BATSLEEP
spritenoshade BATSLEEP
useractor notenemy BATSLEEP WEAK sizeat 35 35
setactor[THISACTOR].clipdist 40
ifvare VISION 1 { setactor[THISACTOR].shade -127 } 
getplayer[THISACTOR].i PLAYERID
getactorvar[PLAYERID].invisible invisible
ifvarn invisible 1 
{
ifvare peractor2 0 { /*addvar TOTALKILLS 1*/ setvar peractor2 1 }
ifaction NO { ifcansee ifpdistl 8192 ifcount 16 { soundonce BATSPOT espawn BAT setactorvar[RETURN].settotalkill 1 killit } } }
ifhitweapon 
{ 
	action BATSLEEPDYING
	ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 
}
getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	action BATSLEEPDYING
	ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 
	setactorvar[THISACTOR].voodoohitenemy 0
}
ifaction BATSLEEPDYING { fall ifactioncount 4 { /*addkills 1*/ killit } }
ifvarg flamedamage 0 ifvare peractor 0 { action BATSLEEPBURNING setvar peractor 1 }
ifaction BATSLEEPBURNING { fall ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 ifactioncount 8 { /*addkills 1*/ action BATSLEEPBURNED break } }
enda

action ABAT   0  4  5  1  8
action ABATDYING 25 4 1 1 10
action ABATBURNING -266 8 1 1 10
action ABATBURNED -258 1 1 1 1

move BATFOWARD 150
move BATFIND 80
move BATDOWN 150 80
move BATUP 150 -100

ai AIBATFOWARD ABAT BATFOWARD faceplayer
ai AIBATFIND ABAT BATFIND randomangle
ai AIBATDOWN ABAT BATDOWN randomangle getv
ai AIBATUP ABAT BATUP randomangle getv
ai AIBATDYING ABATDYING BATFOWARD faceplayer
ai AIBATBURNING ABATBURNING BATFOWARD faceplayer
ai AIBATBURNED ABATBURNED BATFOWARD

spriteshadow BAT
spritenoshade BAT
useractor notenemy BAT BATSTRENGTH
setactor[THISACTOR].clipdist 40
ifvare VISION 1 { setactor[THISACTOR].shade -127 }
getplayer[THISACTOR].i PLAYERID

getactorvar[THISACTOR].settotalkill settotalkill
ifai NO { /*ifvarn settotalkill 1 { addvar TOTALKILLS 1 }*/ cstat 256 sizeat 30 30 strength BATSTRENGTH ai AIBATFOWARD }
ifhitweapon { ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3  ai AIBATDYING }
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1
ifvarn invisible 1 
{
	ifp palive
	{
		ifai AIBATFOWARD ifcansee { ifrnd 16 ai AIBATDOWN else ifrnd 16 { soundonce BATSPOT ai AIBATUP } }
		ifai AIBATDOWN { iffloordistl 8 { ai AIBATUP } ifpdistl 1024 { ai AIBATDOWN } else ifrnd 16 ai AIBATFOWARD }
		ifai AIBATUP { ifceilingdistl 8 { ai AIBATDOWN } ifpdistl 1024 { ai AIBATDOWN } else { ifp phigher ai AIBATUP else ifrnd 16 ai AIBATFOWARD } }
	} else ai AIBATFIND
	ifai AIBATFIND ifcansee ifp palive { soundonce BATSPOT ai AIBATFOWARD }
} else { ifai AIBATFOWARD { ai AIBATFIND } }

ifai AIBATDYING { fall ifactioncount 4 { /*addkills 1*/ killit } }

ifvarg flamedamage 0 { ifvare peractor 0 { ai AIBATBURNING setvar peractor 1 } }
ifai AIBATBURNING { fall ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 ifactioncount 8 { cstat 0 /*addkills 1*/ ai AIBATBURNED break } }

getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3  ai AIBATDYING
	setactorvar[THISACTOR].voodoohitenemy 0
}

enda