move RESPAWN_ACTOR_FLAG
move PSTOPED

state checkb_armor
ifvare reflmode 0
ifvare godmode 0
ifvare DEATHMASK_ON 0
ifvarg paextra 0
ifvarg HEALTHAMOUNT 0
{
	getactorvar[PLAYERID].bodyshield BODYSHIELD_AMOUNT
	getactor[PLAYERID].htextra paextra
	ifvarg BODYSHIELD_AMOUNT 0
	{
		divvarvar paextra 2
		setactor[PLAYERID].htextra paextra
		ifvarvarg BODYSHIELD_AMOUNT paextra
		{
			subvarvar BODYSHIELD_AMOUNT paextra
			setactorvar[PLAYERID].bodyshield BODYSHIELD_AMOUNT
		}
		else
		{
			subvarvar BODYSHIELD_AMOUNT paextra	
			addvarvar HEALTHAMOUNT BODYSHIELD_AMOUNT
			setactor[PLAYERID].extra HEALTHAMOUNT
			setactorvar[PLAYERID].bodyshield 0
		}
	}
}
ends

state checkf_armor
ifvare reflmode 0
ifvare godmode 0
ifvare DEATHMASK_ON 0
ifvarg paextra 0
ifvarg HEALTHAMOUNT 0
{
	getactorvar[PLAYERID].fireshield FIRESHIELD_AMOUNT
	ifvarg FIRESHIELD_AMOUNT 0
	{
		divvarvar paextra 2
		setactor[PLAYERID].htextra paextra
		ifvarvarg FIRESHIELD_AMOUNT paextra
		{
			 subvarvar FIRESHIELD_AMOUNT paextra
			 setactorvar[PLAYERID].fireshield FIRESHIELD_AMOUNT
		}
		else
		{
			subvarvar FIRESHIELD_AMOUNT paextra	
			addvarvar HEALTHAMOUNT FIRESHIELD_AMOUNT
			setactor[PLAYERID].extra HEALTHAMOUNT  
			setactorvar[PLAYERID].fireshield 0
		}
	}
}
ends

state firedamage_floor
getplayer[THISACTOR].cursectnum temp
ifvare godmode 0
ifvare DEATHMASK_ON 0
		ifvarn temp -1 
		{
			getplayer[THISACTOR].posx x
			getplayer[THISACTOR].posy y
			getplayer[THISACTOR].posz z
			addvar z 9216
			getflorzofslope temp x y mz
			subvarvar mz z
			ifvarl mz 1280
			ifp palive
			{
				getactorvar[PLAYERID].fireshield FIRESHIELD_AMOUNT
				ifvarg FIRESHIELD_AMOUNT 0
				{
					ifcount 2 {  addphealth -1 subvarvar FIRESHIELD_AMOUNT 1 resetcount }
					setactorvar[PLAYERID].fireshield FIRESHIELD_AMOUNT
				} else addphealth -1
				soundonce PLAY1118
				//palfrom 16 16
			}
		}
ends

state checks_armor
ifvare reflmode 0
ifvare godmode 0
ifvare DEATHMASK_ON 0
ifvarg paextra 0
ifvarg HEALTHAMOUNT 0
{
	getactorvar[PLAYERID].spiritshield SPIRITSHIELD_AMOUNT
	ifvarg SPIRITSHIELD_AMOUNT  0
	{	
		divvarvar paextra 2
		setactor[PLAYERID].htextra paextra
		ifvarvarg SPIRITSHIELD_AMOUNT paextra
		{
			 subvarvar SPIRITSHIELD_AMOUNT paextra
			 setactorvar[PLAYERID].spiritshield SPIRITSHIELD_AMOUNT
		} 
		else
		{
			subvarvar SPIRITSHIELD_AMOUNT paextra	
			addvarvar HEALTHAMOUNT SPIRITSHIELD_AMOUNT
			setactor[PLAYERID].extra HEALTHAMOUNT
			setactorvar[PLAYERID].spiritshield 0
		}
	}
}
ends

