eventloadactor MULTIBUTTON
    getactor[THISACTOR].hitag HITAGSAVED
    getactor[THISACTOR].lotag LOTAGSAVED
    setactor[THISACTOR].hitag 0
    setactor[THISACTOR].lotag 0
	//state find_rx_tx_cannels
	getactor[THISACTOR].zvel tr_bits
enda

spritenopal MULTIBUTTON
actor MULTIBUTTON

getactor[THISACTOR].sectnum sectnum
getsector[sectnum].floorshade tmp
setactor[THISACTOR].shade tmp

getactor[THISACTOR].pal pal
ifvare pal 1 { ifmultiplayer setactor[THISACTOR].pal 0 else killit }

	ifpdistl 1024 ifp palive 
	{
		ifhitspace {
			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 RETURN RETURN spriteid RETURN RETURN RETURN 0x81c10030h //2208432128 //4294901808
			ifvare buttonhit 0 ifvarvare spriteid THISACTOR 
			{
				ifvarn HITAGSAVED 0 { soundvar HITAGSAVED } else soundonce QLATCH2
				ifaction 0 { action ONE } else ifaction ONE { action TWO } 
				else ifaction TWO { action THREE } else ifaction THREE { action FOUR } 
				else ifaction FOUR { action FIVE } else ifaction FIVE { action 0 }
				
				ifvare LOTAGSAVED 1 ifaction 0 { setactorvar[THISACTOR].active 1 } else 
				ifvare LOTAGSAVED 2 ifaction ONE { setactorvar[THISACTOR].active 1 } else
				ifvare LOTAGSAVED 3 ifaction TWO { setactorvar[THISACTOR].active 1 } else
				ifvare LOTAGSAVED 4 ifaction THREE { setactorvar[THISACTOR].active 1 } else
				ifvare LOTAGSAVED 5 ifaction FOUR { setactorvar[THISACTOR].active 1 } else
				ifvare LOTAGSAVED 6 ifaction FIVE { setactorvar[THISACTOR].active 1 } else setactorvar[THISACTOR].active 0
		
				setvar buttonhit 1
			}
		} else setvar buttonhit 0
	} 
	
ifvare active 1 { ifvare peractor 0 { state rx_cansetactive setvar peractor 1 } } else
{
ifvare peractor 1 
{
	getactor[THISACTOR].yvel tx_can 
	ifvarn tx_can 0
	{
		setvar sectorid 0
		whilevarvarn sectorid NUMSECTORS 
		{
			headspritesect spriteid sectorid
			whilevarn spriteid -1 
			{
				//getactor[spriteid].xvel rx_can
				getactorvar[spriteid].se_xvel rx_can
				ifvarvare tx_can rx_can { getactorvar[spriteid].active tmp ifvarg tmp 0 subvar tmp 1 setactorvar[spriteid].active tmp  }
				nextspritesect spriteid spriteid
			}
			addvar sectorid 1
		}
	}

setvar peractor 0
}
}
enda

eventloadactor MULTIBUTTON2
    getactor[THISACTOR].hitag HITAGSAVED
    getactor[THISACTOR].lotag LOTAGSAVED
    setactor[THISACTOR].hitag 0
    setactor[THISACTOR].lotag 0
	getactor[THISACTOR].zvel tr_bits
	setactor[THISACTOR].zvel 0
	getactor[THISACTOR].owner save_keytime
	ifvarl save_keytime 1
		setvar save_keytime 0
enda

spritenopal MULTIBUTTON2
actor MULTIBUTTON2
getactor[THISACTOR].sectnum sectnum
getsector[sectnum].floorshade tmp
setactor[THISACTOR].shade tmp

