
setdefname bloodtc.def
setcfgname btc.cfg
setgamename BloodTC 1.0

define MAXPISTOLAMMO           100
define MAXSHOTGUNAMMO          100
define MAXCHAINGUNAMMO         500
define MAXRPGAMMO              100
define MAXHANDBOMBAMMO          50
define MAXSHRINKERAMMO         288
define MAXGROWAMMO              50
define MAXDEVISTATORAMMO       250
define MAXFREEZEAMMO           100
define MAXTRIPBOMBAMMO         100
define TRIPBOMBLASERMODE        0

define GRAVITATIONALCONSTANT 176

action PGROWING   7585
action PSTAND     7585   1   5   1  1
action PEXPLODE   6663   5  1  1  18
action PEXPLODEAD  6669   1   1
action PJPHOUVER  7602   1   5   1
action PWALK    7555   5   5   1   16
action PRUN     7555   5   5   1   10
action PWALKBACK  7570   4   5  -1   16
action PRUNBACK   7570   4   5  -1   10
action PJUMPING   7575   2   5   1   40
action PFALLING   7580   1   5
action PDUCKING   7632   1   5
action PCRAWLING  7632   3   5   1   20
action PAKICKING  7585   1   5   1   25
action PTHROWNBACK  7595  6   1   1   18
action PLYINGDEAD   7601  1   1

action PFATALITY 7656  1   1
action PFALL 7652  3 1 1 18
action PGETUP 7655  3 1 -1 18
action PDAMAGED 7657 6 1 1 18
action PDEAD  7663  1 1 1 1
action PDAMAGED2 7664 5 1 1 18
action PDEAD2 7669 1 1 1 1

action PSWIMMINGGO   7602   1   5   1   10
action PSWIMMING   7602   5   5   1   13
action PSWIMMINGWAIT 7602   1   5   1   13
action PTREDWATER  7602   2   5   1   17

include BloodTC/blcons/GAME.CON

include BloodTC/blcons/USERTC.CON
include BloodTC/blcons/DEFSTC.CON
include BloodTC/blcons/STATESTC.CON

include BloodTC/blcons/hud.con
include BloodTC/blcons/cheats.con
include BloodTC/blcons/weapons.con
include BloodTC/blcons/sprites.con
include BloodTC/blcons/monsters.con
include BloodTC/blcons/scripts.con
include BloodTC/blcons/particles.con

// New armors system

onevent EVENT_INCURDAMAGE

	getplayer[THISACTOR].i PLAYERID
	getactor[PLAYERID].extra HEALTHAMOUNT
	getactorvar[PLAYERID].reflective reflmode
	getuserdef[PLAYERID].god godmode

	ifactor APLAYER
	{
		ifwasweapon KNEE { state checkb_armor } else
		ifwasweapon SHOTSPARK1 { state checkb_armor } else
		ifwasweapon RADIUSEXPLOSION { state checkf_armor } else
		ifwasweapon FREEZEBLAST { state checks_armor }
	}

	ifvare player[THISACTOR].extra_extra8 256 //inwater damage
	ifvare player[THISACTOR].airleft 0
	{
		subvar HEALTHAMOUNT 1 
		setactor[PLAYERID].extra HEALTHAMOUNT  
		setplayer[THISACTOR].extra_extra8 0
	}

	setvar RETURN -1
	
endevent

// Process input

onevent EVENT_PROCESSINPUT
getinput[THISACTOR].bits num
ifvarand num 1073741824
{
	getplayer[THISACTOR].inven_icon tmp
	ifvare tmp 11
	{
		ifvarg BEASTVISIONAM 0
		ifcount 13
		{ ifvare BEASTVON 0 { sound POWERUP setvar BEASTVON 1 } else { setvar BEASTVON 0 } resetcount } 
	}
	ifvare tmp 9
	{
		ifinwater
		ifvarg DIVINGSUITAM 0
		ifcount 13
		{ ifvare DIVINGSUITON 0 { sound POWERUP setvar DIVINGSUITON 1 } else { setvar DIVINGSUITON 0 } resetcount } 
	}
	ifvare tmp 8
	{
		ifvarg DOCTORSBAGAM 0
		ifcount 13 { setvar DOCTORSBAGON 1 resetcount } 
	}
	ifvare tmp 12
	{
		ifvarg BOOTSOFJUMPINGAM 0
		ifcount 13
		{ ifvare JBOOTSON 0 { sound POWERUP setvar JBOOTSON 1 } else { setvar JBOOTSON 0 } resetcount } 
	}
	ifvare tmp 10
	{
		ifvarg CRYSTALLBALLAM 0
		ifcount 13
		{ ifvare CRBALLON 0 { sound POWERUP setvar CRBALLON 1 } else { setvar CRBALLON 0 } resetcount } 
	}
}
getplayer[THISACTOR].inven_icon tmp
ifvare tmp 1 { setplayer[THISACTOR].inven_icon 8 }

	state weapon_processinput

endevent

onevent EVENT_DISPLAYROOMS
ifactor APLAYER
{
	setvarvar camera_x camerax
	setvarvar camera_y cameray
	setvarvar camera_z cameraz
	
	ifvarg DRUNKCOUNT 0
	{
		cos crd hz1
		mulvarvar crd DRUNKCOUNT
		shiftvarr crd 13
		addvarvar cameraang crd
		sin crd hz2
		shiftvarr crd 9
		addvarvar camerahoriz crd
	} 
}

ifp pducking 
{ 
	ifvare TIMECOUNT 1	{ addvar cameraz 200 }
	ifvare TIMECOUNT 2	{ addvar cameraz 400 }
	ifvare TIMECOUNT 3	{ addvar cameraz 600 }
	ifvare TIMECOUNT 4	{ addvar cameraz 800 }
	ifvare TIMECOUNT 5	{ addvar cameraz 850 }
	ifvare TIMECOUNT 6	{ addvar cameraz 900 }
	ifvare TIMECOUNT 7	{ addvar cameraz 950 }
	ifvare TIMECOUNT 8	{ addvar cameraz 1000 }
	ifvare TIMECOUNT 9	{ addvar cameraz 900 }
	ifvare TIMECOUNT 10	{ addvar cameraz 700 }
	ifvare TIMECOUNT 11	{ addvar cameraz 500 }
	ifvare TIMECOUNT 12	{ addvar cameraz 300 }
	ifvare TIMECOUNT 13	{ addvar cameraz 250 }
	ifvare TIMECOUNT 14	{ addvar cameraz 200 }
	ifvare TIMECOUNT 15	{ addvar cameraz 150 }
	ifvare TIMECOUNT 16	{ addvar cameraz 100 }
	ifvare TIMECOUNT 17	{ addvar cameraz 50 }
} else setvar TIMECOUNT 0
ifvare fataldead 1 
{ 
	addvar cameraz 6144
}
endevent

// Main code

onevent EVENT_GAME

ifactor APLAYER
{
	state checkhitscan
	setvar spriteid 0
	setvar minimum 16777216 //Thanks to The Lizing for this code
	whilevarn spriteid 16384
	{
		getactor[spriteid].picnum picnum
		switch picnum
		case LOCKER
			ldist EDIST spriteid PLAYERID
			ifvarvarl EDIST minimum { setvarvar minimum EDIST }
		break
		endswitch
		addvar spriteid 1
	}

	/*
	 getplayer[THISACTOR].posx x
	 getplayer[THISACTOR].posy y
	 getplayer[THISACTOR].posz z
	 ifvare godmode 0
     ifvarg k_damage 0 
     {
          addvar COUNTER1 1
          getactor[THISACTOR].htang r0
          setvarvar temp k_damage
          cos x r0
          sin y r0
          divvar temp 2
		  ifvarl temp 0 setvar temp 0 else
          subvarvar temp COUNTER1  		  
          mulvarvar x temp                
          mulvarvar y temp
          shiftvarr x 8
          shiftvarr y 8
          setvar z 0
          movesprite THISACTOR x y z CLIPMASK0 RETURN
          ifvare temp 0 { setvar COUNTER1 0 setvar k_damage 0 }
     }
	*/
}
ifactor LOCKER
{
	getplayer[THISACTOR].i PLAYERID
	ldist EDIST THISACTOR PLAYERID
	ifvarvare EDIST minimum { setactor[THISACTOR].pal 1 } else { setactor[THISACTOR].pal 0 }
}

state weapon_game
state particles_game

ifactor HEART  //VOXEL ANIMATION
{
	addvar COUNTER 1
	ifvare COUNTER 4
	{
		setvar COUNTER 0
		ifaction FRAME_FRAME1 action FRAME_FRAME2 else
		ifaction FRAME_FRAME2 action FRAME_FRAME3 else
		ifaction FRAME_FRAME3 action FRAME_FRAME4 else
		ifaction FRAME_FRAME4 action FRAME_FRAME1
	}
}
ifactor ZOMBIEHEAD
{
	addvar COUNTER 64
	ifvarg COUNTER 2048 { setvar COUNTER 0 }
	{
		cos zdist COUNTER
		divvar zdist 4
		ezshootvar zdist BLOODSPRAY
		getactor[RETURN].ang ang
		addvarvar ang COUNTER
		setactor[RETURN].ang ang
		
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		setactor[RETURN].x x
		setactor[RETURN].y y
		setactor[RETURN].z z
	}
}

endevent

onevent EVENT_KILLIT

	state particles_killit
		
ifactor ZOMBIEHEAD
{
	getactorvar[THISACTOR].active peractor
	espawn ZHEADFLOOR
	setactorvar[RETURN].active peractor
	setvar RETURN 0
}
ifactor BEERBOTTLE
{
	findnearactor3d BCHECK 2048 spriteid
	ifvarn spriteid -1 
	{ 
		getactor[THISACTOR].pal pal
		ifvare pal 1
		{
			getactorvar[spriteid].active tmp 
			addvar tmp 1 
			setactorvar[spriteid].active tmp 
		}
	}
}
endevent

onevent EVENT_EGS

	state weapon_egs

