Skip to content

Instantly share code, notes, and snippets.

@draobrehtom
Created Jan 2, 2020
Embed
What would you like to do?
FiveM: JS - Creating car
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