getactor[THISACTOR].pal pal
ifvare pal 1 { ifmultiplayer setactor[THISACTOR].pal 0 else killit }

	ifpdistl 1024 ifp palive 
	{
		ifhitspace {
			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 RETURN RETURN spriteid RETURN RETURN RETURN 0x81c10030h //2208432128 //4294901808
			ifvare peractor 0 ifvarvare spriteid THISACTOR 
			{
				ifvarn HITAGSAVED 0 { soundvar HITAGSAVED } else soundonce QLATCH2
				ifaction 0 { action ONE } else ifaction ONE { action TWO } 
				else ifaction TWO { action THREE } else ifaction THREE { action 0 } 
				
				ifvarn sprite[THISACTOR].yvel 0
				{
					setvar sectorid 0
					whilevarvarn sectorid NUMSECTORS 
					{
						headspritesect spriteid sectorid
						whilevarn spriteid -1 
						{
							ifvarvare sprite[THISACTOR].yvel actorvar[spriteid].se_xvel { 
								getactor[spriteid].picnum picnum
								ifvare picnum TRIGGER { getactorvar[spriteid].active tmp addvar tmp 1 setactorvar[spriteid].active tmp } else {
								getactorvar[spriteid].active tmp ifvare tmp 1 { setactorvar[spriteid].active 0 } else setactorvar[spriteid].active 1 }
								setactorvar[spriteid].activatedby THISACTOR
								ifvare actorvar[spriteid].status 1 setactorvar[spriteid].status 0 else setactorvar[spriteid].status 1
							}
							nextspritesect spriteid spriteid
						}
						addvar sectorid 1
					}
				}
				setvarvar key_time save_keytime
				setvar peractor 1
				setvar COUNTER 0
			}
		} else { ifvare key_time 0 setvar peractor 0 }
	} 
	
	ifvarg key_time 0 { addvar COUNTER 1 ifvarvarg COUNTER key_time { setvar peractor 0 setvar COUNTER 0 } }

enda

state activatekey
ifvarvare rx_can tx_can 
{ 
	getactor[spriteid].picnum picnum
	ifvare picnum TRIGGER { getactorvar[spriteid].active tmp addvar tmp 1 setactorvar[spriteid].active tmp } else {
	getactorvar[spriteid].active tmp ifvare tmp 1 { setactorvar[spriteid].active 0 } else setactorvar[spriteid].active 1 }
	setactorvar[spriteid].activatedby THISACTOR
	ifvare actorvar[spriteid].status 1 setactorvar[spriteid].status 0 else setactorvar[spriteid].status 1
}
ends

state switchon_button
cstat 32768
	ifvare active 1
	{
		ifvare peractor 0
		{ 
				
				getactor[THISACTOR].yvel tx_can 
				ifvarn tx_can 0
				{
					setvar sectorid 0
					whilevarvarn sectorid NUMSECTORS 
					{
						headspritesect spriteid sectorid
						whilevarn spriteid -1 
						{
							getactorvar[spriteid].se_xvel rx_can
							ifvarvare rx_can tx_can 
							{
								setactorvar[spriteid].active 1
								setactorvar[spriteid].activatedby THISACTOR
								ifvare htowner 1
								{
									setactorvar[spriteid].se_xvel 0
								}
							}
							nextspritesect spriteid spriteid
						}
						addvar sectorid 1
					}
				}
			
			setvar peractor 1 
		}
		ifvare htowner 1 ifvare peractor 0 nullop else ifvare htowner -1 { setvar peractor 0 setvar active 0 }
	}
ends

state switchoff_button
	cstat 32768
	ifvare active 1
	{
		ifvare peractor 0
		{ 
			getactor[THISACTOR].yvel tx_can 
			ifvarn tx_can 0
			{
				setvar sectorid 0
				whilevarvarn sectorid NUMSECTORS 
				{
					headspritesect spriteid sectorid
					whilevarn spriteid -1 
					{
						getactorvar[spriteid].se_xvel rx_can
						ifvarvare rx_can tx_can 
						{
							setactorvar[spriteid].active 0
							ifvare sprite[spriteid].picnum 1 {
								setactorvar[spriteid].activate_autoclose 1
								setactorvar[spriteid].COUNTER actorvar[spriteid].autoclose_delay
							}
							ifvare htowner 1
							{
								setactorvar[spriteid].se_xvel 0
							}
						}
						nextspritesect spriteid spriteid
					}
					addvar sectorid 1
				}
			}
			
			setvar peractor 1 
		}
		ifvare htowner 1 ifvare peractor 0 nullop else ifvare htowner -1 { setvar peractor 0 setactorvar[THISACTOR].active 0 }
	}
ends

state shotswitch_button

