araynimax / sounity

A 3D sound library for FiveM which uses the browsers sound api.
https://araynimax.github.io/sounity/
MIT License
32 stars 6 forks source link

File or Link don't Working #17

Closed NathanLFG closed 1 month ago

NathanLFG commented 9 months ago

Hi, I've been trying to use your script for a few days now, but I can't get it to work. Whatever I put in the space where I want to put a link, nothing works. Would it be possible to explain to me what I should put, and if you have an example, that would be great!

Thanks in advance!

WhitigolProd commented 9 months ago

Whatever I put in the space where I want to put a link, nothing works.

The field for the URL can accept a third party URL source to an audio file, or an in-game NUI file. For example:

With External URL:

-- create a sound instance
local soundId = exports.sounity:CreateSound("https://example.com/audio.mp3", json.encode({
    posX = 3,
    posY = 5,
    posZ = 8,
}));

-- start playback of that sound
exports.sounity:StartSound(soundId);

With in-game NUI:

-- create a sound instance
local soundId = exports.sounity:CreateSound("https://cfx-nui-" .. GetCurrentResourceName() .. "/nui/audio.mp3", json.encode({
    posX = 3,
    posY = 5,
    posZ = 8,
}));

-- start playback of that sound
exports.sounity:StartSound(soundId);

This MUST be ran server-sided to be heard by all players

NathanLFG commented 8 months ago

The field for the URL can accept a third party URL source to an audio file, or an in-game NUI file. For example:

Thanks ! What if I want to use a file stored in the script? What can I do? Does the script accept a direct link to a file, or do I have to use a link? For links, is it possible to use google drive?

Thanks in advance @WhitigolProd !

WhitigolProd commented 8 months ago

What if I want to use a file stored in the script?

You can use https://cfx-nui-[resource_name_here]/path/to/file.ext

For links, is it possible to use google drive?

As long as you can provide a direct link to the raw file, yes. However, I don't believe google drive does this.

cc @NathanLFG

NathanLFG commented 8 months ago

Thank you very much! I'll give it a try and come back if I still have a problem!

NathanLFG commented 8 months ago

Hey! Sorry to bother you again !

Is it possible for you to send an example of code that uses this script, especially for StartSound, StopSound so that other players can hear from a distance?

In fact I don't know what I need to put in the client.lua file or the server.lua file for everything to work and for people around to hear.

So if you ever have a complete code that works so that I can see how it works between the client side and the server side, and also if I can know how to delete a sound so that I can restart it, that would be great too !

Thanks a lot in advance @WhitigolProd !

WhitigolProd commented 8 months ago

I unfortunately can not provide a Lua example, since I create my scripts in TypeScript, however, here is a typescript example that I used to play sounds:

server.ts

onNet("whitigol.toolbox:playUncuffSound", async (src: string) => {
    const uncuffSound = exps.sounity.CreateSound(
        `https://cfx-nui-${GetCurrentResourceName()}/nui/uncuff.ogg`,
        JSON.stringify({
            posX: 0,
            posY: 0,
            posZ: 0,
        })
    );
    const ped = GetPlayerPed(src);
    const pedId = NetworkGetNetworkIdFromEntity(ped);
    exps.sounity.AttachSound(uncuffSound, pedId);
    exps.sounity.StartSound(uncuffSound);
    await delay(3000);
    exps.sounity.DisposeSound(uncuffSound);
});

cc @NathanLFG

NathanLFG commented 7 months ago

I unfortunately can not provide a Lua example, since I create my scripts in TypeScript, however, here is a typescript example that I used to play sounds:

server.ts

onNet("whitigol.toolbox:playUncuffSound", async (src: string) => {
    const uncuffSound = exps.sounity.CreateSound(
        `https://cfx-nui-${GetCurrentResourceName()}/nui/uncuff.ogg`,
        JSON.stringify({
            posX: 0,
            posY: 0,
            posZ: 0,
        })
    );
    const ped = GetPlayerPed(src);
    const pedId = NetworkGetNetworkIdFromEntity(ped);
    exps.sounity.AttachSound(uncuffSound, pedId);
    exps.sounity.StartSound(uncuffSound);
    await delay(3000);
    exps.sounity.DisposeSound(uncuffSound);
});

cc @NathanLFG

Hey @WhitigolProd !

Thanks for the help, but I have a new problem that this time seems to come from the script, so just in case I ask the question anyway: When I set a sound with distance, it works perfectly, except that when I move too far away and I come back in the sound area, Sounity sends me back an error and tells me that it can't launch the same sound twice, even though I'm not the one launching it on my script since I only activated the sound once by counting the distance.

Thanks in advance if you have an answer for me, Nathan_LFG

WhitigolProd commented 7 months ago

Unfortunately, I'm unsure of what could cause this issue. I've since stopped using this sound engine and created my own internal use sound engine for better developer experience and performance.

NathanLFG commented 7 months ago

Oh ok no worries! And this system you're ready to share. This one could certainly help me a lot.

WhitigolProd commented 7 months ago

Unfortunately the sound engine I've built will remain a private development tool.

NathanLFG commented 7 months ago

Ok no worries thanks anyway!