Jump to content

playSound3D [HELP]


Recommended Posts

I want when Bank Robbery will be started, radio into the police cars will advert it for all cops

addEvent("policeradio", true) 
addEventHandler("policeradio", root, 
function() 
local polveh = getElementsByType("vehicle") 
if ( getElementData(polveh,"Service") == "Police" ) then 
policeradio = playSound3D("policead.mp3",x,y,z, true)  
attachElements(polveh, policeradio) 
end 
end 
) 

but when i have opened first door into the bank, debug string said, that getElementData got table WTF ? I have used it with players and Data: Robbery, Robber or Assistant and there are no problems with table... Then i have tried to use ipairs

and then debug string said that:

policeradio got table

attachElements got table

:( Sadness, i can't to create sound in all police cars at the moment when Bank Robbery starting ?

Link to comment
local polveh = getElementsByType("vehicle") 

getElementsByType

Returns

Returns a table containing all the elements of the specified type. Returns an empty table if there are no elements of the specified type. Returns false if the string specified is invalid (or not a string).

I'm gonna help you to understand how to use this.

So, you want it to be triggered for every police vehicle? I guess you mean you mean to every player who is in a police vehicle. That isn't possible from client-side, unless you want to add unnecesary extra processing both for client and server by triggering events from client and back from server.

So, in the server script is where we'll use some of that code you have there.

You gotta paste the following in the part where you trigger the client event. Use your common sense to know if there's something to replace, remove, or add; I'm only explaining how to do this particular stuff work, NOT how to make it compatible to your whole code:

local polveh = getElementsByType("vehicle") 
for i, v in ipairs (polveh) do --Let's loop through every policecar 
if getElementData(polveh,"Service") == "Police" then --I hope the car itself has this element data, not the player 
pl = getVehicleOccupant(polveh) --Let's only retrieve the player who's the driver of a policecar (it isn't a good idea to trigger the event more than once per car) 
triggerClientEvent(root, "policeradio", pl) --trigger that client event to EVERY player that exists (hence that "root") 
end 
end --This "for" loop will be done for every single policecar, remember that! 
  

Now, for the client-side:

addEvent("policeradio", true) 
addEventHandler("policeradio", root, 
function() 
local x, y, z = getElementPosition( source ) 
local polveh = getPedOccupiedVehicle( source ) 
policeradio = playSound3D("policead.mp3",x,y,z, true)  
attachElements(polveh, policeradio) 
end 
end 
) 

This should work.

You can delete my comments (the gray text) when you paste the codes; they're only there to help you understand why and how it all works.

Also, remember to eventually destroy the sound!

Link to comment
local polveh = getElementsByType("vehicle") 

getElementsByType

Returns

Returns a table containing all the elements of the specified type. Returns an empty table if there are no elements of the specified type. Returns false if the string specified is invalid (or not a string).

I'm gonna help you to understand how to use this.

So, you want it to be triggered for every police vehicle? I guess you mean you mean to every player who is in a police vehicle. That isn't possible from client-side, unless you want to add unnecesary extra processing both for client and server by triggering events from client and back from server.

So, in the server script is where we'll use some of that code you have there.

You gotta paste the following in the part where you trigger the client event. Use your common sense to know if there's something to replace, remove, or add; I'm only explaining how to do this particular stuff work, NOT how to make it compatible to your whole code:

local polveh = getElementsByType("vehicle") 
for i, v in ipairs (polveh) do --Let's loop through every policecar 
if getElementData(polveh,"Service") == "Police" then --I hope the car itself has this element data, not the player 
pl = getVehicleOccupant(polveh) --Let's only retrieve the player who's the driver of a policecar (it isn't a good idea to trigger the event more than once per car) 
triggerClientEvent(root, "policeradio", pl) --trigger that client event to EVERY player that exists (hence that "root") 
end 
end --This "for" loop will be done for every single policecar, remember that! 
  

Now, for the client-side:

addEvent("policeradio", true) 
addEventHandler("policeradio", root, 
function() 
local x, y, z = getElementPosition( source ) 
local polveh = getPedOccupiedVehicle( source ) 
policeradio = playSound3D("policead.mp3",x,y,z, true)  
attachElements(polveh, policeradio) 
end 
end 
) 

This should work.

You can delete my comments (the gray text) when you paste the codes; they're only there to help you understand why and how it all works.

Also, remember to eventually destroy the sound!

great thanks :D but i'm not so noob in scripting to do not know that --------- [[]] and other methods like this just like decoder :)

Link to comment
local polveh = getElementsByType("vehicle") 

getElementsByType

Returns

Returns a table containing all the elements of the specified type. Returns an empty table if there are no elements of the specified type. Returns false if the string specified is invalid (or not a string).

I'm gonna help you to understand how to use this.

So, you want it to be triggered for every police vehicle? I guess you mean you mean to every player who is in a police vehicle. That isn't possible from client-side, unless you want to add unnecesary extra processing both for client and server by triggering events from client and back from server.

So, in the server script is where we'll use some of that code you have there.

You gotta paste the following in the part where you trigger the client event. Use your common sense to know if there's something to replace, remove, or add; I'm only explaining how to do this particular stuff work, NOT how to make it compatible to your whole code:

local polveh = getElementsByType("vehicle") 
for i, v in ipairs (polveh) do --Let's loop through every policecar 
if getElementData(polveh,"Service") == "Police" then --I hope the car itself has this element data, not the player 
pl = getVehicleOccupant(polveh) --Let's only retrieve the player who's the driver of a policecar (it isn't a good idea to trigger the event more than once per car) 
triggerClientEvent(root, "policeradio", pl) --trigger that client event to EVERY player that exists (hence that "root") 
end 
end --This "for" loop will be done for every single policecar, remember that! 
  

Now, for the client-side:

addEvent("policeradio", true) 
addEventHandler("policeradio", root, 
function() 
local x, y, z = getElementPosition( source ) 
local polveh = getPedOccupiedVehicle( source ) 
policeradio = playSound3D("policead.mp3",x,y,z, true)  
attachElements(polveh, policeradio) 
end 
end 
) 

This should work.

You can delete my comments (the gray text) when you paste the codes; they're only there to help you understand why and how it all works.

Also, remember to eventually destroy the sound!

but this sound plays only for player into the police car ?

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...