state checkhitscan

	getplayer[THISACTOR].posx px
	getplayer[THISACTOR].posy py
	getplayer[THISACTOR].posz pz
	getplayer[THISACTOR].cursectnum psector
	getplayer[THISACTOR].ang pang
	getplayer[THISACTOR].horiz phoriz
	subvar phoriz 100
	mulvar phoriz -2048
	cos mycos pang
	sin mysin pang

	ifvarn psector -1 hitscan px py pz psector mycos mysin phoriz HITSECTOR HITWALL HITSPRITE HITX HITY HITZ 4294901808 //1

	//inittimer 240 
	
	setvarvar deb_x px
	setvarvar deb_y py
	setvarvar deb_z pz
	setvarvar deb_psect DOCTORSBAGON
	ifvarn HITSPRITE -1
	{
		getactor[HITSPRITE].picnum debug_picnum
		getactor[HITSPRITE].cstat debug_cstat
		getactor[HITSPRITE].extra debug_extra
		getactor[HITSPRITE].htextra deb_htextra
		getactorvar[HITSPRITE].active debug_active
		getactorvar[HITSPRITE].se_xvel deb_se_x
		getactor[HITSPRITE].xvel debug_rx
		getactor[HITSPRITE].yvel debug_tx
		getactorvar[HITSPRITE].HITAGSAVED deb_hitag
		getactorvar[HITSPRITE].LOTAGSAVED deb_lotag
		getactorvar[HITSPRITE].obj_statnum deb_statnum
		getactorvar[HITSPRITE].stat14_cstat debug_cs14
		getactorvar[HITSPRITE].activatedby debug_actby
		
		ifhitspace {
			setvarvar deb_getid HITSPRITE
		}
		
	} else
	{
		setvar debug_cstat 0
		setvar debug_extra 0
		setvar debug_active 0
		setvar deb_htextra 0 
		setvar debug_picnum 0
		setvar deb_se_x 0
		setvar debug_rx 0
		setvar debug_tx 0
		setvar deb_hitag 0
		setvar deb_lotag 0
		setvar deb_statnum 0
		setvar debug_cs14 0
	}

ends

state check_pstandard
  ifp pwalking
    action PWALK
  else
    ifp pkicking
      action PAKICKING
  else
    ifp pwalkingback
      action PWALKBACK
  else
    ifp prunning
      action PRUN
  else
    ifp prunningback
      action PRUNBACK
  else
    ifp pjumping
      action PJUMPING
  else
    ifp pducking
      action PDUCKING
ends


state quikweaponget
  palfrom 32 0 32
  ifgotweaponce 1
    break
  killit
ends

state getweaponcode

  palfrom 32 0 32
  ifgotweaponce 1
    break
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
    killit
ends

state respawnit
  ifcount RESPAWNITEMTIME
  {
    spawn TRANSPORTERSTAR
    move 0
    cstat 0
    sound TELEPORTER
  }
ends

state getcode
  palfrom 16 0 32
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
    killit
ends

state quikget
  palfrom 16 0 32
  killit
ends


state lndstate
switch picnum
		case 5260
		case 5240
		case 5390
		case 5398
		case 5420
		case 5421
		case 5424
		case 5425
		case 5426
		case 5427
		case 5428
		case 5435
		case 5475
		case 5481
		case 5482
		case 5510
		case 5542
		case 5574
		case 6127
		case 6128
		case 6249
		case 7568
		soundonce LNDDIRT
		break
		case 255
		case 5315
		case 5320
		case 5329
		case 5386
		case 5496
		case 5558
		case 5611
		case 5612
		case 5620
		case 5625
		case 6164
		case 7666
		case 9729
		soundonce LNDMETAL
		break
		case 5135
		case 5140
		case 5141
		case 5148
		case 5154
		case 5162
		case 5169
		case 5187
		case 5188
		case 5290
		case 5295
		case 5370
		case 5376
		case 5456
		case 5572
		case 6027
		case 9730
		case 9731
		soundonce LNDWOOD
		break
		case 5350
		case 5354
		case 5361
		case 6150
		case 6240
		case 8035
		soundonce LNDWATER
		break
		default
		soundonce LNDSTONE
		break
endswitch
ends

onevent EVENT_JUMP
setvar RETURN -1
endevent

actor APLAYER MAXPLAYERHEALTH PSTAND 0 0
ifawayfromwall setvar phitobj 0 else setvar phitobj 1

ifvarg player[THISACTOR].weapon_pos 0
	setvarvar current_weapon player[THISACTOR].curr_weapon

ifvarn CURRWEAP 5 ifvare player[THISACTOR].weapon_pos 0 {
	ifvarn WEAPON_VAR_TNT 1 {
		ifvarg TNT_AMMOAMOUNT 0
			setvar WEAPON_VAR_TNT 1
		else {
			ifvarg PROXIMITYMINE_AMMOAMOUNT 0 setvar WEAPON_VAR_TNT 2 else
			ifvarg REMOTETNT_AMMOAMOUNT 0 setvar WEAPON_VAR_TNT 3 else setvar WEAPON_VAR_TNT 1
		}
	}
}

getplayer[THISACTOR].hard_landing tmp
ifvarg tmp 0 {
	//p->horiz -= (p->hard_landing<<4);
	getplayer[THISACTOR].horiz phoriz
	shiftvarl tmp 4
	addvarvar phoriz tmp
	setplayer[THISACTOR].horiz phoriz
}

