esx_core
esx_core copied to clipboard
fix(commands/tp) Fix teleporting in vehicle
Description
This PR fixes an issue where admins using the /tp command while in a vehicle would lose their vehicle. Now, if a player is in a vehicle, the vehicle is teleported along with the player.
Motivation
Admins using the /tp command while inside a vehicle would lose the vehicle because only the player’s coordinates were updated. This fix ensures that the vehicle moves along with the player, preventing accidental loss.
Implementation Details
- Retrieve the player ped using GetPlayerPed.
- Check if the player is currently in a vehicle using GetVehiclePedIsIn.
- If a vehicle exists, use SetEntityCoords to teleport the vehicle, which automatically teleports the player as well.
- If the player is not in a vehicle, update the player’s coordinates using xPlayer.setCoords.
Usage Example
/tp [x] [y] [z]
PR Checklist
- [x] My commit messages and PR title follow the Conventional Commits standard.
- [x] My changes have been tested locally and function as expected.
- [x] My PR does not introduce any breaking changes.
- [x] I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.