getactor[THISACTOR].htextra htextra
	ifvarg htextra 0
	{
		getactor[THISACTOR].htpicnum but_htpic
		ifvare but_htpic SHOTSPARK1
		ifvare buttonhit 0
		{
			ifvarn HITAGSAVED 0 { soundvar HITAGSAVED }
			ifaction 0 
			{ 
				  
					getactor[THISACTOR].yvel tx_can 
					ifvarn tx_can 0
					{
						setvar sectorid 0
						whilevarvarn sectorid NUMSECTORS 
						{
							headspritesect spriteid sectorid
							whilevarn spriteid -1 
							{
								getactorvar[spriteid].se_xvel rx_can
								state activatekey
								nextspritesect spriteid spriteid
							}
							addvar sectorid 1
						}
					}
				
				action ONE 
			} else 
			ifaction ONE 
			{ 
				  
					getactor[THISACTOR].yvel tx_can 
					ifvarn tx_can 0
					{
						setvar sectorid 0
						whilevarvarn sectorid NUMSECTORS 
						{
							headspritesect spriteid sectorid
							whilevarn spriteid -1 
							{
								getactorvar[spriteid].se_xvel rx_can
								state activatekey
								nextspritesect spriteid spriteid
							}
							addvar sectorid 1
						}
					}
				
				action 0 
			}
			operateactivators LOTAGSAVED THISACTOR
			operaterespawns LOTAGSAVED
			operatemasterswitches LOTAGSAVED
			ifvare htowner 1 { setvar button_off 1 } 
			resetcount
			setvar buttonhit 1
		}
		setactor[THISACTOR].htextra -1
	} else ifcount 26 { ifvare button_off 1 nullop else setvar buttonhit 0 }
ends

state activeswitch_button
	cstat 32768

	getactor[THISACTOR].pal pal
	ifvarn pal 1
	{
	
		ifvare active 1
		ifvare key_time 0 
		{
			ifaction 0 
			{ 
				state se64_check 
							
				ifvare SERETURN 0
				{  
					getactor[THISACTOR].yvel tx_can 
					ifvarn tx_can 0
					{
						setvar sectorid 0
						whilevarvarn sectorid NUMSECTORS 
						{
							headspritesect spriteid sectorid
							whilevarn spriteid -1 
							{
								getactorvar[spriteid].se_xvel rx_can
								ifvare HITAGSAVED 0 state activatekey else
								{ ifvare switch_access 1 state activatekey }
								nextspritesect spriteid spriteid
							}
							addvar sectorid 1
						}
					}
				}
				action ONE 
			} else
			ifvare htowner -1
			ifaction ONE 
			{ 
				state se64_check 
				ifvare SERETURN 0
				
				{  
					getactor[THISACTOR].yvel tx_can 
					ifvarn tx_can 0
					{
						setvar sectorid 0
						whilevarvarn sectorid NUMSECTORS 
						{
							headspritesect spriteid sectorid
							whilevarn spriteid -1 
							{
								getactorvar[spriteid].se_xvel rx_can
								ifvare HITAGSAVED 0 state activatekey else
								ifvare switch_access 1 state activatekey
								nextspritesect spriteid spriteid
							}
							addvar sectorid 1
						}
					}
				}
				action 0 
			}
			ifvare htowner 1 //одноразовая
			ifvare peractor 0 
			{ 
				operateactivators LOTAGSAVED THISACTOR
				operaterespawns LOTAGSAVED
				operatemasterswitches LOTAGSAVED 
				setvar peractor 1 
			} else 
			ifvare htowner -1
			{	
				getactorvar[THISACTOR].save_keytime key_time
				operateactivators LOTAGSAVED THISACTOR
				operaterespawns LOTAGSAVED
				operatemasterswitches LOTAGSAVED
				setactorvar[THISACTOR].active 0
			}
		}
		ifvarg key_time 0 { subvarvar key_time 1 }
		ifvarl key_time 1 { setactorvar[THISACTOR].active 0 setvar key_time 0 }
	} else ifvare pal 1
	{
	ifvare active 1
	{
		ifvare peractor 0
		{ 
				getactor[THISACTOR].yvel tx_can 
				ifvarn tx_can 0
				{
					setvar sectorid 0
					whilevarvarn sectorid NUMSECTORS 
					{
						headspritesect spriteid sectorid
						whilevarn spriteid -1 
						{
							getactorvar[spriteid].HITAGSAVED rx_can
							ifvarvare rx_can tx_can 
							{
								getactorvar[spriteid].switch_access tmp
								ifvare tmp 0 setactorvar[spriteid].switch_access 1 else setactorvar[spriteid].switch_access 0
							}
							nextspritesect spriteid spriteid
						}
						addvar sectorid 1
					}
				}
			setvar peractor 1 
		}
		ifvare htowner 1 ifvare peractor 0 nullop else ifvare htowner -1 { setvar peractor 0 setactorvar[THISACTOR].active 0 }
	}
	}