ifactor ZOMBIEHEAD
{
  getplayer[THISACTOR].ang tmp
  setactor[THISACTOR].ang tmp
}
endevent

actor APLAYER MAXPLAYERHEALTH PSTAND 0 0
getactor[THISACTOR].extra HEALTHAMOUNT
getuserdef[THISACTOR].ffire ffirevar
getplayer[THISACTOR].i r0
setplayer[THISACTOR].knuckle_incs 0
getsector[THISACTOR].floorshade shade
getplayer[THISACTOR].curr_weapon CURRWEAP
getactor[PLAYERID].htextra paextra

ifvare peractor 0
{
	ifvarn SAVED_BODYSHIELD 0 setactorvar[THISACTOR].bodyshield SAVED_BODYSHIELD
	ifvarn SAVED_FIRESHIELD 0 setactorvar[THISACTOR].fireshield SAVED_FIRESHIELD
	ifvarn SAVED_SPIRITSHIELD 0 setactorvar[THISACTOR].spiritshield SAVED_SPIRITSHIELD
	setvar peractor 1 
}

getactorvar[THISACTOR].bodyshield BODYSHIELD_AMOUNT
getactorvar[THISACTOR].fireshield FIRESHIELD_AMOUNT
getactorvar[THISACTOR].spiritshield SPIRITSHIELD_AMOUNT

getactorvar[THISACTOR].playerdrunk DRUNKCOUNT
ifvarg DRUNKCOUNT 0
{
	addvar hz1 8
	andvar hz1 2047
	setvarvar hz2 hz1
	mulvar hz2 2
	
	subvar DRUNKCOUNT 1
	setactorvar[THISACTOR].playerdrunk DRUNKCOUNT
	cos cmang hz1
	mulvarvar cmang DRUNKCOUNT
	shiftvarr cmang 14
	
	setplayer[THISACTOR].rotscrnang cmang
}

getactorvar[THISACTOR].handattack temp
ifvare temp 1 
{ 
	randvar temp 6
	ifvare phandvar 0
	{
		addvar peractor 1
		sin perplayer peractor
		divvar perplayer 600
		modvar perplayer 19
		ifvarg perplayer 17 setvar phandvar 1
	}
	
	palfrom 32 0 0 0 
	getplayer[THISACTOR].pals_time pal
	addvarvar pal temp
	addvarvar pal perplayer
	setplayer[THISACTOR].pals_time pal
	
	ifvarl phandtime 40
	{
		addvar phandtime 1
		ifcount 2 { subvar HEALTHAMOUNT 1 resetcount }
		setactor[THISACTOR].extra HEALTHAMOUNT
	} else ifcount 3 setvar phandtime 0
	
	ifrnd 128 { addvar phandcount 2 } else addvar phandcount 3
	ifvarg phandcount 150 setvar phandcount 150
	
	ifhitspace 
	{
		ifvare phandspace 0
		{ 
			ifrnd 127 { subvar phandcount 15 } else ifrnd 127 { subvar phandcount 10 } else subvar phandcount 30
			setvar phandspace 1
			ifvarl phandcount 0 
			{
				espawn EVILHAND 
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				getplayer[THISACTOR].ang ang
				setvarvar x2 x
				addvar x2 512
				rotatepoint x y x2 y ang x3 y3
				setactor[RETURN].x x3
				setactor[RETURN].y y3
				setactorvar[RETURN].handshock 1
				setactorvar[THISACTOR].handattack 0 
				setvar peractor 0
				setvar perplayer 0
				setvar phandvar 0
				setvar phandcount 35
			}
		} 
	} else setvar phandspace 0
}

ifvare cheat_on 1
{
	setactorvar[THISACTOR].bodyshield 200
	setactorvar[THISACTOR].fireshield 200
	setactorvar[THISACTOR].spiritshield 200
	setvar cheat_on 0
}

ifvare DEATHMASK_ON 1
{
	addvar GODTIME 1
	setactor[THISACTOR].htextra -1
	getplayer[THISACTOR].i PLAYERID
	getactor[PLAYERID].extra HEALTHAMOUNT
	ifvare GODTIME 1 { getactor[PLAYERID].extra HPGOD }
	ifvarvarg HEALTHAMOUNT HPGOD { getactor[PLAYERID].extra HPGOD }
	ifvarvarl HEALTHAMOUNT HPGOD { setactor[PLAYERID].extra HPGOD }
	ifvare GODTIME 780 { setvar DEATHMASK_ON 0 setvar GODTIME 0 }
}

randvar voodooprobability 40

ifvare player[THISACTOR].crack_time 1 
{
	ifrnd 28 sound VOICE1 else
	ifrnd 28 sound VOICE2 else
	ifrnd 28 sound VOICE3 else
	ifrnd 28 sound VOICE4 else
	ifrnd 28 sound VOICE5 else
	ifrnd 28 sound VOICE6 else
	ifrnd 28 sound VOICE7 else
	ifrnd 28 sound VOICE8 else
	sound VOICE9
}

getactorvar[THISACTOR].pfire temp
ifvarg temp 0 { addvar COUNTER 1 } 
ifinwater { setvar COUNTER 0 setactorvar[THISACTOR].pfire 0 }
ifvarvare COUNTER 182 { setactorvar[THISACTOR].pfire 0 setvar COUNTER 0 }
	
getactorvar[THISACTOR].reflective temp
ifvare temp 1
{
	palfrom 40 1 5 11
	addvar REFLTIME 1
	ifvarg paextra 0
	{
		getactor[THISACTOR].htowner spriteid
		ifvarn spriteid -1
		{
			getactor[spriteid].extra extra
			ifvarg extra 0
			{
				setactorvar[spriteid].reflective 1
				setactor[THISACTOR].htextra -1
				subvarvar extra paextra
				setactor[spriteid].extra extra
			}
		}
	}
	ifvare REFLTIME 1 { espawn PREFLBALL setactorvar[RETURN].spriteid THISACTOR }
	ifvare REFLTIME 780 { setactorvar[THISACTOR].reflective 0 setvar REFLTIME 0 }
}
/*
	ifvare LIGHTERENABLE 1
	{
		setactorvar[THISACTOR].active 1
		ifvare peractor 0
		{
			espawn SMALLSMOKE
			setvar light_radius 2048
			setvar red 255
			setvar green 144
			setvar blue 0
			state spawnlight
			setvar peractor 1
		}
	} else { setactorvar[THISACTOR].active 0 setvar peractor 0 }
*/

getactorvar[THISACTOR].voodoohitenemy temp
ifvare temp 1 
{ 
	setactor[THISACTOR].extra -1 
	action PTHROWNBACK 
	setactorvar[THISACTOR].voodoohitenemy 0 
}
getactorvar[THISACTOR].voodoohitenemy temp
ifvare temp 2
{
	palfrom 64 0 0 0
	setactorvar[THISACTOR].voodoohitenemy 0 
}

getactorvar[THISACTOR].invisible temp
getactor[THISACTOR].cstat pcstat
ifvare temp 1
{
	orvar pcstat 514
	addvar INVISTIME 1
	setvar orientationweapon 33
	ifvare INVISTIME 780 { subvar pcstat 514 setactorvar[THISACTOR].invisible 0 setvar orientationweapon 0 setvar INVISTIME 0 }
} 
setactor[THISACTOR].cstat pcstat

getactorvar[THISACTOR].flamedamage temp
ifvarg temp 0 { addvar COUNTER 1 state newfirestate  { ifrnd 96 sound PLAY1118 else ifrnd 96 sound PLAY1119 else sound PLAY1120 } } 
ifinwater { setvar COUNTER 0 }
ifvarvare COUNTER temp { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }

getactorvar[THISACTOR].burningguyactive temp
ifvare temp 1 
{ 

    { stopsound PLAY1118 stopsound PLAY1119 stopsound PLAY1120 ifrnd 96 sound DIE1 else ifrnd 96 sound DIE2 else sound DIE3 }
	setactor[THISACTOR].extra -1 
	action PTHROWNBACK 
	setactorvar[THISACTOR].burningguyactive 0 
	setactorvar[THISACTOR].flamedamage 0 
	setvar COUNTER 0 
}

getactor[r0].extra HEALTHAMOUNT
getactorvar[r0].reflective reflmode
getuserdef[r0].god godmode
ifvare godmode 1 { setactor[THISACTOR].htextra 0 }

getactor[THISACTOR].htpicnum htpicnum
ifvare htpicnum ALTTESLA 
{ 
	getactor[THISACTOR].htowner temp
	palfrom 32 32
	getactor[temp].htextra paextra
	ifvarg paextra 128
	{
		divvar paextra 4
		setactor[temp].htextra paextra
		state checkb_armor
		setactor[temp].htpicnum -1
	} else { palfrom 0 setactor[temp].htextra -1 setactor[temp].htpicnum -1 }
}

// -------------- Underwater damage

ifvare player[THISACTOR].airleft 0
{ setvar perplayer 1 }
getactor[THISACTOR].sectnum num
getsector[num].lotag lotag
ifvare lotag 1 ifvare perplayer 1 { sound PAIN6 setvar perplayer 0 }

addvar TIMECOUNT 1

// INVENTORY CODE

ifvare DISPLAYINVENTORY 1
{
	ifvare ICPOSITION 0
	{
        ifvarg DOCTORSBAGAM 0 { setplayer[THISACTOR].inven_icon 8 }
	}
	ifvare ICPOSITION 1
	{
	ifvarg DIVINGSUITAM 0 { setplayer[THISACTOR].inven_icon 9 }
	}
	ifvare ICPOSITION 2
	{
	ifvarg CRYSTALLBALLAM 0 { setplayer[THISACTOR].inven_icon 10 }
        }
        ifvare ICPOSITION 3
	{
	ifvarg BEASTVISIONAM 0 { setplayer[THISACTOR].inven_icon 11 }
        }
        ifvare ICPOSITION 4
	{
	ifvarg BOOTSOFJUMPINGAM 0 { setplayer[THISACTOR].inven_icon 12 }
	}
}

//BEAST VISION ACTION