getinput[THISACTOR].bits num
ifvarand num 1 {
	ifvare pjumphit 0 ifp ponground {
		setplayer[THISACTOR].jumping_counter 1
		setvar pjumphit 1
	}
} else { 
	setvar pjumphit 0
	getplayer[THISACTOR].posxv tmp
	mulvar tmp 10
	divvar tmp 11
	setplayer[THISACTOR].posxv tmp
	getplayer[THISACTOR].posyv tmp
	mulvar tmp 10
	divvar tmp 11
	setplayer[THISACTOR].posyv tmp
}
iffloordistl 32 //чтобы игрок не получал урон от падения, устанавливаем время падения на минимум
{
	ifvarl player[THISACTOR].falling_counter 17 //увеличение безболезненную высоту падения
		setplayer[THISACTOR].falling_counter 8
	
}
  
  
setplayer[THISACTOR].ammo_amount 0 100
ifsound DUKE_LAND 
{
	


	getplayer[THISACTOR].spritebridge tmp //sbs
	ifvare tmp 1 
	{ 
		getplayer[THISACTOR].sbs spriteid
		getactor[spriteid].picnum picnum
		state lndstate
	} else
	{
		getplayer[THISACTOR].cursectnum psectnum
		ifvarn psectnum -1 getsector[psectnum].floorpicnum picnum
		state lndstate
	}
}	

//setplayer[THISACTOR].over_shoulder_on 0 //вид от 3го лица
getplayer[THISACTOR].scream_voice tmp
ifvarg tmp 0 soundonce FALL

state checkhitscan	

getactorvar[THISACTOR].bodyshield BODYSHIELD_AMOUNT
getactorvar[THISACTOR].fireshield FIRESHIELD_AMOUNT
getactorvar[THISACTOR].spiritshield SPIRITSHIELD_AMOUNT
ifvare BODYSHIELD_AMOUNT 0 ifvarn SAVED_BODYSHIELD 0 { setactorvar[THISACTOR].bodyshield SAVED_BODYSHIELD setvar SAVED_BODYSHIELD 0 }
ifvare FIRESHIELD_AMOUNT 0 ifvarn SAVED_FIRESHIELD 0 { setactorvar[THISACTOR].fireshield SAVED_FIRESHIELD setvar SAVED_FIRESHIELD 0 }
ifvare SPIRITSHIELD_AMOUNT 0 ifvarn SAVED_SPIRITSHIELD 0 { setactorvar[THISACTOR].spiritshield SAVED_SPIRITSHIELD setvar SAVED_SPIRITSHIELD 0 }

ifvarg QUAKETIME 0 subvarvar QUAKETIME 1 else setvar QUAKEACTIVE 0
ifvare EOG_VAR 1 { addvar EOG_TMP 1 modvar EOG_TMP 2400 } else setvar EOG_TMP 0

state aplayer_hitwall

setplayer[THISACTOR].frag_ps 0
setplayer[THISACTOR].max_actors_killed TOTALKILLS

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

setactorvar[THISACTOR].width 128
setactorvar[THISACTOR].height 8192


	state weaponchangestate
	state weaponplayerstate

getactor[THISACTOR].xvel pspeed
getactor[THISACTOR].mdflags  tmp
orvar  tmp 16
setactor[THISACTOR].mdflags  tmp


ifvarg quotecount_1 0 subvar quotecount_1 1
ifvare quotecount_1 0 { setarray QUOTES[0] 0 }
ifvarg quotecount_2 0 subvar quotecount_2 1
ifvare quotecount_2 0 { setarray QUOTES[1] 0 }
ifvarg quotecount_3 0 subvar quotecount_3 1
ifvare quotecount_3 0 { setarray QUOTES[2] 0 }
ifvarg quotecount_4 0 subvar quotecount_4 1
ifvare quotecount_4 0 { setarray QUOTES[3] 0 }