ends

state wallbrok_button
cstat 32768
ifvare active 1
	{
		ifvare peractor 0
		{ 
			getactor[THISACTOR].yvel tx_can 
			ifvarn tx_can 0
			{
				setvar wallid 0
				whilevarvarn wallid NUMWALLS
				{
					setvarvar wall_extra WALL_EXTRA[wallid]
					ifvarg wall_extra 0 ifvarvare tx_can wall_extra
					{
						setwall[wallid].cstat 32768
						getwall[wallid].nextwall wallid2
						setwall[wallid2].cstat 32768
					}
					addvar wallid 1
				}
			}	
			setvar peractor 1 
		}
		ifvare htowner 1 ifvare peractor 0 nullop else ifvare htowner -1 { setvar peractor 0 setactorvar[THISACTOR].active 0 }
	}
ends



state keyswitch

ifvare switch_active 1 {
	action ONE setvar switch_active 0
}
					
getactorvar[THISACTOR].se_xvel switch_rx
getactor[THISACTOR].sectnum sectnum
getsector[sectnum].floorshade tmp
setactor[THISACTOR].shade tmp

getactor[THISACTOR].pal pal
ifvare pal 1 ifvarn tr_bits 7 { ifmultiplayer setactor[THISACTOR].pal 0 else killit }

ifvare htowner 2
ifvare key_action 0
{
	ifaction 0 
	{ 
			getactor[THISACTOR].yvel tx_can 
			ifvarn tx_can 0
			{
				setvar sectorid 0
				whilevarvarn sectorid NUMSECTORS 
				{
					headspritesect spriteid sectorid
					whilevarn spriteid -1 
					{
						getactorvar[spriteid].se_xvel rx_can
						state activatekey
						nextspritesect spriteid spriteid
					}
					addvar sectorid 1
				}
			}
		
		action ONE 
	}
	setvar key_action 1
} else
ifvare htowner 3
ifvare key_action 0
{
	ifaction 0 
	{ 
		  
			getactor[THISACTOR].yvel tx_can 
			ifvarn tx_can 0
			{
				setvar sectorid 0
				whilevarvarn sectorid NUMSECTORS 
				{
					headspritesect spriteid sectorid
					whilevarn spriteid -1 
					{
						getactorvar[spriteid].se_xvel rx_can
						state activatekey
						nextspritesect spriteid spriteid
					}
					addvar sectorid 1
				}
			}
		
		action ONE 
	}
	setvar key_action 1
}

