-- script by 3com
-- Since we can not control StartParticleEmitter(e) function yet, something like amount, density, size, of the particles, in this case toxic gas, 
-- then I decided place 6 bombs, 5 bombs invisible, a just one visible. ( of course you can just let them all visible, i.e. in an sci-fi lab )

switch_on = 0 -- assure switch is on
id = 0 -- control entity number
id_soldier = 0 -- control soldier number

function switch_init(e)
end

function switch_main(e)

PlayerDist = GetPlayerDistance(e)
 if PlayerDist < 100 then
  if g_Entity[e]['activated'] == 0 then
	Prompt("Press E key to activate the bomb")
    if g_KeyPressE == 1 then 
 	  g_Entity[e]['activated'] = 1
    end
  end
	
if g_Entity[e]['activated'] == 1 then
	SetAnimation(0)
	PlayAnimation(e,0)
	g_Entity[e]['animating'] = 1
	g_Entity[e]['activated'] = 2
	ActivateIfUsed(e)
    PlaySound(e,0) -- set the sound you want, in entity properties panel>Sound0
	switch_on = 1
end

if g_Entity[e]['activated'] == 2 and switch_on == 1 then
	--StartParticleEmitter(e) -- uncommented this line if you want the switch throwing gas too.
	StartParticleEmitter(2) -- gas bomb activate - Notice 114 is the entity number (visible bomb). You'll have to get your own, and change it.
	id=5
	-- the others gas bomb activate too.
	--for id = 120,127 do --  -- You'll have to get your own, and change it, too.
		StartParticleEmitter(id)
	--end
	
	-- killing soldiers
for id_soldier = 2,4 do -- You'll have to get your own, and change it, too.
	SetEntityHealth(id_soldier,0)
	if plrHasMask == 0 then -- Place this global variable into your global.lua (plrHasMask = 0)
		SetPlayerHealth(0)  -- if player has not the gas mask, then he will dead.
	end
end

end
 
else
	--StopParticleEmitter(e)
	--StopParticleEmitter(114) -- deactivate bomb when player away from the switch.
	
	--for id = 120,127 do
		StopParticleEmitter(id) -- deactivate the others bombs. (the invisible ones)
	--end
	
	StopSound(e,0)
end
end -- main

function switch_exit(e)
end --exit




