Jump to content

Door sounds(onClientStartEnter detect problem)


JeViCo

Recommended Posts

Good day, community! I have a question: How can i detect a moment when the player is near the car and opens the door? I tried to use onClientVehicleStartEnter. When then distance between player and vehicle like 1 meter and more sound plays before player starts opening the door. getPedOccupiedVehicle + OnClientRender gives me the same as onClientVehicleEnter

Link to comment
  • Moderators

It's only play sound when enter to the vehicle from OUTSIDE.

More tasks: https://wiki.multitheftauto.com/wiki/List_of_player_tasks

Maybe you need: TASK_SIMPLE_CAR_OPEN_DOOR_FROM_OUTSIDE, TASK_SIMPLE_CAR_OPEN_LOCKED_DOOR_FROM_OUTSIDE, TASK_SIMPLE_CAR_CLOSE_DOOR_FROM_INSIDE, TASK_SIMPLE_CAR_CLOSE_DOOR_FROM_OUTSIDE

 

-- CLIENT

function checkEnter()
    local a,b,c,d = getPedTask(getLocalPlayer(), "primary", 3)
        
    if tostring(b) == "TASK_SIMPLE_CAR_OPEN_DOOR_FROM_OUTSIDE" then
        playDoorSound()
        removeEventHandler("onClientRender", getRootElement(), checkEnter)
    end
end

function playDoorSound()
    outputChatBox("playSound()")
end

addEventHandler("onClientVehicleStartEnter", getRootElement(), function(player)
    if player ~= localPlayer then return end
    addEventHandler("onClientRender", getRootElement(), checkEnter)
end)

 

Edited by gpetersz
  • Thanks 1
Link to comment
On 01.04.2018 at 15:16, gpetersz said:

It's only play sound when enter to the vehicle from OUTSIDE.

More tasks: https://wiki.multitheftauto.com/wiki/List_of_player_tasks

Maybe you need: TASK_SIMPLE_CAR_OPEN_DOOR_FROM_OUTSIDE, TASK_SIMPLE_CAR_OPEN_LOCKED_DOOR_FROM_OUTSIDE, TASK_SIMPLE_CAR_CLOSE_DOOR_FROM_INSIDE, TASK_SIMPLE_CAR_CLOSE_DOOR_FROM_OUTSIDE

 


-- CLIENT

function checkEnter()
    local a,b,c,d = getPedTask(getLocalPlayer(), "primary", 3)
        
    if tostring(b) == "TASK_SIMPLE_CAR_OPEN_DOOR_FROM_OUTSIDE" then
        playDoorSound()
        removeEventHandler("onClientRender", getRootElement(), checkEnter)
    end
end

function playDoorSound()
    outputChatBox("playSound()")
end

addEventHandler("onClientVehicleStartEnter", getRootElement(), function(player)
    if player ~= localPlayer then return end
    addEventHandler("onClientRender", getRootElement(), checkEnter)
end)

 

Thank you so much, it works! I didn't know about getPedTask. I'll learn it. Thanks again xD

Link to comment

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