ifvare tr_bits 11 state wallbrok_button else
ifvare tr_bits 10 state switchon_button else //включающая кнопка
ifvare tr_bits 9 state switchoff_button else //выключающая кнопка
ifvare tr_bits 8 state shotswitch_button else //кнопка для выстрелов
ifvare tr_bits 7 state activeswitch_button
else
{	
	ifpdistl 1024 ifp palive
	{
		ifhitspace
		{	
			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 RETURN RETURN spriteid RETURN RETURN RETURN 0x81c10030h //2208432128 // 4294901808 //1+64+128+256+32768 = 33217
			
			
			ifvarvare spriteid THISACTOR
			ifvare buttonhit 0
			{
				ifvare switch_rx 0
				{
					ifvare peractor 0
					{
						ifvarvarn VAR_SKULLKEY 1
						ifvare tr_bits 1
						{
							quote 137
							soundonce 473
							setvar peractor 1
						} else
						ifvarvarn VAR_EYEKEY 1
						ifvare tr_bits 2
						{
							quote 137
							soundonce 473
							setvar peractor 1
						} else
						ifvarvarn VAR_FIREKEY 1
						ifvare tr_bits 3
						{
							quote 137
							soundonce 473
							setvar peractor 1
						} else
						ifvarvarn VAR_DAGGERKEY 1
						ifvare tr_bits 4
						{
							quote 137
							soundonce 473
							setvar peractor 1
						} else
						ifvarvarn VAR_SPIDERKEY 1
						ifvare tr_bits 5
						{
							quote 137
							soundonce 473
							setvar peractor 1
						} else
						ifvarvarn VAR_MOONKEY 1
						ifvare tr_bits 6
						{
							quote 137
							soundonce 473
							setvar peractor 1
						}
						else
						{
							ifvarn HITAGSAVED 0 { soundvar HITAGSAVED }
							
							ifaction 0 
							{
									getactor[THISACTOR].yvel tx_can 
									ifvarn tx_can 0
									{
										setvar sectorid 0
										whilevarvarn sectorid NUMSECTORS 
										{
											headspritesect spriteid sectorid
											whilevarn spriteid -1 
											{
												getactorvar[spriteid].se_xvel rx_can
												state activatekey
												nextspritesect spriteid spriteid
											}
											addvar sectorid 1
										}
									}
								
								action ONE 
							} else 
							ifaction ONE 
							{ 
								getactor[THISACTOR].yvel tx_can 
								ifvarn tx_can 0
								{
									setvar sectorid 0
									whilevarvarn sectorid NUMSECTORS 
									{
										headspritesect spriteid sectorid
										whilevarn spriteid -1 
										{
											getactorvar[spriteid].se_xvel rx_can
											state activatekey
											nextspritesect spriteid spriteid
										}
										addvar sectorid 1
									}
								}
								action 0 
							}
							operateactivators LOTAGSAVED THISACTOR
							operaterespawns LOTAGSAVED
							operatemasterswitches LOTAGSAVED
							getactorvar[THISACTOR].save_keytime key_time
							setvar peractor2 0
							setvar peractor 1
							ifvare peractor 1 ifvare htowner 1 { setvar button_off 1 } else
							ifvare peractor 1 ifvare htowner 3 { setvar button_off 1 }
						}
					}
				} 
				else
				{	
					ifvarn active 0
					{
						ifvare peractor 0
						{
							operateactivators LOTAGSAVED THISACTOR
							operaterespawns LOTAGSAVED
							operatemasterswitches LOTAGSAVED
							ifvarn HITAGSAVED 0 { soundvar HITAGSAVED }
							ifaction 0 { action ONE } else ifaction ONE { action 0 }
							getactor[THISACTOR].yvel tx_can 
							ifvarn tx_can 0
							{
								setvar sectorid 0
								whilevarvarn sectorid NUMSECTORS 
								{
									headspritesect spriteid sectorid
									whilevarn spriteid -1 
									{
										getactorvar[spriteid].se_xvel rx_can
										state activatekey
										nextspritesect spriteid spriteid
									}
									addvar sectorid 1
								}
							}
							setvar peractor 1
							ifvare peractor 1 ifvare htowner 1 { setvar button_off 1 } 
						} 
					}
				}
				setvar buttonhit 1
			}
		}
		else
		{
			ifvare button_off 0 { ifvarl key_time 1 setvar peractor 0 }
			checkactivatormotion LOTAGSAVED ifvare RETURN 0 setvar buttonhit 0
		}
	}
	ifvarg key_time 0 subvarvar key_time 1
	ifvare switch_action1 1 ifvare key_time 1 { ifaction 0 action ONE else ifaction ONE action 0 }
}
ends

state button_loadactor
						
	getactor[THISACTOR].hitag HITAGSAVED
    getactor[THISACTOR].lotag LOTAGSAVED
    setactor[THISACTOR].hitag 0
    setactor[THISACTOR].lotag 0

	//state find_rx_tx_cannels
	getactor[THISACTOR].cstat acstat
	ifvarand acstat 256 { xorvar acstat 256 setactor[THISACTOR].cstat acstat }
	getactor[THISACTOR].zvel tr_bits
	getactor[THISACTOR].owner htowner
	setvarvar save_keytime sprite[THISACTOR].extra
	ifvarl save_keytime -1 {
		mulvar save_keytime -1
		setvar switch_action1 1
	} 
	
	ifvare tr_bits 11
	{
		getactor[THISACTOR].yvel tx_can 
		ifvarn tx_can 0
		{
			setvar sectorid 0
			whilevarvarn sectorid NUMSECTORS 
			{
				getsector[sectorid].wallptr wallptr
				getsector[sectorid].wallnum wallnum
				setvar tmp 0
				ifvarl wallnum 1 break
				whilevarvarn tmp wallnum
				{ 
					getwall[wallptr].extra wall_extra
					ifvarg wall_extra 0 
					{
						setarray WALL_EXTRA[wallptr] wall_extra
					}

					addvar wallptr 1
					addvar tmp 1
				}
				addvar sectorid 1
			}
		}				
	}				
					
					
