Gaimo Posted December 9 Share Posted December 9 (edited) I need to be able to cancel at any time during the execution of entering a vehicle. My problem is the following, there is a collision behind the vehicle, and when the player presses to enter a vehicle and presses the actionKey, he should be attached to the vehicle, but as he is performing the action of entering the vehicle this does not happen, and the problem with this is that the player is left without colliding with the vehicle. Bug demo: https://youtu.be/um9erpGCSzE Client.lua bindKey(actionKey, "down", function() if playerInColshape then local elementData = getElementData(playerInColshape, "waste_collector") if elementData and elementData.owner == localPlayer then local vehicle = getElementParent(playerInColshape) setElementCollidableWith(localPlayer, vehicle, false) triggerServerEvent("onPlayerRequestAttach", localPlayer, playerInColshape) end end end) Server.lua addEvent("onPlayerRequestAttach", true) addEventHandler("onPlayerRequestAttach", root, function(colshape) local player = source local vehicle = getElementParent(colshape) if attachedPlayers[player] then detachPlayerFromVehicle(player) togglePlayerControls(player, true) else attachPlayerToVehicle(player, vehicle) togglePlayerControls(player, false) end end) Edited December 9 by Gaimo Link to comment
Gaimo Posted December 9 Author Share Posted December 9 I used setElementPosition as androski mentioned on discord and a setTimer and it worked. bindKey(actionKey, "down", function() if playerInColshape then local elementData = getElementData(playerInColshape, "waste_collector") if elementData and elementData.owner == localPlayer then local vehicle = getElementParent(playerInColshape) local x, y, z = getElementPosition(localPlayer) setElementPosition(localPlayer, x, y, z) setTimer(function() setElementCollidableWith(localPlayer, vehicle, false) triggerServerEvent("onPlayerRequestAttach", localPlayer, playerInColshape) end, 50, 1) end end end) Link to comment
Moderators IIYAMA Posted December 9 Moderators Share Posted December 9 Just a little details, it is actually the hidden argument 'warp' that is responsible for the cancellation. In the past this argument was not present and was applied by default. https://wiki.multitheftauto.com/wiki/SetElementPosition Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now