Skip to content

Commit

Permalink
Add support for OneSync Infinity and Maximum Distances
Browse files Browse the repository at this point in the history
OneSync Infinity and Maximum Distance
  • Loading branch information
plunkettscott authored Jul 15, 2021
2 parents 2efbcdb + 862e34a commit 3d4a629
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
--
-- Starts playing a sound locally on a single client.
------
RegisterServerEvent('InteractSound_SV:PlayOnOne')
RegisterNetEvent('InteractSound_SV:PlayOnOne')
AddEventHandler('InteractSound_SV:PlayOnOne', function(clientNetId, soundFile, soundVolume)
TriggerClientEvent('InteractSound_CL:PlayOnOne', clientNetId, soundFile, soundVolume)
end)
Expand All @@ -42,7 +42,7 @@ end)
--
-- Starts playing a sound locally on a single client, which is the source of the event.
------
RegisterServerEvent('InteractSound_SV:PlayOnSource')
RegisterNetEvent('InteractSound_SV:PlayOnSource')
AddEventHandler('InteractSound_SV:PlayOnSource', function(soundFile, soundVolume)
TriggerClientEvent('InteractSound_CL:PlayOnOne', source, soundFile, soundVolume)
end)
Expand All @@ -59,7 +59,7 @@ end)
--
-- Starts playing a sound on all clients who are online in the server.
------
RegisterServerEvent('InteractSound_SV:PlayOnAll')
RegisterNetEvent('InteractSound_SV:PlayOnAll')
AddEventHandler('InteractSound_SV:PlayOnAll', function(soundFile, soundVolume)
TriggerClientEvent('InteractSound_CL:PlayOnAll', -1, soundFile, soundVolume)
end)
Expand All @@ -81,11 +81,22 @@ end)
-- 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.
------
RegisterServerEvent('InteractSound_SV:PlayWithinDistance')
RegisterNetEvent('InteractSound_SV:PlayWithinDistance')
AddEventHandler('InteractSound_SV:PlayWithinDistance', function(maxDistance, soundFile, soundVolume)
if GetConvar("onesync_enableInfinity", "false") == "true" then
TriggerClientEvent('InteractSound_CL:PlayWithinDistanceOS', -1, GetEntityCoords(GetPlayerPed(source)), maxDistance, soundFile, soundVolume)
else
TriggerClientEvent('InteractSound_CL:PlayWithinDistance', -1, source, maxDistance, soundFile, soundVolume)
end
end)

RegisterNetEvent('InteractSound_SV:PlayWithinDistance')
AddEventHandler('InteractSound_SV:PlayWithinDistance', function(maxDistance, soundFile, soundVolume)
local src = source
local DistanceLimit = 300
if maxDistance < DistanceLimit then
TriggerClientEvent('InteractSound_CL:PlayWithinDistance', -1, GetEntityCoords(GetPlayerPed(src)), maxDistance, soundFile, soundVolume)
else
print(('[interact-sound] [^3WARNING^7] %s attempted to trigger InteractSound_SV:PlayWithinDistance over the distance limit ' .. DistanceLimit):format(GetPlayerName(src)))
end
end)

0 comments on commit 3d4a629

Please sign in to comment.