ifvarg BEASTVISIONAM 0
ifvare BEASTVON 1
{
subvar BEASTVISIONAM 1
setvar VISION 1
} else setvar VISION 0

// DIVING SUIT ACTION

ifinwater
ifvarg DIVINGSUITAM 0
ifvare DIVINGSUITON 1
{
setplayer[THISACTOR].scuba_on 1
subvar DIVINGSUITAM 1
} else { setvar DIVINGSUITON 0 setplayer[THISACTOR].scuba_on 0 }

// DOCTOR'S BAG Thanks to TheLezing for this code

ifvarg DOCTORSBAGAM 0
ifvarn DOCTORSBAGON 0
{ 
setvar DOCTORSBAGON 0
getplayer[THISACTOR].i PLAYERID
getactor[PLAYERID].extra HEALTHAMOUNT
ifvarl HEALTHAMOUNT 100 
 { 
  globalsound PICKHEAL
  mulvar HEALTHAMOUNT -1
  addvar HEALTHAMOUNT 100
  setvarvar tmp DOCTORSBAGAM
  ifvarvarl tmp HEALTHAMOUNT setvarvar HEALTHAMOUNT tmp
  getactor[PLAYERID].extra tmp
  addvarvar tmp HEALTHAMOUNT
  subvarvar DOCTORSBAGAM HEALTHAMOUNT
  setactor[PLAYERID].extra tmp
 }
}

// BOOTS OF JUMPING

ifvarg BOOTSOFJUMPINGAM 0
ifvare JBOOTSON 1
{
subvar BOOTSOFJUMPINGAM 1
getplayer[THISACTOR].jumping_counter tmp
ifvarg tmp 0 { setplayer[THISACTOR].poszv -11584 }
iffloordistl 32
{
getplayer[THISACTOR].falling_counter tmp
ifvarl tmp 61
ifvarg BOOTSOFJUMPINGAM 0
{
  setvar tmp 8
  setplayer[THISACTOR].falling_counter tmp
}
}
}

//CRISTALL BALL

ifvarg CRYSTALLBALLAM 0
{
	ifvare CRBALLON 1 {	subvar CRYSTALLBALLAM 1	}
} 	else setvar CRBALLON 0

// AUTOCLOSE INVMENU

ifvare DISPLAYINVENTORY 1
{
	ifvarn INVENTORYCHECK 0 { subvar INVENTORYCHECK 1 }
	ifvare INVENTORYCHECK 0
	{
	setvar DISPLAYINVENTORY 0
	}
}

//AKIMBO ITEM CODE

ifvarg AKIMBOTIME 0
ifvare tommysweep 0
ifvare akimbotommysweep 0
{
	subvar AKIMBOTIME 1
	ifvare activeakimbo 1
	{
		setvar flakimbo 9
		setvar WEAPON1_FIREDELAY 2
		setvar WEAPON1_TOTALTIME 18
		setvar WEAPON1_FLAGS 68
		
		setvar sgakimbo 9
		setvar WEAPON2_TOTALTIME 14
		setvar WEAPON2_FIREDELAY 2
		setvar WEAPON2_CLIP 0
		setvar WEAPON2_RELOAD 0
				
		setvar tmakimbo 9
				
		setvar npakimbo 9
		setvar WEAPON4_FIREDELAY 2
		setvar WEAPON4_TOTALTIME 21
					
		setvar tsakimbo 9
		setvar activeakimbo 0
	}
	ifvare AKIMBOTIME 0 { setvar deactiveakimbo 1 }
	ifvare deactiveakimbo 1
	{
		setvar flakimbo -9
		setvar WEAPON1_FIREDELAY 5
		setvar WEAPON1_TOTALTIME 15
		setvar WEAPON1_FLAGS 4
		
		setvar sgakimbo -9
		setvar WEAPON2_TOTALTIME 12
		setvar WEAPON2_FIREDELAY 4
		setvar WEAPON2_CLIP 2
		setvar WEAPON2_RELOAD 27
				
		setvar tmakimbo -9
		
		setvar npakimbo -9
		setvar WEAPON4_FIREDELAY 4
		setvar WEAPON4_TOTALTIME 15
					
		setvar tsakimbo -9
	}
} 
ifvare deactiveakimbo 1 { setvar deactiveakimbo 0 }
ifvare CURRWEAP 2
{
	getplayer[THISACTOR].kickback_pic tmp
	ifvare tmp 16
	{ 
		state shotgunshellstate 
		state shotgunshellstate 	
		getactor[RETURN].xoffset xoffset
		addvar xoffset -15
		setactor[RETURN].xoffset xoffset 
	}
}	

// ----------------------------- VOODOO DOLL CODE

	setvar spriteid 0
	setvar minimum 16777216
	setvar minid -1
	whilevarn spriteid 16384
	{
		getactor[spriteid].picnum picnum
		switch picnum
		case ZOMBIE
		case HERETIC
		{
			getactor[spriteid].x mx
			getactor[spriteid].y my
			getactor[spriteid].z mz
			getactor[spriteid].extra extra
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			subvarvar mx x
			subvarvar my y
			getangle mang mx my
		    getactor[THISACTOR].ang ang
			getincangle mang mang ang
			ifvarg extra 0
			ifvarg mang -256 ifvarl mang 256
			{
				dist temp THISACTOR spriteid
				ifvarvarl temp minimum { setvarvar minimum temp }
				ifvarvare temp minimum ifvarvarn spriteid THISACTOR 
				{ setvarvar minid spriteid }
			}
		}
		break
		endswitch
		addvar spriteid 1
	}

	setvar temp 0
	setvar pminimum 16777216
	setvar pminid -1
	getplayer[THISACTOR].i r0
	whilevarvarn temp numplayers
	{
		getplayer[temp].i pid
		ifvarvarn pid r0 { setvarvar peractor2 temp }
		getplayer[peractor2].i pid
		getactor[pid].x px
		getactor[pid].y py
		getactor[pid].z pz
		getactor[pid].extra HEALTHAMOUNT
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		subvarvar px x
		subvarvar py y
		getangle pang px py
		getactor[THISACTOR].ang ang
		getincangle pang pang ang
		ifvarg HEALTHAMOUNT 0
		ifvarg pang -256 ifvarl pang 256
		{
			dist xydist THISACTOR pid
			ifvarvarl xydist minimum { setvarvar minimum xydist }
			ifvarvare xydist minimum ifvarvarn pid r0 { setvarvar pminid pid }
		}
		addvar temp 1
	}
	
	ifvarn pminid -1
	{
		getactor[pminid].x px
		getactor[pminid].y py
		getactor[pminid].z pz
		getactor[pminid].sectnum sect2
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		getactor[THISACTOR].sectnum sect1
		subvar pz 8192

		ifvarn sect2 4096 { cansee x y z sect1 px py pz sect2 psee } else setvar psee 0
		ifvare psee 1
		{
			getactor[pminid].extra HEALTHAMOUNT
			ifvarg HEALTHAMOUNT 0 { setvar voodoohit 1 }
			
			ifvare voodoocount2 3 { ifvarg HEALTHAMOUNT 0 { state pvoodoohitstate } else setvar voodoohit 0 }
			ifvare voodoocount3 3 { ifvarg HEALTHAMOUNT 0 { state pvoodoohitstate } else setvar voodoohit 0 }
			ifvare voodoocount4 3 { ifvarg HEALTHAMOUNT 0 { state pvoodoohitstate } else setvar voodoohit 0 }
			ifvare voodoocount5 3 { ifvarg HEALTHAMOUNT 0 { state pvoodoohitstate } else setvar voodoohit 0 }
		} else setvar voodoohit 0
	} else
	ifvarn minid -1
	{	
		getactor[minid].x mx
		getactor[minid].y my
		getactor[minid].z mz
		getactor[minid].sectnum sect2
		getplayer[THISACTOR].posx px
		getplayer[THISACTOR].posy py
		getplayer[THISACTOR].posz pz
		getplayer[THISACTOR].cursectnum sect1
		subvar mz 8192

		ifvarn sect2 4096 { cansee px py pz sect1 mx my mz sect2 see } else setvar see 0
		ifvare see 1
		{
			getactor[minid].extra extra
			ifvarg extra 0 { setvar voodoohit 1 }
			ifvare voodoocount2 3 { ifvarg extra 0 { state voodoohitstate } else setvar voodoohit 0 }
			ifvare voodoocount3 3 { ifvarg extra 0 { state voodoohitstate } else setvar voodoohit 0 }
			ifvare voodoocount4 3 { ifvarg extra 0 { state voodoohitstate } else setvar voodoohit 0 }
			ifvare voodoocount5 3 { ifvarg extra 0 { state voodoohitstate } else setvar voodoohit 0 }
		} else setvar voodoohit 0

	} else 
	setvar voodoohit 0

	ifvare voodoohit 0
	ifvare voodoocount1 3
	{
			getactor[THISACTOR].extra temp
			subvar temp 1
			setactor[THISACTOR].extra temp
	} 