ends

eventloadactor BL_BUTTON1
  state button_loadactor  
enda

eventloadactor BL_BUTTON1ON
  state button_loadactor  
  cactor BL_BUTTON1
  setvar switch_active 1
enda

useractor 4  BL_BUTTON1
state keyswitch
enda

eventloadactor BL_BUTTON2
    state button_loadactor
enda

useractor 4 BL_BUTTON2
state keyswitch
enda

eventloadactor BL_BUTTON3
    state button_loadactor
enda

useractor 4  BL_BUTTON3
state keyswitch
enda

eventloadactor BL_BUTTON4
    state button_loadactor
enda

useractor 4  BL_BUTTON4
state keyswitch
enda

eventloadactor BL_BUTTON5
    state button_loadactor
enda

useractor 4  BL_BUTTON5
state keyswitch
enda

eventloadactor BL_BUTTON6
    state button_loadactor
enda

useractor 4  BL_BUTTON6
state keyswitch
enda

eventloadactor LIGHT_SWITCH
    state button_loadactor
enda

useractor 4  LIGHT_SWITCH
state keyswitch
enda

eventloadactor WHEEL
    state button_loadactor
enda

useractor 4  WHEEL
state keyswitch
enda

eventloadactor EXITBUTTON
    getactor[THISACTOR].hitag HITAGSAVED
    getactor[THISACTOR].lotag LOTAGSAVED
    setactor[THISACTOR].hitag 0
    setactor[THISACTOR].lotag 0
enda

state eol_state
ifvarn LOTAGSAVED 16384
{
setvarvar EOL_LEVEL LOTAGSAVED
setvar EOL_VAR 1 } else setvar EOG_VAR 1

setvar stat14_load 0
setvar spriteid 0
				whilevarn spriteid 16384
				{
					getactor[spriteid].picnum picnum
					ifvarn picnum APLAYER
					{
						setactor[spriteid].xvel 0
						setactor[spriteid].yvel 0
						setactor[spriteid].zvel 0
						setactor[spriteid].owner -1
						setactor[spriteid].extra -1
						setactor[spriteid].cstat 0
						setactor[spriteid].hitag 0
						setactor[spriteid].lotag 0
						//setactor[spriteid].statnum 0
						changespritestat spriteid 0 
						setactor[spriteid].ang 0
						setactor[spriteid].clipdist 32
						setactor[spriteid].shade 0
						setactor[spriteid].pal 0
						
						setactorvar[spriteid].active 0
						setactorvar[spriteid].trigger_id_numbers 0
						setactorvar[spriteid].trshoot_var 0 
						setactorvar[spriteid].switch_access 0
						setactorvar[spriteid].obj_statnum 0
						setactorvar[spriteid].triggerlink 0
						setactorvar[spriteid].peractor 0
						setactorvar[spriteid].se_xvel 0
						setactorvar[spriteid].mover_rid 0
						setactorvar[spriteid].obj_zvel 0
						setactorvar[spriteid].obj_lotag 0
						setactorvar[spriteid].stat14_cstat 0
						setactorvar[spriteid].sprite_wall -1
						setactorvar[spriteid].obj_hitag 0
						setactorvar[spriteid].obj_extra 0
						setactorvar[spriteid].obj_sound 0
						setactorvar[spriteid].multisw_stat16 0
						setactorvar[spriteid].acstat 0
						setactorvar[spriteid].obj_picplus 0
						setactorvar[spriteid].stat14_kill 0
						setactorvar[spriteid].savez 0
						setactorvar[spriteid].enemy_opendr 0
						setactorvar[spriteid].le_syncid 0
					}
					ifvarl spriteid 4096
					{ setarray SECT_SHADE[spriteid] 0 }
					addvar spriteid 1
				}
				
	setvar active 0
ends

actor EXITBUTTON

