eventloadactor TRIGGERSOUND
	getactor[THISACTOR].hitag HITAGSAVED
    getactor[THISACTOR].lotag LOTAGSAVED
	getactor[THISACTOR].owner trigger_var
    setactor[THISACTOR].hitag 0
    setactor[THISACTOR].lotag 0
	cstat 32768
enda

actor TRIGGERSOUND
getactor[THISACTOR].zvel tr_bits
ifvare tr_bits 0 //active var sound
{
	ifvare active 1 
	{ 
	getplayer[THISACTOR].i PLAYERID
	setactorvar[PLAYERID].playervoice LOTAGSAVED
	ifvare trigger_var 1 killit else setactorvar[THISACTOR].active 0 }
} 
else ifvare tr_bits 1 //player sector
{
	getactor[THISACTOR].ang ang
	getactor[THISACTOR].sectnum sectnum
	getactor[PLAYERID].sectnum sectorid
	ifvare ang 512 {  
		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 2048
			{
				ifvarvare sectnum sectorid { ifvare peractor2 0 { getplayer[THISACTOR].i PLAYERID setactorvar[PLAYERID].playervoice LOTAGSAVED ifvare trigger_var 1 killit setvar peractor2 1 } } else setvar peractor2 0
			}
		}
	} else {
		ifvarvare sectnum sectorid { ifvare peractor2 0 { getplayer[THISACTOR].i PLAYERID setactorvar[PLAYERID].playervoice LOTAGSAVED ifvare trigger_var 1 killit setvar peractor2 1 } } else setvar peractor2 0
	}
}
else ifvare tr_bits 2 //ambient
{
	ifvare active 0 
	{
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getplayer[THISACTOR].posx px
	getplayer[THISACTOR].posy py
	subvarvar x px
	subvarvar y py
	mulvarvar x x
	mulvarvar y y
	addvarvar x y
	sqrt x DIST
	ifvarn HITAGSAVED 0 { ifvarvarl DIST HITAGSAVED soundoncevar LOTAGSAVED else stopsoundvar LOTAGSAVED } else soundoncevar LOTAGSAVED
	} else { stopsoundvar LOTAGSAVED killit }
}
else ifvare tr_bits 3
{
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getplayer[THISACTOR].posx px
	getplayer[THISACTOR].posy py
	subvarvar x px
	subvarvar y py
	mulvarvar x x
	mulvarvar y y
	addvarvar x y
	sqrt x DIST
	ifvare active 1 
	{
		ifvarn HITAGSAVED 0 {
			ifvarvarl DIST HITAGSAVED { setvar peractor 0 ifvare trigger_var 1 soundvar LOTAGSAVED else soundoncevar LOTAGSAVED } else ifvare peractor 0 { stopactorsound THISACTOR LOTAGSAVED setvar peractor 1 } 
		} else { ifvare trigger_var 1 soundvar LOTAGSAVED else soundoncevar LOTAGSAVED }
		
		ifvare trigger_var 1 { setactorvar[THISACTOR].active 0 }
	} //else ifvarvarl DIST HITAGSAVED { stopsoundvar LOTAGSAVED }
}
else ifvare tr_bits 4 //звук через разные промежутки времени
{
	ifvarg active 0
	{
		addvar peractor 1
		ifvarg peractor 2 { randvarvar COUNTER HITAGSAVED setvar peractor 0 }
		ifvare COUNTER 1 { ifvare peractor 1 { soundoncevar LOTAGSAVED } } 
	} 
}
enda