Jump to content
RAGE Multiplayer Community

How can I destroy all vehicles binded to a player?

Recommended Posts

Hello. I'm trying to destroy all the vehicles binded to a player once he quits the server. But there's an error... Why is this:

mp.events.add("playerQuit", (player) => {
    var arrayLength = player.personalVehicles.length;
    for (var i = 0; i < arrayLength; i++) {
        vehicle = player.personalVehicles[i];

Returning this error:

C:\RAGEMP\server-files\packages\RPG\vehicles.js:52: TypeError: vehicle.destroy is not a function


The `console.log(player.personalVehicles);` returns:

  vehicle: {
    setVariable: [Function (anonymous)],
    setVariables: [Function (anonymous)]

The vehicles are spawned like this:

mp.events.add("playerReady", (player) => {
    pool.getConnection((err, con) => {
        if (err) console.log(err)
            con.query("SELECT vehicleID, vehicleModel, vehicleSpawnX, vehicleSpawnY, vehicleSpawnZ FROM vehicles WHERE vehicleType = ? AND vehicleOwner = ?", ["players", player.playerID], function (err, result) {
                if (err) console.log(err)
                player.personalVehicles = []
                for (i = 0; i < result.length; i++) {
                    vehicleModel = result[i].vehicleModel
                    player.personalVehicles.push({vehicle: mp.vehicles.new(parseInt(vehicleModel), new mp.Vector3(result[i].vehicleSpawnX, result[i].vehicleSpawnY, result[i].vehicleSpawnZ))})


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...