getactor[THISACTOR].zvel tr_bits
ifvare tr_bits 1
{
	ifpdistl 1024 ifp palive
	{
		ifhitspace {	
			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 RETURN RETURN spriteid RETURN RETURN RETURN 0x81c10030h //4294901808

			ifvare buttonhit 0 ifvarvare spriteid THISACTOR
			{
				state eol_state
				setvar buttonhit 1
			}
		} else setvar buttonhit 0
	}
} else
ifvare tr_bits 0
{		
	cstat 32768
	ifvare active 1
	{
		ifvarg HITAGSAVED 0 subvar HITAGSAVED 3 else
		ifvare HITAGSAVED 0 { state eol_state } else
		ifvarl HITAGSAVED 0 { state eol_state }
	}
}
enda


eventloadactor BL_MULTISWITCH
	getactor[THISACTOR].hitag HITAGSAVED
    getactor[THISACTOR].lotag LOTAGSAVED
    setactor[THISACTOR].hitag 0
    setactor[THISACTOR].lotag 0

	getactor[THISACTOR].cstat acstat
	ifvarand acstat 256 { xorvar acstat 256 setactor[THISACTOR].cstat acstat }
	getactor[THISACTOR].zvel tr_bits
	getactor[THISACTOR].extra tmp
	setactorvar[THISACTOR].save_keytime tmp
enda

actor BL_MULTISWITCH 

ifvarn multisw_stat16 1
{
	getactorvar[THISACTOR].se_xvel switch_rx
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade tmp
	setactor[THISACTOR].shade tmp

	ifpdistl 1024 ifp palive
	{
		ifhitspace
		{	
			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 RETURN RETURN spriteid RETURN RETURN RETURN 0x81c10030h
	
			ifvare buttonhit 0
			ifvare key_time 0
			ifvarvare spriteid THISACTOR
			{
				ifvare switch_rx 0
				{
					ifvare peractor 0
					{
						ifaction NO action ONE else
						ifaction ONE action TWO else 
						ifaction TWO action THREE else
						ifaction THREE action NO
						
							getactor[THISACTOR].yvel tx_can 
							ifvarn tx_can 0
							{
								setvar sectorid 0
								whilevarvarn sectorid NUMSECTORS 
								{
									headspritesect spriteid sectorid
									whilevarn spriteid -1 
									{
										getactorvar[spriteid].se_xvel rx_can
										ifaction NO { getactor[THISACTOR].yvel tx_can addvar tx_can 2 } else
										ifaction ONE { getactor[THISACTOR].yvel tx_can addvar tx_can 0 } else 
										ifaction TWO { getactor[THISACTOR].yvel tx_can addvar tx_can 1 } else 
										ifaction THREE { getactor[THISACTOR].yvel tx_can addvar tx_can 2 } 
										ifvarvare rx_can tx_can 
										{ 
											ifvare actorvar[spriteid].status 0 {
												ifvare actorvar[spriteid].active 0
													setactorvar[spriteid].active 1
												else setactorvar[spriteid].active 0
												setactorvar[spriteid].activatedby THISACTOR
												setactorvar[spriteid].status 1
											}
											setvarvar key_time save_keytime
										}
										
										ifaction ONE { getactor[THISACTOR].yvel tx_can addvar tx_can -1 } else 
										ifaction TWO { getactor[THISACTOR].yvel tx_can addvar tx_can 0 } else 
										ifaction THREE { getactor[THISACTOR].yvel tx_can addvar tx_can 1 } 
										ifvarvare rx_can tx_can 
										{ 
											ifvare actorvar[spriteid].status 1 {
												ifvare actorvar[spriteid].active 0
													setactorvar[spriteid].active 1
												else setactorvar[spriteid].active 0
												setactorvar[spriteid].status 0
											}
											getactorvar[THISACTOR].save_keytime key_time
										}
										nextspritesect spriteid spriteid
									}
									addvar sectorid 1
								}
							}
								

						setvar peractor 1
					}
				}
				setvar buttonhit 1
			}
		} else { checkactivatormotion LOTAGSAVED ifvare RETURN 0 setvar buttonhit 0 setvar peractor 0 }
	}
	ifvarg key_time 0 { subvarvar key_time 1 }
	ifvarl key_time 1 { setvar active 0 setvar key_time 0 }
}
enda