ifvarn voodoocount1 0
{
	addvar voodoocount1 1
	ifvarg voodoocount1 15 setvar voodoocount1 0
}	
ifvarn voodoocount2 0
{
	addvar voodoocount2 1
	ifvarg voodoocount2 15 setvar voodoocount2 0
}	
ifvarn voodoocount3 0
{
	addvar voodoocount3 1
	ifvarg voodoocount3 15 setvar voodoocount3 0
}	
ifvarn voodoocount4 0
{
	addvar voodoocount4 1
	ifvarg voodoocount4 23 setvar voodoocount4 0
}
ifvarn voodoocount5 0
{
	addvar voodoocount5 1
	ifvarg voodoocount5 35 setvar voodoocount5 0
}	
ifvarn voodooalt 0
ifvare voodoocount1 0 
ifvare voodoocount2 0 
ifvare voodoocount3 0 
ifvare voodoocount4 0 
ifvare voodoocount5 0
{
	setplayer[THISACTOR].curr_weapon 9
	setplayer[THISACTOR].weapon_pos 0
	stopsound INSERT_CLIP
	stopsound SHOTGUN_COCK
	stopsound SELECT_WEAPON

	ifvare voodooalt 20 
	{
		ifvarn pminid -1
		{
			getactor[pminid].extra HEALTHAMOUNT
			ifvarg HEALTHAMOUNT 0
			{ 
				getplayer[THISACTOR].ammo_amount 9 temp
				ifvare psee 1
				{
					mulvar temp 2
					subvarvar HEALTHAMOUNT temp ifvarl HEALTHAMOUNT 0 { setvar HEALTHAMOUNT 0 setactorvar[pminid].playerdrunk 150 setactorvar[pminid].voodoohitenemy 1 setactor[pminid].extra HEALTHAMOUNT }
				}
			}
		} else
		ifvarn minid -1
		{
			getactor[minid].extra extra
			ifvarg extra 0
			{ 
				getplayer[THISACTOR].ammo_amount 9 temp
				ifvare see 1
				{
					mulvar temp 2
					subvarvar extra temp ifvarl extra 0 { setvar extra 0 setactorvar[minid].voodoohitenemy 1 }
				}
			}
		}
		globalsound VOODOOKILL 
		setplayer[THISACTOR].ammo_amount 9 0
	}
	
	addvar voodooalt 1
	ifvarg voodooalt 30 setvar voodooalt 0
}	

//------------------------------DYNAMITE CODE

ifvare CURRWEAP 10 
{ 
	ifvare WEAPON_VAR_TNT 1 { setplayer[THISACTOR].curr_weapon 5 }
	ifvare WEAPON_VAR_TNT 2 { setplayer[THISACTOR].curr_weapon 5 }
}
ifvare CURRWEAP 5 { setvarvar currdinamite WEAPON_VAR_TNT } else { setvar currdinamite 0 }

ifvarn detonateplayer 0
{
	addvar detonateplayer 1
	ifvarg detonateplayer 14 setvar detonateplayer 0
}

ifvarn tntalt 0
{
	setplayer[THISACTOR].curr_weapon 5
	setplayer[THISACTOR].weapon_pos 0
	stopsound INSERT_CLIP
	stopsound SHOTGUN_COCK
	stopsound SELECT_WEAPON
	addvar tntalt 1
	ifvarg tntalt 14 setvar tntalt 14
}

	ifvare SHOOTTNT 1 
	{ 
	getprojectile[TNTBUNDLE].vel tmp
	mulvar TNTCOUNT 8
	addvarvar tmp TNTCOUNT
	setprojectile[TNTBUNDLE].vel tmp

	eshoot TNTBUNDLE
	setactorvar[RETURN].detonatetime dtime
	getactor[RETURN].zvel zvel
	mulvar TNTCOUNT -25
	addvarvar zvel TNTCOUNT
	setactor[RETURN].zvel zvel
	subvar TNT_AMMOAMOUNT 1
	setvar SHOOTTNT 0 
	setvar TNTCOUNT 0
	setvar dtime 0
	setprojectile[TNTBUNDLE].vel 512
	}

	ifvare SHOOTTNT 2
	{ 
	getprojectile[PROXIMITYBUNDLE].vel tmp
	mulvar TNTCOUNT 8
	addvarvar tmp TNTCOUNT
	setprojectile[PROXIMITYBUNDLE].vel tmp

	eshoot PROXIMITYBUNDLE
	getactor[RETURN].zvel zvel
	mulvar TNTCOUNT -25
	addvarvar zvel TNTCOUNT
	setactor[RETURN].zvel zvel
	subvar PROXIMITYMINE_AMMOAMOUNT 1
	setvar SHOOTTNT 0 
	setvar TNTCOUNT 0
	setprojectile[PROXIMITYBUNDLE].vel 512
	}

	ifvare SHOOTTNT 3 
	{ 
	getprojectile[REMOTEBUNDLE].vel tmp
	mulvar TNTCOUNT 8
	addvarvar tmp TNTCOUNT
	setprojectile[REMOTEBUNDLE].vel tmp

	eshoot REMOTEBUNDLE
	getactor[RETURN].zvel zvel
	mulvar TNTCOUNT -25
	addvarvar zvel TNTCOUNT
	setactor[RETURN].zvel zvel
	subvar REMOTETNT_AMMOAMOUNT 1
	setvar SHOOTTNT 0 
	setvar TNTCOUNT 0
	setprojectile[REMOTEBUNDLE].vel 512
	}
	
ifvare CURRWEAP 5
{
ifvare WEAPON_VAR_TNT 1 { setplayer[THISACTOR].ammo_amount 5 TNT_AMMOAMOUNT }
ifvare WEAPON_VAR_TNT 2 { setplayer[THISACTOR].ammo_amount 5 PROXIMITYMINE_AMMOAMOUNT }
ifvare WEAPON_VAR_TNT 3 { setplayer[THISACTOR].ammo_amount 5 REMOTETNT_AMMOAMOUNT }

getplayer[THISACTOR].kickback_pic tmp
ifvare tmp 15 { soundonce TNTTOSS }

getplayer[THISACTOR].ammo_amount 5 tmp
ifvare tmp 0
{
	getplayer[THISACTOR].kickback_pic tmp
	ifvare tmp 0
	{
		ifvare TNT_AMMOAMOUNT 0 ifvare REMOTETNT_AMMOAMOUNT 0 ifvare PROXIMITYMINE_AMMOAMOUNT 0 { setvar changeweappos 5 setplayer[THISACTOR].weapon_pos 10 }
		ifrnd 85 { ifvarg TNT_AMMOAMOUNT 0 { setvar WEAPON_VAR_TNT 1 } } else
		ifrnd 85 { ifvarg REMOTETNT_AMMOAMOUNT 0 { setvar WEAPON_VAR_TNT 3 } } else
		ifvarg PROXIMITYMINE_AMMOAMOUNT 0 { setvar WEAPON_VAR_TNT 2 } else
		setvar LIGHTERENABLE 0
	}
}

ifvare WEAPON_VAR_TNT 1
{
	setvar WEAPON5_FIREDELAY 14
	setvar WEAPON5_HOLDDELAY 15
	ifinwater { setplayer[THISACTOR].weapon_pos 20 setvar LIGHTERENABLE 0 setvar tntalt 0 }
} 
else ifvare WEAPON_VAR_TNT 2
{
	setvar WEAPON5_FIREDELAY 4
	setvar WEAPON5_HOLDDELAY 12
}
else ifvare WEAPON_VAR_TNT 3
{
	setvar WEAPON5_FIREDELAY 4
	setvar WEAPON5_HOLDDELAY 12
}
	
	ifvare tntalt 14
	{
	addvar dtime 1 soundonce TNTFUSE
	ifvarg dtime 156
			{
			setplayer[THISACTOR].kickback_pic 0
			setplayer[THISACTOR].weapon_pos 20
			palfrom 32 32
			setvar detonateplayer 1
			globalsound EXPLODCM
			espawn EXPLOSION3
	    	getactor[THISACTOR].x x
	    	getactor[THISACTOR].y y
	    	getplayer[THISACTOR].ang tmp
	    	setvarvar x2 x
	    	addvar x2 512
	    	rotatepoint x y x2 y tmp x3 y3
	    	setactor[RETURN].x x3
	    	setactor[RETURN].y y3
			hitradius 2048 60 100 160 300

			getplayer[THISACTOR].ang ang
			addvar ang 1024
			setactor[THISACTOR].htang ang
			setactor[THISACTOR].htextra 150
			setvarvar k_damage 25
			getplayer[THISACTOR].ammo_amount 5 tmp
			ifvarg tmp 0 subvar tmp 1
			setplayer[THISACTOR].ammo_amount 5 tmp
			setvar dtime 0
			setvar tntalt 0
			}
	}
	getplayer[THISACTOR].kickback_pic tmp
	ifvare tmp 14
	ifvare WEAPON_VAR_TNT 1
	{
	addvar dtime 1 soundonce TNTFUSE
	ifvarg dtime 156
			{
			setplayer[THISACTOR].kickback_pic 0
			setplayer[THISACTOR].weapon_pos 20
			palfrom 32 32
			setvar detonateplayer 1
			globalsound EXPLODCM
			espawn EXPLOSION3
	    	getactor[THISACTOR].x x
	    	getactor[THISACTOR].y y
	    	getplayer[THISACTOR].ang tmp
	    	setvarvar x2 x
	    	addvar x2 512
	    	rotatepoint x y x2 y tmp x3 y3
	    	setactor[RETURN].x x3
	    	setactor[RETURN].y y3
			hitradius 2048 60 100 160 300

			getplayer[THISACTOR].ang ang
			addvar ang 1024
			setactor[THISACTOR].htang ang
			setactor[THISACTOR].htextra 150
			setvarvar k_damage 25
			getplayer[THISACTOR].ammo_amount 5 tmp
			ifvarg tmp 0 subvar tmp 1
			setplayer[THISACTOR].ammo_amount 5 tmp
			setvar dtime 0
			setvar tntalt 0
			}
	}
	ifvare dtime 0 { stopsound TNTFUSE }
}

ifvare CURRWEAP 10
{
	getplayer[THISACTOR].kickback_pic tmp
	ifvare tmp 3 { globalsound PROXDET }
	
	ifvare  REMOTETNT_AMMOAMOUNT 0
	{
		ifrnd 128 { ifvarg TNT_AMMOAMOUNT 0 { setplayer[THISACTOR].ammo_amount 5 TNT_AMMOAMOUNT } } else
		ifvarg PROXIMITYMINE_AMMOAMOUNT 0 { setplayer[THISACTOR].ammo_amount 5 PROXIMITYMINE_AMMOAMOUNT }
	}
}


//LIGHTER CODE