ifp palive
{
	ifvarg haha_enabled 0 {
		addvar haha_var 1
		ifvarg haha_var 30 {
			ifvare haha_enabled 1 { soundonce HAHA1 setvar haha_enabled 0 }
			ifvare haha_enabled 2 { soundonce HAHA2 setvar haha_enabled 0 }
			ifvare haha_enabled 3 { soundonce HAHA3 setvar haha_enabled 0 }
			ifvare haha_enabled 4 { soundonce HAHA4 setvar haha_enabled 0 }
			ifvare haha_enabled 5 { soundonce HAHA5 setvar haha_enabled 0 }
			ifvare haha_enabled 6 { soundonce HAHA6 setvar haha_enabled 0 }
			ifvare haha_enabled 7 { soundonce HAHA7 setvar haha_enabled 0 }
			ifvare haha_enabled 8 { soundonce HAHA8 setvar haha_enabled 0 }
			setvar haha_var 0
		}
	}
	/*
	ifvarg haha_enabled 0 
	ifvare haha_var 0
	{ 
		ifrnd 32 ifvarl haha_enabled 3 { soundonce HAHA1 setvar haha_enabled 0 } else
		{
			ifvarg haha_count 13 { setvar haha_var 1 setvar haha_count 0 } else
			addvar haha_count 1 
		}	
	}
	ifvare haha_var 1
	{
		ifvarg haha_enabled 6 ifvarl haha_enabled 9 { stopsound HAHA1 ifrnd 64 { soundonce HAHA2 setvar haha_var 2 } else setvar haha_var 0 setvar haha_enabled 0 } 
		ifvarg haha_enabled 8 ifvarl haha_enabled 11 { ifrnd 128 { soundonce HAHA3 setvar haha_var 2 } else setvar haha_var 0 setvar haha_enabled 0 } 
		ifvarg haha_enabled 10 ifvarl haha_enabled 13 { ifrnd 128 { soundonce HAHA4 setvar haha_var 2 } else setvar haha_var 0 setvar haha_enabled 0 } 
	    ifvarg haha_enabled 12 ifvarl haha_enabled 15 { soundonce HAHA5 setvar haha_var 2 setvar haha_enabled 0 }
		ifvarg haha_enabled 14 ifvarl haha_enabled 17 { soundonce HAHA6 setvar haha_var 2 setvar haha_enabled 0 }
		ifvarg haha_enabled 16 ifvarl haha_enabled 19 { soundonce HAHA7 setvar haha_var 2 setvar haha_enabled 0 }
		ifvarg haha_enabled 18 { soundonce HAHA8 setvar haha_var 2 setvar haha_enabled 0 }
	}
	ifvarg haha_var 1 //чтобы звуки смеха не накладывались друг на друга
	{
		addvar haha_var 1
		ifvarg haha_var 56 { setvar haha_var 0 setvar haha_enabled 0 }
	}
	*/
}
		
		
getactorvar[PLAYERID].reflective reflmode
getuserdef[PLAYERID].god godmode

	ifwasweapon SHOTSPARK1 { state checkb_armor } else
	ifwasweapon RADIUSEXPLOSION { state checkf_armor } else
	ifwasweapon PR_NAPALM { state checkf_armor } else
	ifwasweapon TCHERNMISSLE { state checkf_armor } else
	ifwasweapon ALTNAPALM { state checkf_armor } else
	ifwasweapon BUCHERSLIME { state checks_armor } else
	ifwasweapon BUCHERFLYAXE { state checkb_armor } else
	ifwasweapon PHANTOMSKULL { state checks_armor } else
	ifwasweapon STAFFALTPROJ { state checks_armor }

state cheataplayerstate
	
getplayer[THISACTOR].cursectnum psectnum
ifvarn psectnum -1 {
	getplayer[THISACTOR].posx x
	getplayer[THISACTOR].posy y
	getplayer[THISACTOR].posz z
	addvar z 9216
	getflorzofslope psectnum x y mz
	subvarvar mz z
	ifvarl mz 1280
	{
		headspritesect spriteid psectnum
		whilevarn spriteid -1 
		{
			ifvare sprite[spriteid].picnum SECTOREFFECTOR
			{
				getactor[spriteid].lotag lotag
				ifvare lotag 69
				{
					getsector[psectnum].lotag lotag
					ifvarn lotag 1
					{
						ifvare actorvar[spriteid].rot_moving 1 ifvare actorvar[spriteid].moving_var 0
						{
							getplayer[THISACTOR].posz z
							addvar z 128
							addvarvar z actorvar[spriteid].acc_defvel
							setplayer[THISACTOR].posz z
						}
					}
				}
			}
			nextspritesect spriteid spriteid
		}
	}
}

/*
ifvarg paextra 0
{
		getactor[THISACTOR].htang htang
		setvarvar in1 htang 
		setvarvar in2 paextra
ifvarg 	paextra 100
{
	mulvarvar paextra -30
	setvarvar in3 paextra
}	else setvarvar in3 0
		state physics_start
		state phys_reset_vel
		state phys_add_vel_ang
		state physics_end		
		
		setactorvar[THISACTOR].phys_air_damping_x 1040
		setactorvar[THISACTOR].phys_air_damping_y 1040
		setactorvar[THISACTOR].phys_air_damping_z 1050	
		setactorvar[THISACTOR].phys_wall_damping_x 1350 
		setactorvar[THISACTOR].phys_wall_damping_y 1350
		setactorvar[THISACTOR].phys_wall_damping_z 1050 		
			
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		randvar tmp 200
		addvar tmp 400
		setactorvar[THISACTOR].phys_gravity_z tmp
}

	state physics_start
	state physics_interact_air
	movesprite THISACTOR 0 0 0 CLIPMASK0 phys_movfalg_interanl
	getplayer[THISACTOR].posx px
	getplayer[THISACTOR].posy py
	addvarvar px phys_x_internal
	addvarvar py phys_y_internal
	setplayer[THISACTOR].posx px
	setplayer[THISACTOR].posy py
	
	ifvarl phys_z_internal 0
	{
	getplayer[THISACTOR].posz pz
	addvarvar pz phys_z_internal
	setplayer[THISACTOR].posz pz
	}
	state physics_interact_walls
	state physics_end
*/


