Jump to content

Recommended Posts

Posted
mp.events.addCommand("veh", (player, text) => {
  if (text == undefined) {
    let veh = mp.vehicles.new(mp.joaat("T20"), player.position);
    player.putIntoVehicle(veh, -1);
  } else {
    let veh = mp.vehicles.new(mp.joaat(text), player.position);
    player.putIntoVehicle(veh, -1);
  }
});

I am using this simple script. When I execute veh command it creates the vehicle, but the player is not inside.

Posted (edited)

this does not work for servers with more than 1 player, try this:

mp.events.addCommand("veh", (player, text) => {
  if (text == undefined) {
    player.veh = mp.vehicles.new(mp.joaat("T20"), player.position);
    player.putIntoVehicle(player.veh, -1);
  } else {
    player.veh = mp.vehicles.new(mp.joaat(text), player.position);
    player.putIntoVehicle(player.veh, -1);
  }
});

 

Edited by [BC]VACEDA[NWD]
Posted (edited)
41 minutes ago, [BC]VACEDA[NWD] said:

this does not work for servers with more than 1 player, try this:


mp.events.addCommand("veh", (player, text) => {
  if (text == undefined) {
    player.veh = mp.vehicles.new(mp.joaat("T20"), player.position);
    player.putIntoVehicle(player.veh, -1);
  } else {
    player.veh = mp.vehicles.new(mp.joaat(text), player.position);
    player.putIntoVehicle(player.veh, -1);
  }
});

 

Thanks for Quick reply. Will try tomorrow. I also noted that once I entered the same type of car the code worked at the following run.

for example:

I run: /veh luxor - wont put me inside, but I do manually get in.

then I run /veh luxor again and it works

Edited by micsko17
Posted
vor 9 Minuten schrieb micsko17:

Thanks for Quick reply. Will try tomorrow. I also noted that once I entered the same type of car the code worked at the following run.

for example:

I run: /veh luxor - wont put me inside, but I do manually get in.

then I run /veh luxor again and it works

You using 1.1?

It's a known bug

Posted

A person in discord suggested me doing this and it works for now:

 

setTimeout( () => {
player.putIntoVehicle(veh, seat);
}, 200);

 

Posted

I'm using the following code so I don't have to wrap the call in a timer everytime I want to put a player in a vehicle. It's not all my code, was inspired by the search bar on the RAGE:MP discord server.

 

const putIntoVehicleKey = Symbol('putIntoVehicle');

mp.events.add('entityCreated', entity => {
    if (entity.type !== 'player') {
        return;
    }

    entity[putIntoVehicleKey] = entity.putIntoVehicle;
    entity.putIntoVehicle = (vehicle, seat) => {
        setTimeout(() => {
            entity[putIntoVehicleKey](vehicle, seat);
        }, 200);
    }; 
});

 

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...