2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
|
|
|
|
include('shared.lua')
|
|
|
|
|
|
|
|
ENT.WireDebugName = "Sound"
|
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
|
|
|
|
|
|
|
self.Inputs = Wire_CreateInputs(self.Entity, { "A" })
|
|
|
|
end
|
|
|
|
|
2007-07-01 16:21:46 +00:00
|
|
|
function ENT:OnRemove()
|
2007-08-07 19:21:29 +00:00
|
|
|
self.BaseClass.OnRemove(self)
|
|
|
|
self:StopSounds()
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
2007-08-07 19:21:29 +00:00
|
|
|
function ENT:TriggerInput(iname, value)
|
|
|
|
if (iname == "A") then
|
|
|
|
local on = value > 0
|
|
|
|
if (self.on == on) then return end
|
|
|
|
self.on = on
|
|
|
|
if ( on ) then
|
|
|
|
self:SetOverlayText( "Sound: " .. self.sound .. "\nOn" )
|
|
|
|
self:StartSounds()
|
|
|
|
else
|
|
|
|
self:SetOverlayText( "Sound: " .. self.sound .. "\nOff" )
|
|
|
|
self:StopSounds()
|
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-07-01 16:21:46 +00:00
|
|
|
function ENT:SetSound(sound)
|
2007-08-07 19:21:29 +00:00
|
|
|
self:StopSounds()
|
2008-03-07 22:35:34 +00:00
|
|
|
if (sound) then
|
2008-06-11 20:15:59 +00:00
|
|
|
local parsedsound = sound
|
|
|
|
while (string.find(parsedsound,"%s") && (string.find(parsedsound,"%s") == 1)) do
|
|
|
|
parsedsound = string.sub(parsedsound,2,string.len(parsedsound))
|
2008-06-10 19:45:57 +00:00
|
|
|
end
|
2008-06-11 20:15:59 +00:00
|
|
|
util.PrecacheSound(parsedsound)
|
|
|
|
|
|
|
|
self.sound = (parsedsound or ""):gsub("[/\\]+","/")
|
2007-08-07 19:21:29 +00:00
|
|
|
self:SetOverlayText( "Sound: " .. self.sound .. "\nOff" )
|
2007-07-01 16:21:46 +00:00
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
|
|
|
|
2007-08-07 19:21:29 +00:00
|
|
|
function ENT:StartSounds()
|
2008-03-07 22:35:34 +00:00
|
|
|
self:StopSounds(); -- Stop old sounds before
|
|
|
|
self.SND = CreateSound(self.Entity,Sound(self.sound)); -- Create new CSoundPatch (Must be created everytime again, or some people do not hear it)
|
|
|
|
self.SND:Play();
|
2007-08-07 19:21:29 +00:00
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
|
2007-08-07 19:21:29 +00:00
|
|
|
function ENT:StopSounds()
|
|
|
|
if (self.SND) then
|
|
|
|
self.SND:Stop()
|
2008-03-07 22:35:34 +00:00
|
|
|
self.SND = nil;
|
2007-08-07 19:21:29 +00:00
|
|
|
end
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|
2007-12-28 04:22:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
function MakeWireEmitter( pl, Model, Ang, Pos, sound, nocollide, frozen )
|
|
|
|
|
|
|
|
if ( !pl:CheckLimit( "wire_emitters" ) ) then return false end
|
|
|
|
|
|
|
|
local wire_emitter = ents.Create( "gmod_wire_soundemitter" )
|
|
|
|
if (!wire_emitter:IsValid()) then return false end
|
|
|
|
wire_emitter:SetModel( Model )
|
|
|
|
|
|
|
|
wire_emitter:SetAngles( Ang )
|
|
|
|
wire_emitter:SetPos( Pos )
|
|
|
|
wire_emitter:Spawn()
|
2008-02-06 01:21:09 +00:00
|
|
|
|
|
|
|
if wire_emitter:GetPhysicsObject():IsValid() then
|
|
|
|
local Phys = wire_emitter:GetPhysicsObject()
|
|
|
|
Phys:EnableMotion(!frozen)
|
|
|
|
end
|
|
|
|
|
2007-12-28 04:22:41 +00:00
|
|
|
wire_emitter:SetSound( Sound(sound) )
|
|
|
|
wire_emitter:SetPlayer( pl )
|
|
|
|
|
|
|
|
local etable = {
|
|
|
|
pl = pl,
|
2008-02-06 01:21:09 +00:00
|
|
|
sound = sound,
|
2007-12-28 04:22:41 +00:00
|
|
|
nocollide = nocollide
|
|
|
|
}
|
|
|
|
table.Merge(wire_emitter:GetTable(), etable )
|
|
|
|
|
|
|
|
pl:AddCount( "wire_emitters", wire_emitter )
|
|
|
|
|
|
|
|
return wire_emitter
|
|
|
|
|
|
|
|
end
|
|
|
|
duplicator.RegisterEntityClass("gmod_wire_soundemitter", MakeWireEmitter, "Model", "Ang", "Pos", "sound", "nocollide", "frozen")
|