ifvare CURRWEAP 6 ifvare LIGHTERENABLE 0 { ifvare player[THISACTOR].weapon_pos 2 globalsound ZIPLIGHT }
ifvare CURRWEAP 5 ifvare LIGHTERENABLE 0 ifvare WEAPON_VAR_TNT 1 { ifvare player[THISACTOR].weapon_pos 2 globalsound ZIPLIGHT } 
ifvarn CURRWEAP 6 ifvarn currdinamite 1 { setvar LIGHTERENABLE 0 }
ifvare CURRWEAP 10 { setvar LIGHTERENABLE 1 }
ifvarn CURRWEAP 5 ifvarn CURRWEAP 6 { setvar TNTCOUNT 0 }


// SPRAY CODE

ifvarn sprayalt 0
{
	setvar WEAPON6_TOTALTIME 16
	setplayer[THISACTOR].curr_weapon 6
	setplayer[THISACTOR].weapon_pos 0
	stopsound INSERT_CLIP
	stopsound SHOTGUN_COCK
	stopsound SELECT_WEAPON
	addvar sprayalt 1
	ifvarg sprayalt 14 setvar sprayalt 14
}

ifvare sprayalt 14
{
	addvar dtime 1 soundonce SPRAYFIR
	ifvarg dtime 156
			{
			setplayer[THISACTOR].weapon_pos 20
			palfrom 32 32
			setvar detonateplayer 1
			globalsound EXPLODCM
			stopsound SPRAYFIR
			espawn EXPLOSION3
	    	getactor[THISACTOR].x x
	    	getactor[THISACTOR].y y
	    	getplayer[THISACTOR].ang tmp
	    	setvarvar x2 x
	    	addvar x2 512
	    	rotatepoint x y x2 y tmp x3 y3
	    	setactor[RETURN].x x3
	    	setactor[RETURN].y y3
			hitradius 2048 60 100 160 300
			getplayer[THISACTOR].ang ang
			addvar ang 1024
			setactor[THISACTOR].htang ang
			setactor[THISACTOR].htextra 150
			setvarvar k_damage 25
			getplayer[THISACTOR].ammo_amount 6 tmp
			subvar tmp 48
			setplayer[THISACTOR].ammo_amount 6 tmp
			setvar dtime 0
			setvar sprayalt 0
			}
}
ifp palive
{
	ifvare SHOOTSPRAY 1 
	{ 
	getprojectile[SPRAYBUNDLE].vel tmp
	mulvar TNTCOUNT 8
	addvarvar tmp TNTCOUNT
	setprojectile[SPRAYBUNDLE].vel tmp

	eshoot SPRAYBUNDLE
	getactor[RETURN].zvel zvel
	mulvar TNTCOUNT -25
	addvarvar zvel TNTCOUNT
	setactor[RETURN].zvel zvel
	getplayer[THISACTOR].ammo_amount 6 tmp
	subvar tmp 48
	setplayer[THISACTOR].ammo_amount 6 tmp
	setvar SHOOTSPRAY 0 
	setvar TNTCOUNT 0
	setvar dtime 0
	setprojectile[SPRAYBUNDLE].vel 512
	}
}
ifvare CURRWEAP 6
{
getplayer[THISACTOR].kickback_pic tmp
ifvare tmp 6 { globalsound TNTTOSS }
ifinwater { setplayer[THISACTOR].weapon_pos 20 setvar LIGHTERENABLE 0 setvar sprayalt 0 }
}

// TESLA CODE

ifvare CURRWEAP 7
ifp palive
ifvare akimboteslaalt 0
ifvare teslaalt 0
{
	getplayer[THISACTOR].ammo_amount 7 tmp
	ifvarg tmp 0
	{
		getplayer[THISACTOR].kickback_pic temp
		ifvarand temp 1 { modvar temp 1 }
		ifvarg temp 0
		{ 
			ifvare tsakimbo 0
			{
				subvar tmp 1
				setplayer[THISACTOR].ammo_amount 7 tmp
				sound TESSNGFR
				sound TESSNGHT
				shoot PLASMAPROJ 
			} 
			else 
			{
				subvar tmp 1
				setplayer[THISACTOR].ammo_amount 7 tmp
				sound TESSNGFR
				sound TESSNGHT
				eshoot PLASMAPROJ
				getactor[RETURN].xoffset xoffset
				addvar xoffset -12
				setactor[RETURN].xoffset xoffset
			}
		}
	}
}

// TESLA ALT FIRE

ifvarn teslaalt 0
ifvare akimboteslaalt 0
{
	setplayer[THISACTOR].curr_weapon 7
	setplayer[THISACTOR].weapon_pos 0
	stopsound INSERT_CLIP
	stopsound SHOTGUN_COCK
	stopsound SELECT_WEAPON
	
	ifvare teslaalt 1 { sound TESLA1 }
	ifvare teslaalt 60 
	{
		shoot ALTTESLA
		globalsound TESALTFR 
		getplayer[THISACTOR].ammo_amount 7 tmp
		subvar tmp 35
		setplayer[THISACTOR].ammo_amount 7 tmp
	}
	addvar teslaalt 1
	ifvarg teslaalt 71 setvar teslaalt 0
	getplayer[THISACTOR].ammo_amount 7 tmp
	ifvarl tmp 35 { setvar teslaalt 0 }
}

ifvarn akimboteslaalt 0
ifvare teslaalt 0
{
	setplayer[THISACTOR].curr_weapon 7
	setplayer[THISACTOR].weapon_pos 0
	stopsound INSERT_CLIP
	stopsound SHOTGUN_COCK
	stopsound SELECT_WEAPON
	
	ifvare akimboteslaalt 35
	{
		eshoot ALTTESLA
		globalsound TESALTFR 
		getactor[RETURN].xoffset xoffset
		addvar xoffset -24
		setactor[RETURN].xoffset xoffset
		getplayer[THISACTOR].ammo_amount 7 tmp
		subvar tmp 35
		setplayer[THISACTOR].ammo_amount 7 tmp
	}
	ifvare akimboteslaalt 38
	{
		eshoot ALTTESLA
		globalsound TESALTHT
		getactor[RETURN].xoffset xoffset
		addvar xoffset 24
		setactor[RETURN].xoffset xoffset
		getplayer[THISACTOR].ammo_amount 7 tmp
		subvar tmp 35
		setplayer[THISACTOR].ammo_amount 7 tmp
	}
	ifvare akimboteslaalt  7 { sound TALTAC3 }
	ifvare akimboteslaalt 10 { sound TESLAZ1 sound TESLAZ2 }
	
	
	addvar akimboteslaalt 1
	ifvarg akimboteslaalt 43 setvar akimboteslaalt 0
}

//------------------------------HELLSTAFF CODE

ifvare CURRWEAP 8
ifp palive
{
	getplayer[THISACTOR].kickback_pic temp
	ifvare temp 1 { globalsound LALTFR1 }
	ifvarg temp 9 ifvarl temp 62
	{
		ifvarand temp 3 { modvar temp 3 }
		ifvare temp 1
		{ 
			getplayer[THISACTOR].ammo_amount 8 tmp
			ifvarg tmp 0
			ifvarn tmp 1
			{ 
				subvar tmp 1
				setplayer[THISACTOR].ammo_amount 8 tmp
				eshoot STAFFPROJ
				getplayer[THISACTOR].ang temp
				randvar tmp 32
				ifrnd 128  addvarvar temp tmp else subvarvar temp tmp
				setactor[RETURN].ang temp
				getactor[RETURN].zvel zvel
				subvar zvel 128
				setvar tmp 0
				randvar tmp 256
				addvarvar zvel tmp
				setactor[RETURN].zvel zvel
			} 
			else
			{
				getactor[r0].extra extra
				subvar extra 1
				setactor[r0].extra extra
				getplayer[THISACTOR].ammo_amount 8 tmp
				subvar tmp 1
				setplayer[THISACTOR].ammo_amount 8 tmp
				eshoot STAFFPROJ
				getplayer[THISACTOR].ang temp
				randvar tmp 32
				ifrnd 128  addvarvar temp tmp else subvarvar temp tmp
				setactor[RETURN].ang temp
				getactor[RETURN].zvel zvel
				subvar zvel 128
				setvar tmp 0
				randvar tmp 256
				addvarvar zvel tmp
				setactor[RETURN].zvel zvel
			}
		} 
	}
	getplayer[THISACTOR].ammo_amount 8 temp
	ifvare temp 0 { setplayer[THISACTOR].ammo_amount 8 1 }
}

	
//------------------------------RESET ALTFIRE

ifvare player[THISACTOR].kickback_pic 0 
{
setvar flarealt 0
setvar shotgunalt 0
setvar napalmalt 0
}

//------------------------------AKIMBOCODE

// FLARE AKIMBO

ifvarg flakimbo 1 subvar flakimbo 1
ifvarl flakimbo -1
{
	addvar flakimbo 1
	ifvare flakimbo -1 setvar flakimbo 0
}

//SHOTGUN AKIMBO

ifvarg sgakimbo 1 subvar sgakimbo 1
ifvarl sgakimbo -1
{
	addvar sgakimbo 1
	ifvare sgakimbo -1 setvar sgakimbo 0
}

//TOMMYGUN AKIMBO

ifvarg tmakimbo 1 subvar tmakimbo 1
ifvarl tmakimbo -1
{
	addvar tmakimbo 1
	ifvare tmakimbo -1 setvar tmakimbo 0
}

//NAPALM AKIMBO

ifvarg npakimbo 1 subvar npakimbo 1
ifvarl npakimbo -1
{
	addvar npakimbo 1
	ifvare npakimbo -1 setvar npakimbo 0
}

//TESLAGUN AKIMBO

ifvarg tsakimbo 1 subvar tsakimbo 1
ifvarl tsakimbo -1
{
	addvar tsakimbo 1
	ifvare tsakimbo -1 setvar tsakimbo 0
}

