Jump to content

Urgent! Client side variables problem!


jingzhi

Recommended Posts

Posted

Hello everybody,

I have been working on a script recently and got a problem which seems like 2 variables on the Client side overwriting each other (on two different clients)

local_sound = playSound3D(sound, x, y, z, true) 

When I try to play this sound for 2 players at the same time the local_sound variable gets overwrited so only the player who played sound second will hear the sound and the first player won't be able to hear it anymore.

Any thought / help ?

Posted

Surely two clients aren't connected between each other (only through the server), so the problem could only be in the script, for example, where you somehow delete the variable from all clients and redefine it on a specific client.

Posted

Then it's very strange, this shouldn't be happening, here is the related scripts

function engine_func() 
    local veh = getPedOccupiedVehicle (localPlayer) 
    local RPM = getVehicleRPM(veh) 
    setElementData(veh,"RPM",RPM) 
    if veh then 
        if getVehicleEngineState (veh) == true then 
            setSoundVolume(local_sound,1) 
            setSoundSpeed(local_sound, RPM * 2.5 / 10000) 
        else 
            if getSoundVolume(local_sound) == 1 then 
                setSoundVolume(local_sound,0) 
            end 
        end 
    else 
        destroyElement(local_sound) 
        removeEventHandler("onClientRender",root,engine_func) 
    end 
end 
  
addEventHandler ( "onClientVehicleEnter", getRootElement(),  
function() 
    if getElementModel ( source ) == 411 then 
        setWorldSoundEnabled(40,false) 
        local x,y,z = getElementPosition(source) 
        if vehicles[source] then vehicles[source] = nil end 
        local_sound = playSound3D(engine_sound, x, y, z, true) 
        setSoundVolume(local_sound,0) 
        attachElements(local_sound,source) 
        addEventHandler ( "onClientRender", getRootElement(), engine_func ) 
    end 
end) 
  
addEventHandler ( "onClientVehicleExit", getRootElement(), function() 
    if getElementModel(source) == 411 then 
        setWorldSoundEnabled(40,true) 
        destroyElement(local_sound) 
        removeEventHandler ( "onClientRender", getRootElement(), engine_func ) 
    end 
end) 

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...