getactorvar[THISACTOR].playerdrunk DRUNKCOUNT
ifvarg DRUNKCOUNT 0
{
	addvar hz1 8
	andvar hz1 2047
	setvarvar hz2 hz1
	mulvar hz2 2
	palfrom 32 0 0 0
	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 1 } else addvar phandcount 2
	ifvarg phandcount 30 setvar phandcount 30
	
	ifhitspace 
	{
		ifvare phandspace 0
		{ 
			ifrnd 127 { subvar phandcount 30 } else ifrnd 127 { subvar phandcount 20 } else subvar phandcount 50
			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 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 }
}

ifvare player[THISACTOR].crack_time 1 
{
	randvar pvoices 8
	switch pvoices
	case 0 sound VOICE1 break
	case 1 sound VOICE2 break
	case 2 sound VOICE3 break
	case 3 sound VOICE4 break
	case 4 sound VOICE5 break
	case 5 sound VOICE6 break
	case 6 sound VOICE7 break
	case 7 sound VOICE8 break
	case 8 sound VOICE9 break
	endswitch
}

getactorvar[THISACTOR].playervoice playervoice
ifvarn playervoice -1 ifp palive { soundvar playervoice setactorvar[THISACTOR].playervoice -1 }

ifvarg pfire 0 { 
	addvar COUNTER 1 
	ifinwater { setvar COUNTER 0 setvar pfire 0 }
	ifvarvarg COUNTER 182 { setvar pfire 0 setvar flamedamage 0 setvar COUNTER 0 } 
}

ifvarg flamedamage 0 ifp palive
{ 
	ifvarg flamedamage 200 { setvar flamedamage 200 }
	subvar flamedamage 1
	
	state newfirestate 
	ifvare godmode  0 {
		ifvare p_scream 0 { ifrnd 96 setvar p_scream 1 else ifrnd 96 setvar p_scream 2 else setvar p_scream 3 } else addvar scream_timer 1
		ifvare p_scream 1 { soundonce PLAY1118 ifvarg scream_timer 90 { stopsound PLAY1118 setvar scream_timer 0 setvar p_scream 0 } } else 
		ifvare p_scream 2 { soundonce PLAY1119 ifvarg scream_timer 60 { stopsound PLAY1119 setvar scream_timer 0 setvar p_scream 0 } } else 
		ifvare p_scream 3 { soundonce PLAY1120 ifvarg scream_timer 60 { stopsound PLAY1120 setvar scream_timer 0 setvar p_scream 0 } }
	}
	ifinwater { setvar flamedamage 0 }
	//ifvarvarg COUNTER flamedamage { setvar scream_timer 0 setvar p_scream 0 stopsound PLAY1118 stopsound PLAY1119 stopsound PLAY1120 setvar flamedamage 0 setvar COUNTER 0 } 
} else { setvar scream_timer 0 setvar p_scream 0 
	ifp palive {
		ifvarn sector[THISACTOR].hitag 40 ifvarn sector[THISACTOR].hitag 41 {
			stopsound PLAY1118 stopsound PLAY1119 stopsound PLAY1120 
		} 
	} else stopsound PLAY1118 stopsound PLAY1119 stopsound PLAY1120 
}

ifvarg pcount 0 { subvar pcount 1 } else setactorvar[THISACTOR].animspritevar -1


ifvare fire_shoot 1 
{ 
ifvare CURRWEAP 2 ifvare player[THISACTOR].kickback_pic 1 state playerfirestate
ifvare CURRWEAP 3 state playerfirestate
ifvare CURRWEAP 7 { state playerfirestate setactor[RETURN].pal 10 }
setvar fire_shoot 0 
}

