Jump to content

Playsound problem


Recommended Posts

Posted

Hi everyone, I will like do a Playsound while is changing of map, (On Travelling)

but IDK why this doesn't work:

local angle = 0 
  
function loadingtravel() 
local screenWidth, screenHeight = guiGetScreenSize() 
angle = angle +7 
dxDrawImage(screenWidth/2-32, screenHeight/2-32, 64, 64, 'img/travelling.png', angle,0,0) 
fadeCamera ( false, 0, 0, 0, 0 ) 
end 
  
function sound ()  
    local sound = playSound("audio/xd.mp3") 
    setSoundVolume(sound, 1)  
end 
addEventHandler("onClientRender",getLocalPlayer(),sound,loadingtravel) 

I hope you can help me ^^

Posted

This:

  
addEventHandler("onClientRender",getLocalPlayer(),sound,loadingtravel) 

should be this:

  
addEventHandler("onClientRender",root,sound) 
addEventHandler("onClientRender",root,loadingtravel) 
  

Posted
I cant hear the music:

Debuscript:

WARNING: race/race_client.lua:186: Bad'sound/player' pointer @ 'setSoundVolume (1)

volume: A floating point number representing the desired volume level. Range is from 0.0 to 1.0

Posted

it doesnt work

local angle = 0

function loadingtravel()

local screenWidth, screenHeight = guiGetScreenSize()

angle = angle +7

dxDrawImage(screenWidth/2-32, screenHeight/2-32, 64, 64, 'img/travelling.png', angle,0,0)

fadeCamera ( false, 0, 0, 0, 0 )

end

function sound2 ()

local sound = playSound("audio/xd.mp3")

setSoundVolume(sound,1.0)

end

addEventHandler("onClientRender",root,sound2)

addEventHandler("onClientRender",root,loadingtravel)

Posted
local angle = 0 
local screenWidth, screenHeight = guiGetScreenSize() 
local sound = playSound('audio/xd.mp3') 
angle = angle +7 
addEventHandler('onClientRender', root, 
function () 
dxDrawImage(screenWidth/2-32, screenHeight/2-32, 64, 64, 'img/travelling.png', angle,0,0) 
fadeCamera ( false, 0, 0, 0, 0 ) 
     setSoundVolume(sound, 0.5) 
end 
 ) 

Make Sure , you have audio file with xD.mp3 inside it ,

and Post your , meta.xml file ,

Posted

Now the problem is, I heard a song like a anoying sound which lag me, I can move and nothing, maybe 0.1 fps and I need to close the game, idk why ...

Posted

well , i made the sound 50 % only > and give you lag ?

is there any other sound scripts beside this on the server> ?

if there is iam sure it's form it ,

Posted (edited)

No, just mission acomplice, but it shouldm't work, just on race maps when someone finish the map, but while travelling, I heard a annoying sound which give me lag.

I tried with 1.0 and 0.5 and doesnt work.

Edited by Guest
Posted

Ok , Try Change to root on the event to resourceRoot

And test it , if it's lag ,

then there must be, other resource causing the lag,

Posted

I cant heard nothing

local angle = 0 
  
function loadingtravel() 
local screenWidth, screenHeight = guiGetScreenSize() 
angle = angle +7 
dxDrawImage(screenWidth/2-32, screenHeight/2-32, 64, 64, 'img/travelling.png', angle,0,0) 
fadeCamera ( false, 0, 0, 0, 0 ) 
end 
  
function sound2 ()  
    local sound = playSound("audio/xd.mp3") 
    setSoundVolume(sound, 1.0) 
end 
addEventHandler("onClientRender",resourceRoot,sound2) 
addEventHandler("onClientRender",resourceRoot,loadingtravel) 

Posted (edited)

Try using this:

local angle, handled 
local screenWidth, screenHeight = guiGetScreenSize() 
function loadingtravel() 
   
    angle = angle +7 
    dxDrawImage(screenWidth/2-32, screenHeight/2-32, 64, 64, 'img/travelling.png', angle,0,0) 
     
end 
  
addEvent("onClientMapStopping", true) 
addEventHandler("onClientMapStopping", root, 
function() 
     
    if not handled then 
        handled = true 
        angle = 0 
        fadeCamera ( false, 0, 0, 0, 0 ) 
        addEventHandler("onClientRender", root, loadingTavel) 
        local sound = playSound("audio/xd.mp3") 
        setSoundVolume(sound, 1.0) 
    end 
end) 
  
addEvent("onClientMapStarting", true) 
addEventHandler("onClientMapStarting", root, 
function() 
    if handled then 
        fadeCamera(true, 0) 
        removeEventHandler("onClientRender", root, loadingtravel) 
        handled = false 
    end 
end) 

I used race to find the events for the when the map stops and starts. You were also trying to play a sound each time GTA renders a frame, which could be 60 times a second by using playSound with onClientRender.

Make sure xD.mp3 is in the folder audio, in your resouce. Also make sure it is correctly added in the meta.xml of your resource.

Edited by Guest
Posted

Okay, I edited the code and took "local screenWidth, screenHeight = guiGetScreenSize()" out of loadingtravel() because there was no need to get the screen size every render.

And anytime :).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...