multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.42k stars 437 forks source link

onClientVehicleEnterStop/onVehicleEnterStop #2675

Open Fierelier opened 2 years ago

Fierelier commented 2 years ago

Is your feature request related to a problem? Please describe.

No response

Describe the solution you'd like

A onClientVehicleEnterStop/onVehicleEnterStop, which triggers when the ped/player cancels entering a vehicle, would be just the event I need. Perhaps also a getPedTargetVehicle, which returns the vehicle the ped/player is trying to get into.

Describe alternatives you've considered

No response

Additional context

I have a script which alters the rotation of the player, which makes them not walk to the vehicle properly when getting in from far away. I can use onClientVehicleStartEnter to detect when the player starts getting into a car, but I couldn't think of a reliable way to detect when they cancel doing that (for example, by pressing a movement key) - There's some sort of buffer before the movement keys cancel anything, then I don't know how much analog input there needs to be, and the player could also be moved/teleported away... It's just a lot of stuff to deal with and get wrong.

Security Policy

JcynR commented 2 years ago

I agree with request, however you can work around it by checking for the 'TASK_COMPLEX_GO_TO_CAR_DOOR_AND_STAND_STILL' task with getPedTask.

Here's an example:

addEventHandler('onClientVehicleStartEnter', root, function(player, seat, door)
    local vehicle = source
    Timer(function()
        local _, task = localPlayer:getTask('primary', 3)
        if task ~= 'TASK_COMPLEX_GO_TO_CAR_DOOR_AND_STAND_STILL' then
            triggerEvent('onClientVehicleEnterStop', vehicle, player, seat, door)
            sourceTimer:destroy()
        end
    end, 0, 0)
end)

addEvent('onClientVehicleEnterStop', true)
addEventHandler('onClientVehicleEnterStop', root, function()
    print('Entering interrupted')
end)

Hope this helps.

Fierelier commented 2 years ago

Oh wow, I didn't even know about this function at all, that's insane! Thank you!