ifvare reflective 1
{
	ifvarn player[THISACTOR].palette 1 setgamepalette 1
	addvar REFLTIME 1
	ifvarg paextra 0
	{
		getactor[THISACTOR].htowner spriteid
		ifvarvarn spriteid THISACTOR ifvarn spriteid -1
		{
			getactor[spriteid].extra extra
			ifvarg extra 0
			{
				ifvare sprite[THISACTOR].htpicnum 2595 {
					setactorvar[spriteid].gethurt paextra
					setactor[THISACTOR].htextra -1
				}
			}
		}
	}
	ifvare REFLTIME 1 { espawn PREFLBALL setactorvar[RETURN].spriteid THISACTOR }
	ifvare REFLTIME 780 { setactorvar[THISACTOR].reflective 0 setvar REFLTIME 0 }
} else ifinwater nullop else ifvarn player[THISACTOR].palette 0 setgamepalette 0

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

ifvare burningguyactive 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 
	setvar burningguyactive 0 
	setvar flamedamage 0 
	setvar COUNTER 0 
}

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

getactor[THISACTOR].htpicnum htpicnum
switch htpicnum
case 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 }
break
case STAFFPROJ
getactor[THISACTOR].htowner temp
ifvarvare temp PLAYERID {
	setactor[temp].htextra -1
	setactor[temp].htpicnum -1
}
break;
case BUCHERSLIME
case BUCHERFLYAXE
case BUCHERAXE
case GABGBONE
case PHANTOMSKULL
case PR_NAPALM
ifvarg paextra 0 {
	palfrom 8 8
}
break
endswitch


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

ifonwater {
	getplayer[THISACTOR].posx x
	getplayer[THISACTOR].posy y
	getplayer[THISACTOR].posz z
	getplayer[THISACTOR].cursectnum psector
	addvar z 9216
	ifvarn psector -1 {
		getflorzofslope psector x y mz
		subvarvar mz z
		ifvarl mz 128 ifvarg player[THISACTOR].poszv 255
		{
			ifvare psplashvar 0
			{
				sound SUBMERGE
				setvar psplashvar 1
			}
		} else setvar psplashvar 0
	}
} else setvar psplashvar 0

ifinwater { 
	setvar emergevar 1
} else setvar pdiving 0

