Emit entity sound from concommand

Hey there,

I’ve made a vending machine SENT, and in the process of polishing it, I came up with the idea to play sounds when the player uses it. However, I’m having issues getting the sound to play individually if multiple SENTs are spawned in. The problem I’m having, is that the system works by the client sending a concommand to the server half of the SENT. Because of that, I cannot access variables or use Entity:EmitSound.

Here is my attempt to explain it:

SENT spawns, this runs on shared:

SetNWInt("VendingID", self:EntIndex())

The player walks up and uses the machine. An interface opens up asking them what they would like to purchase. This runs on the client when the menu opens:

function ENT:Initialize()
    ID = self:GetNetworkedVar("VendingID")

The player then selects what he wants and confirms the selection:

concommand.Add( "vend_interface", function( args )

    // Super secret GUI

    Button.DoClick = function ()
    RunConsoleCommand( "vend_buyitem", arg1, arg2, selection, ID)
    Popup:SetVisible( false )

We move to the server half, the SENT receives the concommand:

concommand.Add( "vend_buyitem", function( ply, cmd, args )

    // Checks if you can afford
    // Removes money if you have it    
    Entity( arg[4] ):EmitSound("path",100,100)

    // Player notification
end )

Strangely, this works if there is only 1 machine spawned. But if more than one is spawned, the sound is emitted from the most recent one.

Any help is appreciated, thanks.

Why don’t you just use,

sound.Play( string Name, Vector Pos, number Level, number Pitch, number Volume )

[editline]9th December 2013[/editline]

you shouldn’t use concommands either, try using the net library

I haven’t tried net library so I’ll give that a shot. So replace the Vector Pos with Entity( args[4] ):GetPos(), I would imagine?