• Function Send.Sound
    13 replies, posted
I made some script for anyway event. So i wanna put some sound effect as broadcast for all player, when trigger has been activated. so this code Hook.Add( "Som", "SomeSent", function( ply, text )     if ply:IsAdmin then         local command = string.Explode( " ", text )         if string.lower(command[1]) == Event then             net.Start( "SomeSent" )                 net.WriteString(Some )                 net.WriteString( someMessage )                 net.WriteInt( BACKGROUND_ENABLED, 7 )                 net.WriteInt( timeInSeconds, 7 )             net.Broadcast()             end         end     end end ) so, from another theme facepunch i found function SendSound(str,ply) -- SendSound("path/to/sound/wav") If you don't give it a player, it will be send to everyone net.Start("SendSound") -- Set the net to use our new network net.WriteString(str) -- Write the sound inside it if type(ply)=="Player" then -- If we got a player .. net.Send(ply) -- .. send it to him only else -- No player? .. net.Broadcast() -- .. send it to everyone end end How this code put in my code on server side? this can be right? util.AddNetworkString("SendSound") Hook.Add( "Som", "SomeSent", function( ply, text )     if ply:IsAdmin then         local command = string.Explode( " ", text )         if string.lower(command[1]) == Event then function SendSound("somewherepath/1.wav")(str,ply)             net.Start( "SomeSent" ) net.Start("SendSound") net.WriteString(str)                 net.WriteString(Some )                 net.WriteString( someMessage )                 net.WriteInt( BACKGROUND_ENABLED, 7 )                 net.WriteInt( timeInSeconds, 7 )             net.Broadcast()             end         end     end end )
Why... why are you running two net.Starts, your not even running your SendSound, your send sound function aint even right. And you are running a hook that doesn't exist. Here's a tip, don't use a hook. Secondly, what is this... function SendSound("somewherepath/1.wav")(str,ply) -- creates function and breaks it lol SendSound( "somewherepath/1.wav", ply ) -- runs function But remember, the hook either has to be called... or u use a function to run it, otherwise doesn't do shit. Where have you defined Event variable, where have you defined timeInSeconds variable, where have you defined someMessage, where have you defined str, where have you defined Some.
Hook.Add( "Som" Som? That hook isnt even a think. With hook.add your not creating a hook, you know that? net.Start( "SomeSent" ) net.Start("SendSound") net.WriteString(str) net.WriteString(Some ) net.WriteString( someMessage ) net.WriteInt( BACKGROUND_ENABLED, 7 ) net.WriteInt( timeInSeconds, 7 ) net.Broadcast() like Superior said, you start 2 net messages, and broadcast only one of it. And the second? Starts and never see its end?
yea, for this place, some little changes and hook is not hook is not possible really, one have to a hard time for a very long time to have it an one little not this permetre to sell her(it) or give her (it)... but btw... i asking how two starts made it and not brooking game and anyway mind
Firstly, I did not understand a single thing you just wrote. Secondly, gmod wiki is right there with many examples you can follow my friend, no hard feelings <3
....what?
okay, if dont use net sound start and paste one fuction, like this SendSound( "somewherepath/1.wav", ply ) it can be worked right? then just usable this? util.AddNetworkString("SendSound") Hook.Add( "Som", "SomeSent", function( ply, text ) if ply:IsAdmin then local command = string.Explode( " ", text ) if string.lower(command[1]) == Event then net.Start( "SomeSent" ) SendSound( "somewherepath/1.wav", ply ) net.WriteString(Some ) net.WriteString( someMessage ) net.WriteInt( BACKGROUND_ENABLED, 7 ) net.WriteInt( timeInSeconds, 7 ) net.Broadcast() end end end end )
your english is.....almost impossible to read.. you cant just do Hook.Add("Som" there is no hook that exists with this name.
u think? Actualy it can be example at random name hook without full code... just wanna know how together made two net.Starts - one is Send.Sound and possible like this?
..i dont understand any word..all i can say is, using the hook "Som" wont work. whatever code you put in there, it NEVER will execute. you need to use a hook that exists, and runs at the condition that you need it for.
Anyway is random name... Why? I love random names. After i will be changed at normal hook name PlayerSay just in case, sry
random names wont make things work or help you in the programming in world. If you program, you always need to spell everything perfectly, no typos. and no random names
Kinda like what Trackster said, but your issue is the fact the hook name doesn't exist in garry's mod lua, you have to make it yourself. Also, when calling your sound function, it runs net.Start twice... go on gmod wiki, read over it, then come back. It will seriously help you, search up the function uses.
You have everything wrong tbh. Please learn about: OOP Hook Library Programming in Lua Programming in Lua 2 Also you can use this (almost the same): if ply then net.Send(ply) else net.Broadcast() end What is BACKGROUND_ENABLED and Event? . If I understand you correctly you want to play sound on client/clients. You can make an net message that transmits soundpath to clients and put it into surface.PlaySound
Sorry, you need to Log In to post a reply to this thread.