ifvare godmode 0
ifvare player[THISACTOR].airleft 0
ifvare player[THISACTOR].scuba_on 0
ifp palive
{ 

	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
	soundonce UNDCHOKE setactorsoundpitch THISACTOR UNDCHOKE 0 setvar airleft 1 
}
getactor[THISACTOR].sectnum num
getsector[num].lotag lotag
ifvare lotag 1 { ifvare airleft 1 { ifp palive { stopsound UNDCHOKE sound PAIN6 setvar airleft 0 } } else ifp palive ifvare emergevar 1 { soundonce EMERGE setvar emergevar 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 ifvare BEASTVON 1 { setvar BEASTVON 0 setvar VISION 0 state other_item }

// DIVING SUIT ACTION
ifvarg DIVINGSUITAM 0
{
	ifinwater
	ifvare DIVINGSUITON 1
	{
	setplayer[THISACTOR].scuba_on 1
	setplayer[THISACTOR].airleft 390
	subvar DIVINGSUITAM 1
	} else { setvar DIVINGSUITON 0 setplayer[THISACTOR].scuba_on 0 }
} else ifvare DIVINGSUITON 1 { state other_item 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

ifvare JBOOTSON 0
{
	getplayer[THISACTOR].cursectnum psectnum
	ifvarn psectnum -1
	{
		getsector[psectnum].lotag lotag
		getsector[psectnum].floorz z2
		getplayer[THISACTOR].posz z
		subvarvar z2 z
		ifvarg z2 30000
		ifvarn lotag 2
		{
			getplayer[THISACTOR].posz z
			getplayer[THISACTOR].oposz z2
			setvarvar z3 z2
			subvarvar z2 z
			ifvarg z2 3000 { setplayer[THISACTOR].poszv 7000 setplayer[THISACTOR].posz z3 }
		}
	}
}

getplayer[THISACTOR].jumping_counter jumping //Увеличение высоты прыжка игрока
ifvarg jumping 0
{	
	ifvare pjumpingvar 0
	{
		getplayer[THISACTOR].cursectnum psectnum
		ifvarn psectnum -1
		{
		getsector[psectnum].floorz z2
		getplayer[THISACTOR].posz z
		subvarvar z2 z
		setvarvar pwaterz z2
		getsector[psectnum].lotag plotag
		}
		setvar pjumpingvar 1
	}
	ifvare plotag 1 ifvarl pwaterz 6600 { ifvare JBOOTSON 0 setplayer[THISACTOR].poszv 500 } else
	ifvare jumping 721 { setplayer[THISACTOR].poszv -2300 ifvare JBOOTSON 0 setplayer[THISACTOR].jumping_counter 0 } 

} else setvar pjumpingvar 0

ifvarg BOOTSOFJUMPINGAM 0
{
	ifvare JBOOTSON 1
	{
		subvar BOOTSOFJUMPINGAM 1
		getplayer[THISACTOR].cursectnum psectnum
		ifvarn psectnum -1 getsector[psectnum].lotag lotag
		
		ifvare lotag 1 //не давать игроку пригыть с ботинками в воде
		{
			getplayer[THISACTOR].posx x
			getplayer[THISACTOR].posy y
			getplayer[THISACTOR].posz z
			addvar z 9216
			getflorzofslope psectnum x y mz
			subvarvar mz z
			ifvarl mz 1280 { setvar pjumpboot 1 setplayer[THISACTOR].poszv 500 } else setvar pjumpboot 0
		} else setvar pjumpboot 0
			
		ifvarn pjumpboot 1
		{
			getplayer[THISACTOR].jumping_counter perplayer
			ifvarg perplayer 0 
			{ 
				setplayer[THISACTOR].jumping_counter 377
				getplayer[THISACTOR].poszv pl_poszv
				ifvarl pl_poszv -3696 setplayer[THISACTOR].jumping_counter 0	
			}
			iffloordistl 32 //чтобы игрок не получал урон от падения, устанавливаем время падения на минимум
			{
				getplayer[THISACTOR].falling_counter tmp
				ifvarl tmp 61 //если высота ооочень большая, все равно устанавливается урон
				ifvarg BOOTSOFJUMPINGAM 0
				{
				  setvar tmp 8
				  setplayer[THISACTOR].falling_counter tmp
				}
			}
		}
	}
} else ifvare JBOOTSON 1 { setvar JBOOTSON 0 state other_item }

//CRISTALL BALL

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

// AUTOCLOSE INVMENU

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

 //Thanks to DeeperThought for this code
 
 	// check floor type
	//getsector[THISACTOR].floorpicnum picnum
	//ifvare picnum 5650 { state firedamage_floor }
	//ifvare picnum 5496 { getsector[THISACTOR].floorpal pal ifvare pal 9 { state firedamage_floor } else ifvare pal 30 { state firedamage_floor } }
	//ifvare picnum 6236 { state firedamage_floor }

	getsector[THISACTOR].hitag tmp	
	ifvare tmp 40
	{
		addvar lavasp_count 1
		getplayer[THISACTOR].cursectnum temp
		ifvare godmode 0
ifvare DEATHMASK_ON 0
		ifvarn temp -1 
		{
			getplayer[THISACTOR].posx x
			getplayer[THISACTOR].posy y
			getplayer[THISACTOR].posz z
			addvar z 9216
			getflorzofslope temp x y mz
			subvarvar mz z
			ifvarl mz 1280
			ifp palive
			{
				getactorvar[PLAYERID].fireshield FIRESHIELD_AMOUNT
				ifvarg FIRESHIELD_AMOUNT 0
				{
					ifcount 2 {  addphealth -1 subvarvar FIRESHIELD_AMOUNT 1 resetcount }
					setactorvar[PLAYERID].fireshield FIRESHIELD_AMOUNT
				} else addphealth -1
				soundonce PLAY1118
				ifvarg lavasp_count 8 { spawn LAVASPARK setvar lavasp_count 0 }
				palfrom 16 16
			}
		}
		
		
	} else
	ifvare tmp 41
	{
		addvar lavasp_count 1
		getplayer[THISACTOR].cursectnum temp
		ifvarn temp -1 
		ifvare godmode 0
ifvare DEATHMASK_ON 0
		{
			getplayer[THISACTOR].posx x
			getplayer[THISACTOR].posy y
			getplayer[THISACTOR].posz z
			addvar z 9216
			getflorzofslope temp x y mz
			subvarvar mz z
			ifvarl mz 1280
			{
				ifp palive
				{
					getactorvar[PLAYERID].bodyshield BODYSHIELD_AMOUNT
					ifvarg BODYSHIELD_AMOUNT 0
					{
						ifcount 2 {  addphealth -1 subvarvar BODYSHIELD_AMOUNT 1 resetcount }
						setactorvar[PLAYERID].bodyshield BODYSHIELD_AMOUNT
					} else addphealth -1
					soundonce PLAY1106
					ifvarg lavasp_count 8 { spawn LAVASPARK setvar lavasp_count 0 }
					palfrom 16 16
				}
			}
			
			
		}
	} 
	else ifvare tmp 666
	{
		getplayer[THISACTOR].cursectnum temp
		ifvarn temp -1 
		ifvare godmode 0
ifvare DEATHMASK_ON 0
		{
			getplayer[THISACTOR].posx x
			getplayer[THISACTOR].posy y
			getplayer[THISACTOR].posz z
			addvar z 9216
			getflorzofslope temp x y mz
			subvarvar mz z
			ifvarl mz 1280
			{
				ifp palive
				{
					ifcount 2
					{
						addphealth -33
						palfrom 16 16
						resetcount
					}
				} else 
				ifvare paaction 0
				{
					sound DIE1
					action PTHROWNBACK 
					setvar paaction 1
				}
			}
		}
	}
	

	ifp pjumping ifcount 12 { globalsound JUMP resetcount }
	
	
  ifaction 0
    action PSTAND

  ifdead ifvare godmode 0
  {
	setvar handattack 0 
	setvar active 0
	setplayer[THISACTOR].kickback_pic 0
	setvar COUNTER 0
	setvar pfire 0
	
	setvar reflective 0
	setvar burningguyactive 0
	setvar flamedamage 0
	stopsound PROXDET
	stopsound TNTFUSE
	setvar teslaalt 0
	setvar akimboteslaalt 0
	setvar dtime 0
	setvar tsakimbo 0
	setvar LIGHTERENABLE 0
	setvar TNTCOUNT 0
	setvar SHOOTTNT 0
	setvar sprayfire -1
	setvar pressfire -1
	setvar sprayalt 0

    ifsquished
      palfrom 32 63 63 63
    else
      fall

    ifactioncount 7
      move 0

    ifaction PLYINGDEAD
    {
      ifactioncount 3
        move PSTOPED
	  else ifactioncount 2
		quote 13 
      ifhitspace
      {
        action PSTAND
        spawn CALEBLYINGDEAD
		setvar paaction 0
		
		setvar TNT_AMMOAMOUNT 0
		setvar REMOTETNT_AMMOAMOUNT 0
		setvar PROXIMITYMINE_AMMOAMOUNT 0
		setvar bodyshield 0
		setvar fireshield 0
		setvar spiritshield 0
		setvar SAVED_BODYSHIELD 0
		setvar SAVED_FIRESHIELD 0
		setvar SAVED_SPIRITSHIELD 0
		setvar TOTALKILLS 0
	
        resetplayer
      }
      break
    }

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

    ifaction PEXPLODEAD
    {
      ifhitspace
      {
		setvar TNT_AMMOAMOUNT 0
		setvar REMOTETNT_AMMOAMOUNT 0
		setvar PROXIMITYMINE_AMMOAMOUNT 0
		setvar bodyshield 0
		setvar fireshield 0
		setvar spiritshield 0
		setvar SAVED_BODYSHIELD 0
		setvar SAVED_FIRESHIELD 0
		setvar SAVED_SPIRITSHIELD 0
		setvar TOTALKILLS 0
		
        resetplayer
		setvar paaction 0
        action PSTAND
      }
      break
    }
    ifaction PEXPLODE
    {
      ifactioncount 5
      {
        action PEXPLODEAD
		quote 13
       // spawn BLOODPOOL
      }
      break
    }

     ifinwater
     {
        action PLYINGDEAD
        spawn WATERBUBBLE
        spawn WATERBUBBLE
     }
     else
     {
       action PEXPLODE
	   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
		else ifactioncount 2
		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
			setvar paaction 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
			setvar paaction 0
			resetplayer
		}
	    break
	  }

	  ifvarg HEALTHAMOUNT 20 { setvar pmultivar 0 }
  }
 */ 
 
 
 
  ifsquished
  {
    strength -1
    break
  }
  else ifhitweapon
  {
	  state bloodsprayshit
	  ifdead { ifrnd 96 sound DIE1 else ifrnd 96 sound DIE2 else sound DIE3 } else
	    {
				ifrnd 96 sound PLAY1106 else ifrnd 96 sound PLAY1107 else sound PLAY1108
	    }

	    ifwasweapon RADIUSEXPLOSION
	    {
	      ifrnd 32
	      ifdead { stopsound PLAY1118 stopsound PLAY1119 stopsound PLAY1120 ifrnd 96 sound DIE1 else ifrnd 96 sound DIE2 else sound DIE3 }
	      palfrom 48 52
	      break
	    }
	    ifwasweapon FIREEXT
	    {
	      //ifdead
	        //state standard_pjibs
	      palfrom 48 52
	      break
	    }
	    ifwasweapon SHOTSPARK1
	      palfrom 8 8

	    ifdead
	    {
	      action PTHROWNBACK
	    }
	    break
  }

  ifinwater
  {
	ifvarn player[THISACTOR].palette 1 {
		setgamepalette 1
	}

	ifvarn pdiving 1 {
		ifvarg DIVINGSUITAM 0 {
			setplayer[THISACTOR].inven_icon 9
			setvar DIVINGSUITON 1
		}
		setvar pdiving 1
	}
   
	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
  {
	//setgamepalette 0 //reflectiveball уже изменяет палитру обратно когда это необходимо
    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
 
 
 onevent EVENT_INCURDAMAGE

	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