{"slug":"audio/soundsets","category":"audio","title":"Soundsets","kind":"markdown","intro":"","body":"## SOUNDSETS\n\nSome soundset_refs need according audio banks loaded! Usually name of audio bank is the name of soundset_ref without '\\_Sounds' or '\\_soundset'. You can see audio bank names here: https://github.com/femga/rdr3_discoveries/blob/master/audio/audio_banks/audio_banks.lua\nSome soundset_names have many variants. Natives PLAY_SOUND_FROM_POSITION and PLAY_SOUND_FROM_ENTITY play it randomly.\n\n## Example of playing single sound from position or from entity):\n\n```lua\nlocal is_soundset_playing = false\nlocal soundset_ref = \"RNATV2_Sounds\"\nlocal soundset_name =  \"Alarm\"\n\nCitizen.CreateThread(function()\n  while true do\n    Citizen.Wait(0)\n    if Citizen.InvokeNative(0x91AEF906BCA88877,0, 0x17BEC168) then   -- pressed E\n      if not is_soundset_playing then\n        local counter_i = 1\n        while soundset_ref~=0 and not Citizen.InvokeNative(0xD9130842D7226045 ,soundset_ref,0) and counter_i <= 300  do  -- load soundset\n          counter_i = counter_i + 1\n          Citizen.Wait(0)\n        end\n\n        if soundset_ref == 0 or Citizen.InvokeNative(0xD9130842D7226045 ,soundset_ref,0) then\n          -- PLAY SOUND FROM POSITION:\n          local ped = PlayerPedId()\n          local ped_coords = GetEntityCoords(ped)\n          local x,y,z =  table.unpack(ped_coords + GetEntityForwardVector(ped)*15.0)\n          Citizen.InvokeNative(0xCCE219C922737BFA,soundset_name, x, y, z-1.0, soundset_ref, true, 0, true, 0)  -- PLAY_SOUND_FROM_POSITION\n          is_soundset_playing = true\n\n          -- OR PLAY SOUND FROM ENTITY:\n          -- Citizen.InvokeNative(0x6FB1DA3CA9DA7D90,soundset_name,PlayerPedId(),soundset_ref,true,0,0)  -- PLAY_SOUND_FROM_ENTITY\n\n        end\n\n      else\n          Citizen.InvokeNative(0x531A78D6BF27014B,soundset_ref)  -- stop soundset (required, otherwise new soundsets can fail to load)\n          is_soundset_playing = false\n      end\n    end\n  end\nend)\n\n```\n\nBy default, you can use only one soundset_name at a time (can't play the same sound_name again untill it is over). If u want clone sound, use sound_ids.\n\n## Example of using sound_ids (play the same sound_name simultaneously):\n\n```lua\nlocal is_soundset_playing = false\nlocal soundset_ref = \"RNATV2_Sounds\"\nlocal soundset_name =  \"Alarm\"\nlocal sound_table = {}\n\nCitizen.CreateThread(function()\n  while true do\n    Citizen.Wait(0)\n    if Citizen.InvokeNative(0x91AEF906BCA88877,0, 0x17BEC168) then   -- pressed E\n      if not is_soundset_playing then\n        local counter_i = 1\n        while soundset_ref~=0 and not Citizen.InvokeNative(0xD9130842D7226045 ,soundset_ref,0) and counter_i <= 300  do  -- load soundset\n          counter_i = counter_i + 1\n          Citizen.Wait(0)\n        end\n        if soundset_ref == 0 or Citizen.InvokeNative(0xD9130842D7226045 ,soundset_ref,0) then\n          for counter_id = 0, 15,1 do  -- YOU CAN CLONE MAX 99 SOUND IDS\n            local current_sound_id = GetSoundId()  -- CLONE SOUND ID\n            if current_sound_id ~= -1 then\n              sound_table[current_sound_id] = true\n            end\n          end\n          local counter_to_wait = 1\n          for k,v in pairs(sound_table) do\n              -- PLAY SOUND ID CLONE:\n              Citizen.InvokeNative( 0xF1C5310FEAA36B48,k, soundset_name, PlayerPedId(),soundset_ref, false, 0);\n          \n              -- PLAY SOUND ID CLONE FROM COORDS:\n              -- local coords = GetEntityCoords(PlayerPedId()) + vector3(0.0,5.0,0.0)  -- 5.0 meters from ped\n              -- Citizen.InvokeNative(0xDCF5BA95BBF0FABA, k, soundset_name, coords.x, coords.y, coords.z, soundset_ref, 0, 0, 1)\n          \n          end\n          is_soundset_playing = true\n        end\n\n      else\n          for k,v in pairs(sound_table) do\n            Citizen.InvokeNative(0x353FC880830B88FA,k) -- release sound ids\n          end\n          Citizen.InvokeNative(0x531A78D6BF27014B,soundset_ref)  -- stop soundset (required, otherwise new soundsets can fail to load)\n          is_soundset_playing = false\n      end\n    end\n  end\nend)\n\n```","tables":[],"sourceUrl":"https://github.com/femga/rdr3_discoveries/tree/477aaaccadb7f0c042286611d9939009636cff12/audio/soundsets","rows":[]}