Jump to content

About Adding Sound in Stealth Resource


solidsnake

Recommended Posts

hi all ... :)

i just wanna ask about how can i add sounds when team (red win) -sound 1 & when team (blue win) -sound2

also sounds when player spawn

i read in wiki that (playSound) just only work in client side of script but i cant add it i just can add in Server side under this

if team1survivers > team2survivers then
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( redwinsdisplay, thisplayer )
end
local teampoints = getElementData ( team1, "Score" )
setElementData ( team1, "Score", teampoints+1  )
end	
if team2survivers > team1survivers then
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( bluewinsdisplay, thisplayer )
end

im really dont know well about lua but it least i tried ... i think i'm a bit confused about funiction & event (eventHandler)

i check all client events & function theres nothing such linked(related) with what i want OR maybe need to use more than 1 function & handler idk im dizzy :roll:

Link to comment

You can put some functions in a client-side script file to play the sounds.

Alternatively, use this:

callClientFunction

If you paste the function code into a client script file and a server script file, you can call client functions from the server. I'm not exactly sure if it'd be 100% safe though, but it should be safer than callServerFunction.

Link to comment
  • 4 weeks later...
You can put some functions in a client-side script file to play the sounds.

Alternatively, use this:

callClientFunction

If you paste the function code into a client script file and a server script file, you can call client functions from the server. I'm not exactly sure if it'd be 100% safe though, but it should be safer than callServerFunction.

Great so is there any other way like Call : https://wiki.multitheftauto.com/wiki/Call

call a function in same resources (client) or in other resources ?

i cant understand events things its confused me so i trying to escape from this :P

i just want to play sound

if team1survivers > team2survivers then

sound 1 = playsound( .... )

if team2survivers > team1survivers then

sound 2 = playsound(.....)

Link to comment

callClientFunction is just a custom function which calls client functions through event.

if you have that added, then just call playSound from server for every player (near textDisplayAddObserver in your script) with needed file.

server:

if team1survivers >  team2survivers then
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( redwinsdisplay, thisplayer )
   callClientFunction(thisplayer, "playSound", "sounds/team1ftw.mp3")
end
local teampoints = getElementData ( team1, "Score" )
setElementData ( team1, "Score", teampoints+1  )
end   
if team2survivers > team1survivers then
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( bluewinsdisplay, thisplayer )
   callClientFunction(thisplayer, "playSound", "sounds/ohnoes.mp3")
end

or you can use events:

client:

addEvent("playSomeSound", true)
addEventHandler("playSomeSound", getRootElement(), playSound)

server:

if team1survivers >  team2survivers then
triggerClientEvent("playSomeSound", getRootElement(), "sounds/team1ftw.mp3")
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( redwinsdisplay, thisplayer )
end
local teampoints = getElementData ( team1, "Score" )
setElementData ( team1, "Score", teampoints+1  )
end   
if team2survivers > team1survivers then
triggerClientEvent("playSomeSound", getRootElement(), "sounds/ohnoes.mp3")
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( bluewinsdisplay, thisplayer )
end

Link to comment
callClientFunction is just a custom function which calls client functions through event.

if you have that added, then just call playSound from server for every player (near textDisplayAddObserver in your script) with needed file.

server:

if team1survivers >  team2survivers then
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( redwinsdisplay, thisplayer )
   callClientFunction(thisplayer, "playSound", "sounds/team1ftw.mp3")
end
local teampoints = getElementData ( team1, "Score" )
setElementData ( team1, "Score", teampoints+1  )
end   
if team2survivers > team1survivers then
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( bluewinsdisplay, thisplayer )
   callClientFunction(thisplayer, "playSound", "sounds/ohnoes.mp3")
end

or you can use events:

client:

addEvent("playSomeSound", true)
addEventHandler("playSomeSound", getRootElement(), playSound)

server:

if team1survivers >  team2survivers then
triggerClientEvent("playSomeSound", getRootElement(), "sounds/team1ftw.mp3")
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( redwinsdisplay, thisplayer )
end
local teampoints = getElementData ( team1, "Score" )
setElementData ( team1, "Score", teampoints+1  )
end   
if team2survivers > team1survivers then
triggerClientEvent("playSomeSound", getRootElement(), "sounds/ohnoes.mp3")
local alltheplayers = getElementsByType("player")
for index, thisplayer in ipairs(alltheplayers) do
textDisplayAddObserver( bluewinsdisplay, thisplayer )
end

man i cant belive this you not only fix the problem you also fix the idea in my head about events very very thanks :D now i understand events xD

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...