Created
January 2, 2020 09:20
-
-
Save draobrehtom/8bf04815356ea11213fa4f7e549ce2e9 to your computer and use it in GitHub Desktop.
FiveM: JS - Creating car
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RegisterCommand("car", async (source, args) => { | |
| let vehicleName = args[0] ? args[0] : 'adder'; | |
| if (! IsModelInCdimage(vehicleName) || ! IsModelAVehicle(vehicleName)) { | |
| emitNet("js:chat", 'spawn a ' + vehicleName + '. Who even wants their spawning to actually ^*succeed?', [0,0,0]); | |
| return; | |
| } | |
| RequestModel(vehicleName); | |
| let i = setInterval(() => { | |
| emitNet("js:chat", 'model loading', [0,0,0]); | |
| if (HasModelLoaded(vehicleName)) { | |
| let playerPed = PlayerPedId() | |
| let pos = GetEntityCoords(playerPed) | |
| let vehicle = CreateVehicle(vehicleName, pos[0], pos[1], pos[2], GetEntityHeading(playerPed), true, false) | |
| SetPedIntoVehicle(playerPed, vehicle, -1) | |
| SetEntityAsNoLongerNeeded(vehicle) | |
| SetModelAsNoLongerNeeded(vehicleName) | |
| emitNet("js:chat", 'model loaded', [0,255,0]); | |
| clearInterval(i); | |
| } | |
| }, 500); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment