forked from Simnation/Main
wd
This commit is contained in:
parent
307f4c0d90
commit
1c16382e41
10 changed files with 307 additions and 2 deletions
92
resources/[tools]/interact-sound/client/main.lua
Normal file
92
resources/[tools]/interact-sound/client/main.lua
Normal file
|
@ -0,0 +1,92 @@
|
|||
|
||||
------
|
||||
-- InteractionSound by Scott
|
||||
-- Version: v0.0.1
|
||||
-- Path: client/main.lua
|
||||
--
|
||||
-- Allows sounds to be played on single clients, all clients, or all clients within
|
||||
-- a specific range from the entity to which the sound has been created.
|
||||
------
|
||||
|
||||
local standardVolumeOutput = 0.3;
|
||||
local hasPlayerLoaded = false
|
||||
Citizen.CreateThread(function()
|
||||
Wait(15000)
|
||||
hasPlayerLoaded = true
|
||||
end)
|
||||
------
|
||||
-- RegisterNetEvent LIFE_CL:Sound:PlayOnOne
|
||||
--
|
||||
-- @param soundFile - The name of the soundfile within the client/html/sounds/ folder.
|
||||
-- - Can also specify a folder/sound file.
|
||||
-- @param soundVolume - The volume at which the soundFile should be played. Nil or don't
|
||||
-- - provide it for the default of standardVolumeOutput. Should be between
|
||||
-- - 0.1 to 1.0.
|
||||
--
|
||||
-- Starts playing a sound locally on a single client.
|
||||
------
|
||||
RegisterNetEvent('InteractSound_CL:PlayOnOne')
|
||||
AddEventHandler('InteractSound_CL:PlayOnOne', function(soundFile, soundVolume)
|
||||
if hasPlayerLoaded then
|
||||
SendNUIMessage({
|
||||
transactionType = 'playSound',
|
||||
transactionFile = soundFile,
|
||||
transactionVolume = soundVolume
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
------
|
||||
-- RegisterNetEvent LIFE_CL:Sound:PlayOnAll
|
||||
--
|
||||
-- @param soundFile - The name of the soundfile within the client/html/sounds/ folder.
|
||||
-- - Can also specify a folder/sound file.
|
||||
-- @param soundVolume - The volume at which the soundFile should be played. Nil or don't
|
||||
-- - provide it for the default of standardVolumeOutput. Should be between
|
||||
-- - 0.1 to 1.0.
|
||||
--
|
||||
-- Starts playing a sound on all clients who are online in the server.
|
||||
------
|
||||
RegisterNetEvent('InteractSound_CL:PlayOnAll')
|
||||
AddEventHandler('InteractSound_CL:PlayOnAll', function(soundFile, soundVolume)
|
||||
if hasPlayerLoaded then
|
||||
SendNUIMessage({
|
||||
transactionType = 'playSound',
|
||||
transactionFile = soundFile,
|
||||
transactionVolume = soundVolume or standardVolumeOutput
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
------
|
||||
-- RegisterNetEvent LIFE_CL:Sound:PlayWithinDistance
|
||||
--
|
||||
-- @param playOnEntity - The entity network id (will be converted from net id to entity on client)
|
||||
-- - of the entity for which the max distance is to be drawn from.
|
||||
-- @param maxDistance - The maximum float distance (client uses Vdist) to allow the player to
|
||||
-- - hear the soundFile being played.
|
||||
-- @param soundFile - The name of the soundfile within the client/html/sounds/ folder.
|
||||
-- - Can also specify a folder/sound file.
|
||||
-- @param soundVolume - The volume at which the soundFile should be played. Nil or don't
|
||||
-- - provide it for the default of standardVolumeOutput. Should be between
|
||||
-- - 0.1 to 1.0.
|
||||
--
|
||||
-- Starts playing a sound on a client if the client is within the specificed maxDistance from the playOnEntity.
|
||||
-- @TODO Change sound volume based on the distance the player is away from the playOnEntity.
|
||||
------
|
||||
RegisterNetEvent('InteractSound_CL:PlayWithinDistance')
|
||||
AddEventHandler('InteractSound_CL:PlayWithinDistance', function(otherPlayerCoords, maxDistance, soundFile, soundVolume)
|
||||
if hasPlayerLoaded then
|
||||
local myCoords = GetEntityCoords(PlayerPedId())
|
||||
local distance = #(myCoords - otherPlayerCoords)
|
||||
|
||||
if distance < maxDistance then
|
||||
SendNUIMessage({
|
||||
transactionType = 'playSound',
|
||||
transactionFile = soundFile,
|
||||
transactionVolume = soundVolume or standardVolumeOutput
|
||||
})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue