Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
|
||||
------
|
||||
-- InteractSound by Scott
|
||||
-- Verstion: v0.0.1
|
||||
------
|
||||
|
||||
-- Manifest Version
|
||||
resource_manifest_version '77731fab-63ca-442c-a67b-abc70f28dfa5'
|
||||
|
||||
-- Client Scripts
|
||||
client_script 'client/main.lua'
|
||||
|
||||
-- Server Scripts
|
||||
server_script 'server/main.lua'
|
||||
|
||||
-- NUI Default Page
|
||||
ui_page('client/html/index.html')
|
||||
|
||||
-- Files needed for NUI
|
||||
-- DON'T FORGET TO ADD THE SOUND FILES TO THIS!
|
||||
files({
|
||||
'client/html/index.html',
|
||||
-- Begin Sound Files Here...
|
||||
-- client/html/sounds/ ... .ogg
|
||||
'client/html/sounds/on.ogg',
|
||||
'client/html/sounds/off.ogg'
|
||||
})
|
||||
@@ -0,0 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Need to include jQuery! -->
|
||||
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
|
||||
<script>
|
||||
var audioPlayer = null;
|
||||
// Listen for NUI Messages.
|
||||
window.addEventListener('message', function(event) {
|
||||
// Check for playSound transaction
|
||||
if (event.data.transactionType == "playSound") {
|
||||
|
||||
if (audioPlayer != null) {
|
||||
audioPlayer.pause();
|
||||
}
|
||||
|
||||
audioPlayer = new Audio("./sounds/" + event.data.transactionFile + ".ogg");
|
||||
audioPlayer.volume = event.data.transactionVolume;
|
||||
audioPlayer.play();
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,81 @@
|
||||
|
||||
------
|
||||
-- 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 = 1.0;
|
||||
|
||||
------
|
||||
-- RegisterNetEvent InteractSound_CL: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)
|
||||
SendNUIMessage({
|
||||
transactionType = 'playSound',
|
||||
transactionFile = soundFile,
|
||||
transactionVolume = soundVolume
|
||||
})
|
||||
end)
|
||||
|
||||
------
|
||||
-- RegisterNetEvent InteractSound_CL: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)
|
||||
SendNUIMessage({
|
||||
transactionType = 'playSound',
|
||||
transactionFile = soundFile,
|
||||
transactionVolume = soundVolume
|
||||
})
|
||||
end)
|
||||
|
||||
------
|
||||
-- RegisterNetEvent InteractSound_CL: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(playerNetId, maxDistance, soundFile, soundVolume)
|
||||
local lCoords = GetEntityCoords(GetPlayerPed(-1))
|
||||
local eCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(playerNetId)))
|
||||
local distIs = Vdist(lCoords.x, lCoords.y, lCoords.z, eCoords.x, eCoords.y, eCoords.z)
|
||||
if(distIs <= maxDistance) then
|
||||
SendNUIMessage({
|
||||
transactionType = 'playSound',
|
||||
transactionFile = soundFile,
|
||||
transactionVolume = soundVolume
|
||||
})
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,87 @@
|
||||
|
||||
------
|
||||
-- Interaction Sounds by Scott
|
||||
-- Version: v0.0.1
|
||||
-- Path: server/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. Triggers
|
||||
-- client events only. Used to trigger sounds on other clients from the client or
|
||||
-- server without having to pass directly to another client.
|
||||
------
|
||||
|
||||
------
|
||||
-- RegisterServerEvent InteractSound_SV:PlayOnOne
|
||||
-- Triggers -> ClientEvent InteractSound_CL:PlayOnOne
|
||||
--
|
||||
-- @param clientNetId - The network id of the client that the sound should be played on.
|
||||
-- @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.
|
||||
-- - Can also specify a folder/sound file.
|
||||
--
|
||||
-- Starts playing a sound locally on a single client.
|
||||
------
|
||||
RegisterServerEvent('InteractSound_SV:PlayOnOne')
|
||||
AddEventHandler('InteractSound_SV:PlayOnOne', function(clientNetId, soundFile, soundVolume)
|
||||
TriggerClientEvent('InteractSound_CL:PlayOnOne', clientNetId, soundFile, soundVolume)
|
||||
end)
|
||||
|
||||
------
|
||||
-- RegisterServerEvent InteractSound_SV:PlayOnSource
|
||||
-- Triggers -> ClientEvent InteractSound_CL:PlayOnSource
|
||||
--
|
||||
-- @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.
|
||||
-- - Can also specify a folder/sound file.
|
||||
--
|
||||
-- Starts playing a sound locally on a single client, which is the source of the event.
|
||||
------
|
||||
RegisterServerEvent('InteractSound_SV:PlayOnSource')
|
||||
AddEventHandler('InteractSound_SV:PlayOnSource', function(soundFile, soundVolume)
|
||||
TriggerClientEvent('InteractSound_CL:PlayOnOne', source, soundFile, soundVolume)
|
||||
end)
|
||||
|
||||
------
|
||||
-- RegisterServerEvent InteractSound_SV:PlayOnAll
|
||||
-- Triggers -> ClientEvent InteractSound_CL: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.
|
||||
------
|
||||
RegisterServerEvent('InteractSound_SV:PlayOnAll')
|
||||
AddEventHandler('InteractSound_SV:PlayOnAll', function(soundFile, soundVolume)
|
||||
TriggerClientEvent('InteractSound_CL:PlayOnAll', -1, soundFile, soundVolume)
|
||||
end)
|
||||
|
||||
------
|
||||
-- RegisterServerEvent InteractSound_SV:PlayWithinDistance
|
||||
-- Triggers -> ClientEvent InteractSound_CL: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.
|
||||
------
|
||||
RegisterServerEvent('InteractSound_SV:PlayWithinDistance')
|
||||
AddEventHandler('InteractSound_SV:PlayWithinDistance', function(maxDistance, soundFile, soundVolume)
|
||||
TriggerClientEvent('InteractSound_CL:PlayWithinDistance', -1, source, maxDistance, soundFile, soundVolume)
|
||||
end)
|
||||
Reference in New Issue
Block a user