eventloadactor SWITCHER
cstat 32768
getactor[THISACTOR].hitag hitag
getactor[THISACTOR].xvel xvel
getactor[THISACTOR].yvel yvel
getactor[THISACTOR].zvel zvel
getactor[THISACTOR].owner htowner
getactor[THISACTOR].extra extra

espawn BL_BUTTON2
setactor[RETURN].pal 1
setactor[RETURN].xvel zvel
setactorvar[RETURN].se_xvel zvel
setactor[RETURN].yvel xvel
setactor[RETURN].zvel 7
setactorvar[RETURN].tr_bits 7
setactorvar[RETURN].htowner htowner
setactorvar[RETURN].save_keytime extra

espawn BL_BUTTON2
setactor[RETURN].xvel xvel
setactorvar[RETURN].se_xvel xvel
setactor[RETURN].yvel yvel
setactor[RETURN].zvel 7
setactorvar[RETURN].tr_bits 7
setactorvar[RETURN].HITAGSAVED xvel
setactorvar[RETURN].htowner htowner
setactorvar[RETURN].save_keytime extra
ifvare hitag 1 setactorvar[RETURN].switch_access 1
killit
enda


//использование стены как кнопку

state aplayer_hitwall
ifvarn HITWALL -1
{
	ifvarg wall[HITWALL].picnum 5120
	ifhitspace ifvarg sector[HITSECTOR].lotag -1 ifvarl sector[HITSECTOR].lotag 3
	{	
		getwall[HITWALL].lotag wallactivator_lotag
		getwall[HITWALL].hitag wallactivator_hitag
	
		ifvarg wallactivator_lotag 0
		ifvarn wallactivator_lotag 511 //Glass wall, but masked walls doesn't works as button
		{
				getplayer[THISACTOR].posx px
				getplayer[THISACTOR].posy py
				getplayer[THISACTOR].posy pz
				setvarvar wallactivator_x HITX
				setvarvar wallactivator_y HITY
				subvarvar wallactivator_x px
				subvarvar wallactivator_y py
				mulvarvar wallactivator_x wallactivator_x
				mulvarvar wallactivator_y wallactivator_y
				addvarvar wallactivator_x wallactivator_y
				sqrt wallactivator_x wallactivator_dist
		} else 
		ifvarg wallactivator_hitag 0 ifvarn wallactivator_hitag 1 ifvarn wallactivator_hitag 9999 //9999 - hitag for SE31, 32
		{
				getplayer[THISACTOR].posx px
				getplayer[THISACTOR].posy py
				getplayer[THISACTOR].posy pz
				setvarvar wallactivator_x HITX
				setvarvar wallactivator_y HITY
				subvarvar wallactivator_x px
				subvarvar wallactivator_y py
				mulvarvar wallactivator_x wallactivator_x
				mulvarvar wallactivator_y wallactivator_y
				addvarvar wallactivator_x wallactivator_y
				sqrt wallactivator_x wallactivator_dist
		} else setvar wallactivator_dist -1
		
		ifvarl wallactivator_dist 1278 ifvarn wallactivator_dist -1
		{
				ifvare wallactivator_hitspace 0
				{	
					ifvarg wallactivator_lotag 0
					ifvarn wallactivator_lotag 511
					{
					operateactivators wallactivator_lotag THISACTOR
					operatemasterswitches wallactivator_lotag
					operaterespawns wallactivator_lotag
					}
					ifvarg wallactivator_hitag 0
					{
						setvar sectorid 0
						whilevarvarn sectorid NUMSECTORS 
						{
							headspritesect spriteid sectorid
							whilevarn spriteid -1 
							{
								getactorvar[spriteid].se_xvel rx_can
								
								ifvarvare wallactivator_hitag rx_can 
								{ 
									getactor[spriteid].picnum picnum
									ifvare picnum TRIGGER { getactorvar[spriteid].active tmp addvar tmp 1 setactorvar[spriteid].active tmp } else {
									getactorvar[spriteid].active tmp ifvare tmp 1 { setactorvar[spriteid].active 0 } else setactorvar[spriteid].active 1 } 
								}
								nextspritesect spriteid spriteid
							}
							addvar sectorid 1
						}
					}
					setvar wallactivator_hitspace 1
				}
		}
	} else setvar wallactivator_hitspace 0
} else { setvar wallactivator_dist -1 setvar wallactivator_lotag 0 }
ends