ifvare CURRWEAP 1 ifvarg flakimbo 0
ifvare player[THISACTOR].kickback_pic 7
ifp palive
{
ifvare flarealt 0
	{	
		sound FLAREF
		eshoot FLARE
		getactor[RETURN].xoffset xoffset
		addvar xoffset 24
		setactor[RETURN].xoffset xoffset
		getplayer[THISACTOR].ammo_amount 1 tmp
		ifvarg tmp 0 subvar tmp 1
		setplayer[THISACTOR].ammo_amount 1 tmp
	} 
	else 
	{ 
		getplayer[THISACTOR].ammo_amount 1 ammo
		ifvarg ammo 7
		{
			setprojectile[FLARE].spawns EXPLOSION6
			setprojectile[FLARE].sxrepeat 32
			setprojectile[FLARE].syrepeat 32
			subvar ammo 8
			setplayer[THISACTOR].ammo_amount 1 ammo
			sound FLAREF
			eshoot FLARE
			setactorvar[RETURN].flarealtproj 1
			setactorvar[RETURN].flarefulldamage 1
			setactorvar[RETURN].noflarefire 1
			ifvarl flakimbo 1 { setvar flarealt 0 }
			setprojectile[FLARE].spawns FLAREFIRE
			setprojectile[FLARE].sxrepeat -1
			setprojectile[FLARE].syrepeat -1
		} else setplayer[THISACTOR].kickback_pic 0
		setvar flarealt 0
	}
}
ifvare CURRWEAP 2 ifvarg sgakimbo 0
ifvare player[THISACTOR].kickback_pic 5
ifp palive
{
ifvare shotgunalt 0
	{	
		sound SHOTFIRE
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO
		shoot SHOTAMMO

		getplayer[THISACTOR].ammo_amount 2 tmp
		ifvarg tmp 0 subvar tmp 1
		setplayer[THISACTOR].ammo_amount 2 tmp
		setvar shotgunalt 0
	} 
}
ifvarn akimboshotgunalt 0
{
		switch akimboshotgunalt
		case 1
		getplayer[THISACTOR].ammo_amount 2 tmp
		ifvarg tmp 3 
		{
			sound SHOTFIR2
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			shoot SHOTAMMO
			
			subvar tmp 4
			setplayer[THISACTOR].ammo_amount 2 tmp
		}
		break
		default break
		endswitch
		
		addvar akimboshotgunalt 1
		ifvarg akimboshotgunalt 24 setvar akimboshotgunalt 0
}

ifvare CURRWEAP 3 
{
getplayer[THISACTOR].kickback_pic temp
ifvarand temp 1
ifvare tmakimbo 1
ifp palive
ifvare akimbotommysweep 0
	{	
		sound TOM
		flash
		shoot TOMMYFIRST
		setvar xoffset 65 state tommyshellstate
		getplayer[THISACTOR].ammo_amount 3 tmp
		ifvarg tmp 0 subvar tmp 1
		setplayer[THISACTOR].ammo_amount 3 tmp
	} 
}

ifvarn akimbotommysweep 0
{
		setplayer[THISACTOR].curr_weapon 3
		setplayer[THISACTOR].weapon_pos 1
		stopsound INSERT_CLIP
		stopsound SHOTGUN_COCK
		stopsound SELECT_WEAPON
	
		getplayer[THISACTOR].ang ang
		setvarvar saveang ang
		switch akimbotommysweep
		case 2
		subvar ang 48
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 110 state tommyshellstate
		break
		case 4
		subvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 120 state tommyshellstate
		break
		case 6
		subvar ang 96
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 120 state tommyshellstate
		break
		case 8
		subvar ang 144
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 120 state tommyshellstate
		break
		case 10
		subvar ang 144
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 120 state tommyshellstate
		break
		case 12
		subvar ang 96
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 120 state tommyshellstate
		break
		case 14
		subvarvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 75 state tommyshellstate
		break
		case 16
		subvar ang 48
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 75 state tommyshellstate
		break
		case 18
		addvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 75 state tommyshellstate
		break
		case 20
		addvar ang 96
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 75 state tommyshellstate
		break
		case 22
		addvar ang 144
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 40 state tommyshellstate
		break
		case 24
		case 26
		addvar ang 144
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 40 state tommyshellstate
		break
		case 28
		addvar ang 96
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 60 state tommyshellstate
		break
		case 30
		addvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		setvar xoffset 75 state tommyshellstate
		break
		default break
		endswitch
		
		addvar akimbotommysweep 1
		ifvarg akimbotommysweep 29 setvar akimbotommysweep 0
		getplayer[THISACTOR].ammo_amount 3 tmp
		ifvarl tmp 1 { setvar akimbotommysweep 0 }
}

ifvare CURRWEAP 4 ifvarg npakimbo 0
ifvare player[THISACTOR].kickback_pic 7
ifp palive
{
ifvare napalmalt 0
	{	
		sound NAPEXPL
		eshoot PR_NAPALM
		getactor[RETURN].xoffset xoffset
		addvar xoffset 24
		setactor[RETURN].xoffset xoffset
		getplayer[THISACTOR].ammo_amount 4 tmp
		ifvarg tmp 0 subvar tmp 1
		setplayer[THISACTOR].ammo_amount 4 tmp
	} 
	else 
	{ 
		getplayer[THISACTOR].ammo_amount 4 temp
		ifvarg temp 0
		{
		 sound NAPEXPL
		 eshoot ALTNAPALM
		 ifvarg temp 12 { setactorvar[RETURN].napalmammo 12 } else setactorvar[RETURN].napalmammo temp
		 ifvarg temp 11 { subvar tmp 12 } else setvar temp 0
		 getactor[RETURN].xoffset xoffset
		 addvar xoffset 24
	     setactor[RETURN].xoffset xoffset
		 setplayer[THISACTOR].ammo_amount 4 temp
		} 
		setvar napalmalt 0
	}
}

ifvare CURRWEAP 7 
ifvarg tsakimbo 0
ifvare teslaalt 0
ifvare akimboteslaalt 0
{	
		getplayer[THISACTOR].kickback_pic temp
		ifvarand temp 1 { modvar temp 1 }
		ifvarg temp 0
		{
			getplayer[THISACTOR].ammo_amount 7 tmp
			ifvarg tmp 0
			{
					subvar tmp 1
					setplayer[THISACTOR].ammo_amount 7 tmp
					sound TESSNGFR
					sound TESSNGHT
					eshoot PLASMAPROJ 
					getactor[RETURN].xoffset xoffset
					addvar xoffset 24
					setactor[RETURN].xoffset xoffset
			}
		}
} 

//------------------------------HUDCOORDFIX

