eventloadactor BL_RESPAWN

getactor[THISACTOR].lotag LOTAGSAVED
setactor[THISACTOR].lotag 0
getactor[THISACTOR].hitag HITAGSAVED
setactor[THISACTOR].hitag 0
ifvarg HITAGSAVED 0 setvarvar trigger_skill HITAGSAVED else
setvar trigger_skill 31

cstat 32768
getactor[THISACTOR].zvel tr_bits

enda

state findenemy
ifvare tr_bits 1 ifvarl peractor 3 { //респавн, идущий за объектом
	setvar enemyid -1
	getactor[THISACTOR].yvel tx_can
	ifvarn tx_can 0 {	
		setvar sectorid 0
		setvar key_enemyid 0
		whilevarvarn sectorid NUMSECTORS {
			headspritesect spriteid sectorid
			whilevarn spriteid -1 {
				getactorvar[spriteid].se_xvel rx_can
				getactor[spriteid].statnum statnum
				getactor[spriteid].extra extra
				getactor[spriteid].picnum picnum
				ifvarvare rx_can tx_can ifvarn picnum APLAYER { 
					ifvarn statnum 1024 ifvarg extra 0 setvarvar enemyid spriteid
				}
				ifvarvare rx_can tx_can ifvare picnum ZOMBIERISE ifvarn statnum 1024
					setvarvar enemyid spriteid

				nextspritesect spriteid spriteid
			}
			addvar sectorid 1
		}
	} 
	addvar peractor 1
}
ends

actor BL_RESPAWN
getuserdef[THISACTOR].m_player_skill skillit //установка работы респавна при разных уровнях сложности
ifmultiplayer addvar skillit 1
ifvare skillit 3 setvar skillit 4 else ifvare skillit 4 setvar skillit 8 else ifvare skillit 5 setvar skillit 16
getactorvar[THISACTOR].trigger_skill trigger_skill

ifvarvarand trigger_skill skillit
{
	ifvare tr_bits 0
	{
		ifvare active 1 ifvarn LOTAGSAVED 0 {
			espawnvar LOTAGSAVED
			getactor[THISACTOR].xrepeat xrepeat
			getactor[THISACTOR].yrepeat yrepeat
			setactor[RETURN].xrepeat xrepeat
			setactor[RETURN].yrepeat yrepeat
			getactor[THISACTOR].pal pal
			setactor[RETURN].pal pal
			ifvare peractor -1 setactorvar[THISACTOR].active 0 else killit
		}
	} else ifvare tr_bits 1 {
			state findenemy
			ifvarn enemyid -1 ifvare peractor 3 {
				getactor[enemyid].extra extra

				getactor[enemyid].picnum picnum
				ifvare picnum ZOMBIERISE {
					ifvarn actorvar[enemyid].zombie_id -1 {
						setvarvar enemyid actorvar[enemyid].zombie_id
					} 
					
					ifvare actorvar[enemyid].zrise_dead 1 ifvarn LOTAGSAVED 0 {
						getactor[enemyid].x x
						getactor[enemyid].y y
						getactor[enemyid].z z
						getactor[enemyid].statnum astatnum
						setactor[THISACTOR].x x
						setactor[THISACTOR].y y
						setactor[THISACTOR].z z
						//setactor[THISACTOR].statnum astatnum
						changespritestat THISACTOR astatnum
						espawnvar LOTAGSAVED
						getactor[THISACTOR].xrepeat xrepeat
						getactor[THISACTOR].yrepeat yrepeat
						setactor[RETURN].xrepeat xrepeat
						setactor[RETURN].yrepeat yrepeat
						getactor[THISACTOR].pal pal
						setactor[RETURN].pal pal
							//addlogvar enemyid
						killit
					}
					
				} else {
					ifvarg extra 0
					{
					getactor[enemyid].x x
					getactor[enemyid].y y
					getactor[enemyid].z z
					getactor[enemyid].statnum astatnum
					setactor[THISACTOR].x x
					setactor[THISACTOR].y y
					setactor[THISACTOR].z z
					//setactor[THISACTOR].statnum astatnum
					changespritestat THISACTOR astatnum
					} else
					ifvarn LOTAGSAVED 0 {
						espawnvar LOTAGSAVED
						getactor[THISACTOR].xrepeat xrepeat
						getactor[THISACTOR].yrepeat yrepeat
						setactor[RETURN].xrepeat xrepeat
						setactor[RETURN].yrepeat yrepeat
						getactor[THISACTOR].pal pal
						setactor[RETURN].pal pal
							//addlogvar enemyid
						killit
					}
				}
			}
		
	}
}
enda