//Thanks to TheLezing for this code

  setvar r8 -16
  whilevarn r8 0 {
    addvar r8 1
    // Evaluate dynamics
    getplayer[THISACTOR].i r0
    getactor[r0].x r1
    addvarvar r1 camera_x
    shiftvarl r1 4
    subvarvar r1 HUDpx
    getactor[r0].y r2
    addvarvar r2 camera_y
    shiftvarl r2 4
    subvarvar r2 HUDpy
    getactor[r0].z r3
    addvarvar r3 camera_z
    getplayer[THISACTOR].horiz r4
    subvar r4 100
    shiftvarl r4 2
    addvarvar r3 r4
    subvarvar r3 HUDpz
    mulvar r1 -1 mulvar r2 -1 mulvar r3 -1
    // {r1, r2, r3} are current relative weapon coordinates
    setvar r4 256
    setvar r5 4096
    setvar r6 0
    // {r4, r5, r6} are coordinates of the balanced point
    getactor[r0].ang r7
    addvar r7 1536
    rotatepoint 0 0 r4 r5 r7 r4 r5
    subvarvar r4 r1 subvarvar r5 r2 subvarvar r6 r3
    // {r4, r5, r6} is now the acceleration vector (not normalized)
    setvarvar r0 r4 ifvarl r0 0 mulvar r0 -1
    setvarvar r1 r5 ifvarl r1 0 mulvar r1 -1
    setvarvar r2 r6 ifvarl r2 0 mulvar r2 -1
    addvarvar r0 r1 addvarvar r0 r2
    ifvarg r0 65536 { // Too fast!
      addvarvar HUDpx r4
      addvarvar HUDpy r5
      addvarvar HUDpz r6
      setvar HUDvx 0
      setvar HUDvy 0
      setvar HUDvz 0
    } else {
      addvarvar HUDpx HUDvx
      addvarvar HUDpy HUDvy
      addvarvar HUDpz HUDvz
      setvarvar r0 r4 mulvarvar r0 r0
      setvarvar r1 r5 mulvarvar r1 r1 addvarvar r0 r1
      setvarvar r1 r6 mulvarvar r1 r1 addvarvar r0 r1
      sqrt r0 r0
      mulvarvar r4 r0 mulvarvar r5 r0 mulvarvar r6 r0
      shiftvarr r4 14 shiftvarr r5 14 shiftvarr r6 14
      addvarvar HUDvx r4
      addvarvar HUDvy r5
      addvarvar HUDvz r6
      getplayer[THISACTOR].i r0
      getactor[r0].sectnum r0
      getsector[r0].lotag r0
      ifvare r0 2 {
        addvarvar HUDvz 16 // Gravity
        mulvar HUDvx 5 mulvar HUDvy 5 mulvar HUDvz 6
      } else {
        addvarvar HUDvz 32 // Gravity
        mulvar HUDvx 7 mulvar HUDvy 7 mulvar HUDvz 7
      }
      shiftvarr HUDvx 4 shiftvarr HUDvy 4 shiftvarr HUDvz 4
    }
  }
  // Get projection
  getplayer[THISACTOR].i r0
  getactor[r0].x r1
  addvarvar r1 camera_x
  shiftvarl r1 4
  subvarvar r1 HUDpx
  getactor[r0].y r2
  addvarvar r2 camera_y
  shiftvarl r2 4
  subvarvar r2 HUDpy
  getactor[r0].z r3
  addvarvar r3 camera_z
  
  subvarvar r3 HUDpz
  getactor[r0].ang r4
  addvar r4 1536
  mulvar r4 -1
  rotatepoint 0 0 r1 r2 r4 r1 r2
  mulvar r1 -160
  mulvar r3 100

  ifvarn r2 0 // Prevent division by zero
  {
    divvarvar r1 r2
    divvarvar r3 r2
    subvar r1 16
    // subvar r3 64
    // HUDsx=HUDsx+(r1-HUDsx)*theta
    subvarvar r1 HUDsx
    shiftvarr r1 1
    addvarvar HUDsx r1
    subvarvar r3 HUDsy
    shiftvarr r3 1
    addvarvar HUDsy r3
  }
  
  // shiftvarr HUDsx 8
  // shiftvarr HUDsy 8
  /* findnearactor SIXPAK 2048 r0 // Debug info
  setvarvar r1 HUDpx
  shiftvarr r1 4
  setactor[r0].x r1
  setvarvar r2 HUDpy
  shiftvarr r2 4
  setactor[r0].y r2
  updatesector r1 r2 r3
  setactor[r0].sectnum r3 */
  
 //------------------------------END HUDCOORDFIX
 
 //Thanks to DeeperThought for this code
 
 	// check floor type
	getsector[THISACTOR].floorpicnum picnum
	ifvare picnum 6236
	{
		getplayer[THISACTOR].cursectnum temp
		ifvarn temp -1 
		{
			getplayer[THISACTOR].posx x
			getplayer[THISACTOR].posy y
			getplayer[THISACTOR].posz z
			addvar z 8192
			getflorzofslope temp x y mz
			subvarvar mz z
			ifvarl mz 2048
			{
				addphealth -1
				palfrom 16 16
			}
		}
	}	

  ifvarn tommysweep 0
	{
		setplayer[THISACTOR].curr_weapon 3
		setplayer[THISACTOR].weapon_pos 1
		stopsound INSERT_CLIP
		stopsound SHOTGUN_COCK
		stopsound SELECT_WEAPON
		
		getplayer[THISACTOR].ang ang
		setvarvar saveang ang
		switch tommysweep
		case 2
		state tommyfire
		ifvare tmakimbo 0 { setvar xoffset -5 state tommyshellstate } else { setvar xoffset -70 state tommyshellstate }
		break
		case 4
		subvar ang 24
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset 30 state tommyshellstate } else { setvar xoffset -40 state tommyshellstate }
		break
		case 6
		subvar ang 48
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset 30 state tommyshellstate } else { setvar xoffset -40 state tommyshellstate }
		break
		case 8
		subvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset 30 state tommyshellstate } else { setvar xoffset -40 state tommyshellstate }
		break
		case 10
		subvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset 30 state tommyshellstate } else { setvar xoffset -40 state tommyshellstate }
		break
		case 12
		subvar ang 48
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset 30 state tommyshellstate } else { setvar xoffset -40 state tommyshellstate }
		break
		case 14
		subvar ang 24
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset 10 state tommyshellstate } else { setvar xoffset -70 state tommyshellstate }
		break
		case 16
		state tommyfire
		ifvare tmakimbo 0 { setvar xoffset -10 state tommyshellstate } else { setvar xoffset -70 state tommyshellstate }
		break
		case 18
		addvar ang 24
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset -15 state tommyshellstate } else { setvar xoffset -70 state tommyshellstate }
		break
		case 20
		addvar ang 48
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset -30 state tommyshellstate } else { setvar xoffset -90 state tommyshellstate }
		break
		case 22
		addvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset -70 state tommyshellstate } else { setvar xoffset -120 state tommyshellstate }
		break
		case 24
		addvar ang 72
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset -70 state tommyshellstate } else { setvar xoffset -120 state tommyshellstate }
		break
		case 26
		addvar ang 48
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset -70 state tommyshellstate } else { setvar xoffset -120 state tommyshellstate }
		break
		case 28
		case 30
		addvar ang 24
		setplayer[THISACTOR].ang ang
		state tommyfire
		setplayer[THISACTOR].ang saveang
		ifvare tmakimbo 0 { setvar xoffset -50 state tommyshellstate } else { setvar xoffset -80 state tommyshellstate }
		break
		default break
		endswitch
		
		addvar tommysweep 1
		ifvarg tommysweep 29 setvar tommysweep 0
		getplayer[THISACTOR].ammo_amount 3 tmp
		ifvarl tmp 1 { setvar tommysweep 0 }
	}

	ifp pjumping ifcount 12 { globalsound JUMP resetcount }
	
	ifinwater
	{
		stopsound DUKE_LONGTERM_PAIN
		ifvarl HEALTHAMOUNT 45 sound PAIN5
	}
	
  ifaction 0
    action PSTAND
	
  ifdead
  {
	setactorvar[THISACTOR].handattack 0 
	setactorvar[THISACTOR].active 0
	setplayer[THISACTOR].kickback_pic 0
	setvar COUNTER 0
	setactorvar[THISACTOR].pfire 0
	setactorvar[THISACTOR].bodyshield 0
	setactorvar[THISACTOR].fireshield 0
	setactorvar[THISACTOR].spiritshield 0
	setvarvar SAVED_BODYSHIELD 0
	setvarvar SAVED_FIRESHIELD 0
	setvarvar SAVED_SPIRITSHIELD 0
	
	setactorvar[THISACTOR].reflective 0
	setvar TNT_AMMOAMOUNT 0
	setvar REMOTETNT_AMMOAMOUNT 0
	setvar PROXIMITYMINE_AMMOAMOUNT 0
	setactorvar[THISACTOR].burningguyactive 0
	setactorvar[THISACTOR].flamedamage 0
	stopsound PROXDET
	stopsound TNTFUSE
	setvar teslaalt 0
	setvar akimboteslaalt 0
	setvar dtime 0
	setvar deactiveakimbo 1
	setvar LIGHTERENABLE 0
	setvar TNTCOUNT 0
	setvar SHOOTTNT 0
	setvar sprayfire -1
	setvar sprayalt 0
	
    ifaction PGROWING
    {
	      ifmove 1
	      {
	        quote 13
	        ifhitspace
	        {
	          action 0
	          resetplayer
	        }
	        break
	      }
	      else
	      {
	        ifcount 32
	        {
	          sound SQUISHED
	          palfrom 48 64

	          state standard_pjibs

	          guts JIBS4 20
	          guts JIBS6 20
	          move 1
	          cstat 32768

	          hitradius 2048 60 70 80 90

	        }
	        else
	          sizeto MAXXSTRETCH MAXYSTRETCH
	      }
	      break
    }

    ifsquished
      palfrom 32 63 63 63
    else
      fall

    ifactioncount 7
      move 0

    ifaction PLYINGDEAD
    {
      ifactioncount 3
        move PSTOPED
      quote 13
      ifhitspace
      {
        action PSTAND
        spawn CALEBLYINGDEAD
        resetplayer
      }
      break
    }

    ifaction PTHROWNBACK
    {
      ifactioncount 5
      {
        spawn BLOODPOOL
        action PLYINGDEAD
      }
      else
        ifactioncount 1
          move 0
      break
    }

    ifaction PEXPLODEAD
    {
      quote 13
      ifhitspace
      {
        resetplayer
        action PSTAND
      }
      break
    }
    ifaction PEXPLODE
    {
      ifactioncount 5
      {
        action PEXPLODEAD
        spawn BLOODPOOL
      }
      break
    }

     ifinwater
     {
        action PLYINGDEAD
        spawn WATERBUBBLE
        spawn WATERBUBBLE
     }
     else
     {
       action PEXPLODE
       state standard_pjibs
	   state jibs_state
       sound SQUISHED
       { ifrnd 96 sound DIE1 else ifrnd 96 sound DIE2 else sound DIE3 }
     }
    break
  }
  
  // end ifdead

  
  // ----- FATALITY CODE

  ifmultiplayer
  ifvarn COOP 1
  {
	  ifvarl HEALTHAMOUNT 20
	  ifvare pmultivar 0  
	  {      
		getplayer[THISACTOR].posx fx
		getplayer[THISACTOR].posy fy
		getplayer[THISACTOR].posz fz
		getplayer[THISACTOR].ang fang
		action PFALL
		randvar FCOUNTRAND 100
		addvar FCOUNTRAND 150
		setplayer[THISACTOR].movement_lock 15
		setactorvar[THISACTOR].playerdrunk 300
		setvar fatalvar 1
		setvar pmultivar 1
		break
	  }
	  ifaction PFALL
	  {
		setplayer[THISACTOR].posx fx
		setplayer[THISACTOR].posy fy
		setplayer[THISACTOR].posz fz
		setplayer[THISACTOR].ang fang
		setplayer[THISACTOR].weapon_pos 20
		
	    ifactioncount 3 
			action PFATALITY
				break 
	  }
	  ifaction PFATALITY
	  {
		setplayer[THISACTOR].posx fx
		setplayer[THISACTOR].posy fy
		setplayer[THISACTOR].posz fz
		setplayer[THISACTOR].ang fang
		setplayer[THISACTOR].weapon_pos 20
		addvar FCOUNT 1
		getinput[THISACTOR].extbits temp
		ifvarvarg FCOUNT FCOUNTRAND 
		{ 
			ifvarn temp 0 { action PGETUP globalsound LIVEAGAIN setplayer[THISACTOR].movement_lock 0 setvar FCOUNT 0 setvar FCOUNTRAND 0 setvar fatalvar 0 setactorvar[THISACTOR].playerdrunk 0 break } 
			else ifcount 100 { action PDAMAGED break }
		}
		getactor[THISACTOR].htextra htextra
		ifhitweapon { strength 1 ifvarl htextra 20 action PDAMAGED else action PDAMAGED2 }
	  }

	ifaction PDAMAGED
    {
		setvar FCOUNT 0 setvar FCOUNTRAND 0 
		setplayer[THISACTOR].posx fx
		setplayer[THISACTOR].posy fy
		setplayer[THISACTOR].posz fz
		setplayer[THISACTOR].ang fang
		setplayer[THISACTOR].weapon_pos 20
		palfrom 64 64
		setvar fataldead 1
		sound DIE1
		  ifactioncount 6
		  {
			spawn BLOODPOOL
			action PDEAD
		  }
		  break
    }
	
	ifaction PDAMAGED2
    {
		setvar FCOUNT 0 setvar FCOUNTRAND 0 
		setplayer[THISACTOR].posx fx
		setplayer[THISACTOR].posy fy
		setplayer[THISACTOR].posz fz
		setplayer[THISACTOR].ang fang
		setplayer[THISACTOR].weapon_pos 20
		
		ifvare fataltmp 0
		{
			setprojectile[ZOMBIEHEAD].vel 60 
			ezshoot -1024 ZOMBIEHEAD 
			getactor[RETURN].z z 
			addvar z -3800 
			setactor[RETURN].z z
			setvar fataltmp 1
		}
		
		palfrom 64 64
		setvar fataldead 1
		sound DIE1
		  ifactioncount 5
		  {
			spawn BLOODPOOL
			action PDEAD2
		  }
		  break
    }
	  
	  ifaction PGETUP
	  {
		setplayer[THISACTOR].posx fx
		setplayer[THISACTOR].posy fy
		setplayer[THISACTOR].posz fz
		setplayer[THISACTOR].ang fang
		
		ifactioncount 3
			action PSTAND
				break
	  }
	  
	  ifaction PDEAD
	  {
		setplayer[THISACTOR].posx fx
		setplayer[THISACTOR].posy fy
		setplayer[THISACTOR].posz fz
		setplayer[THISACTOR].weapon_pos 20
		ifactioncount 3
        move PSTOPED
		quote 13
	    ifhitspace
		{	
			setactorvar[THISACTOR].playerdrunk 0
			setplayer[THISACTOR].movement_lock 0
			action PSTAND
			spawn PDEAD_FATALITY1
			setvar pmultivar 0
			setvar fatalvar 0
			setvar fataldead 0
			resetplayer
		}
	    break
	  }
	  ifaction PDEAD2
	  {
		setplayer[THISACTOR].posx fx
		setplayer[THISACTOR].posy fy
		setplayer[THISACTOR].posz fz
		setplayer[THISACTOR].weapon_pos 20
		ifactioncount 3
        move PSTOPED
		quote 13
	    ifhitspace
		{
			setactorvar[THISACTOR].playerdrunk 0
			setplayer[THISACTOR].movement_lock 0
			action PSTAND
			spawn PDEAD_FATALITY1
			setvar pmultivar 0
			setvar fataltmp 0
			setvar fatalvar 0
			setvar fataldead 0
			resetplayer
		}
	    break
	  }

	  ifvarg HEALTHAMOUNT 20 { setvar pmultivar 0 }
  }
  
  ifsquished
  {
    strength -1
    sound SQUISHED
    state random_ooz
    break
  }

  ifp ponsteroids
  {
    ifp pstanding nullop
    else
      spawn FRAMEEFFECT1
  }

  ifmove PSHRINKING
  {
    ifcount 32
    {
      ifcount SHRUNKDONECOUNT
      {
        move 0
        cstat 257
      }
      else
        ifcount SHRUNKCOUNT
      {
        sizeto 42 36
        ifgapzl 24
        {
          strength 0
          sound SQUISHED
          palfrom 48 64
          break
        }
      }
      else
        ifp ponsteroids
          count SHRUNKCOUNT
    }
    else
    {
      ifp ponsteroids
        count SHRUNKCOUNT
      else
      {
        sizeto 8 9
        spawn FRAMEEFFECT1
      }
    }
  }
  else ifhitweapon
  {
	  state bloodsprayshit
	  ifdead { ifrnd 96 sound DIE1 else ifrnd 96 sound DIE2 else sound DIE3 } else
	    {
			ifvarg HEALTHAMOUNT 89 sound DUKE_LONGTERM_PAIN else
			ifvarg HEALTHAMOUNT 79 ifvarl HEALTHAMOUNT 90 sound DUKE_LONGTERM_PAIN2 else
			ifvarg HEALTHAMOUNT 69 ifvarl HEALTHAMOUNT 80 sound DUKE_LONGTERM_PAIN3 else
			ifvarg HEALTHAMOUNT 59 ifvarl HEALTHAMOUNT 70 sound DUKE_LONGTERM_PAIN6 else
			ifvarg HEALTHAMOUNT 49 ifvarl HEALTHAMOUNT 60 sound DUKE_LONGTERM_PAIN5 else
			ifvarg HEALTHAMOUNT 39 ifvarl HEALTHAMOUNT 50 sound DUKE_LONGTERM_PAIN4 else
			ifvarg HEALTHAMOUNT 29 ifvarl HEALTHAMOUNT 40 sound PAIN1 else
			ifvarg HEALTHAMOUNT 19 ifvarl HEALTHAMOUNT 30 sound DUKE_LONGTERM_PAIN8 else
			ifvarg HEALTHAMOUNT 0 ifvarl HEALTHAMOUNT 20 sound DUKE_LONGTERM_PAIN7
	    }
	    ifstrength TOUGH
	    {
	      state headhitstate
	      sound DUKE_GRUNT
		}

	    ifwasweapon RPG
	    {
	      ifrnd 32
	        spawn BLOOD
	      ifdead
		  ifvarn DEATHMASK_ON 1
	        state standard_pjibs
	      palfrom 48 52
	      break
	    }
	    ifwasweapon RADIUSEXPLOSION
	    {
	      ifrnd 32
	        spawn BLOOD
	      ifdead
	        state standard_pjibs
			stopsound PLAY1118 stopsound PLAY1119 stopsound PLAY1120 ifrnd 96 sound DIE1 else ifrnd 96 sound DIE2 else sound DIE3
	      palfrom 48 52
	      break
	    }
	    ifwasweapon FIREEXT
	    {
	      ifrnd 32
	        spawn BLOOD
	      ifdead
	        state standard_pjibs
	      palfrom 48 52
	      break
	    }
	    ifwasweapon SHOTSPARK1
	      palfrom 24 48
	    ifwasweapon COOLEXPLOSION1
	      palfrom 48 48 0 48
	    ifwasweapon KNEE
	      palfrom 16 32
	    ifwasweapon FIRELASER
	      palfrom 32 32

	    ifdead
	    {
	      action PTHROWNBACK
	      //tossweapon
	    }

	    state random_wall_jibs

	    break
  }

  ifinwater
  {
    ifaction PTREDWATER
    {
      ifp pwalking prunning
        action PSWIMMINGGO
    }
    else
      ifp pstanding pwalkingback prunningback
        action PTREDWATER
    else
    {
      ifaction PSWIMMING
      {
        ifrnd 4
          spawn WATERBUBBLE
        ifactioncount 4
          action PSWIMMINGWAIT
      }
      else
        ifaction PSWIMMINGWAIT
      {
        ifactioncount 2
          action PSWIMMINGGO
      }
      else
        ifaction PSWIMMINGGO
      {
        ifactioncount 2
          action PSWIMMING
      }
      else
        action PTREDWATER
    }

    ifrnd 4
      spawn WATERBUBBLE // For effect

    break
  }
  else ifp pjetpack
  {
    ifaction PJPHOUVER
    {
      ifactioncount 4
        resetactioncount
    }
    else
      action PJPHOUVER
    break
  }
  else
  {
    ifaction PTREDWATER
      action PSTAND
    ifaction PSWIMMING
      action PSTAND
    ifaction PSWIMMINGWAIT
      action PSTAND
    ifaction PSWIMMINGGO
      action PSTAND
    ifaction PJPHOUVER
      action PFALLING
  }

  ifaction PFALLING
  {
    ifp ponground
      action PSTAND
    else
    {
      ifp pfalling
        break
      else
        state check_pstandard
    }
  }

  ifaction PDUCKING
  {
    ifgapzl 48
    {
      ifp pwalking pwalkingback prunning prunningback
        action PCRAWLING
    }
    else ifp pducking
    {
      ifp pwalking pwalkingback prunning prunningback
        action PCRAWLING
    }
    else
    {
      ifp pstanding
        action PSTAND
      else
        state check_pstandard
    }
  }

  else ifaction PCRAWLING
  {
    ifgapzl 48
    {
      ifp pstanding
        action PCRAWLING
    }
    else
      ifp pducking
    {
      ifp pstanding
        action PDUCKING
    }
    else
    {
      ifp pstanding
        action PSTAND
      else
        state check_pstandard
    }
  }
  else
    ifgapzl 48
      action PDUCKING

  else
    ifaction PJUMPING
  {
    ifp ponground
      action PSTAND
    else
      ifactioncount 4
        ifp pfalling
          action PFALLING
  }

  ifp pfalling
    action PFALLING
  else
    ifaction PSTAND
      state check_pstandard
  else
    ifaction PAKICKING
  {
    ifactioncount 2
      action PSTAND
    break
  }
  else
    ifaction PWALK
  {
    ifp pfalling
      action PFALLING
    else
      ifp pstanding
        action PSTAND
    else
      ifp prunning
        action PRUN
    else
      ifp pwalkingback
        action PWALKBACK
    else
      ifp prunningback
        action PRUNBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }

  else
    ifaction PRUN
  {
    ifp pstanding
      action PSTAND
    else
      ifp pwalking
        action PWALK
    else
      ifp pwalkingback
        action PWALKBACK
    else
      ifp prunningback
        action PRUNBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }

  else
    ifaction PWALKBACK
  {
    ifp pstanding
      action PSTAND
    else
      ifp pwalking
        action PWALK
    else
      ifp prunning
        action PRUN
    else
      ifp prunningback
        action PRUNBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }

  else
    ifaction PRUNBACK
  {
    ifp pstanding
      action PSTAND
    else
      ifp pwalking
        action PWALK
    else
      ifp prunning
        action PRUN
    else
      ifp pwalkingback
        action PWALKBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }
 enda
 
 useractor notenemy CALEBLYINGDEAD
 sizeat 32 32 fall cstat 256
 ifhitweapon { state jibs_state killit }
 enda
 
 useractor notenemy PDEAD_FATALITY1
 sizeat 32 32 fall cstat 256
 ifhitweapon { state jibs_state killit }
 enda
 
  useractor notenemy PDEAD_FATALITY2
 sizeat 32 32 fall cstat 256
 ifhitweapon { state jibs_state killit }
 enda
 
 onevent EVENT_JUMP
 setactor[THISACTOR].extra 300
 endevent