This is a mobile optimized page that loads fast, if you want to load the real page, click this text.

Vehicle Rotation in the Air

SHIMANO

Новый участник
10 Апр 2022
7
1
67
Hey, how can i disable the car Control in the Air? So players should not be able to Rotate the Car if its on wrong side
 

Jerry (ChatGPT)

AI-powered language model
VIP
helper
17 Окт 2023
2,491
240
100
You can disable the car control in the air by setting the vehicle's rotation constraints appropriately using your game engine's physics system or coding. This will prevent players from rotating the car when it's upside down or in a wrong position.
 

Vermilion

Высший разум
High developer
BackEnd developer
FrontEnd developer
29 Сен 2021
1,465
874
181
34
JavaScript:
mp.events.add('render', () => {
    if(mp.players.local.vehicle.isInAir()) {
        mp.game.controls.disableAllControlActions(0)
    } else {
        mp.game.controls.enableAllControlActions(0)
    }
})
 

XDeveluxe

⚡️BackEnd Developer
Команда форума
Moderator
High developer
BackEnd developer
30 Авг 2021
3,013
1,743
211
28
JavaScript:
mp.events.add('render', () => {
    if(mp.players.local.vehicle.isInAir()) {
        mp.game.controls.disableAllControlActions(0)
    } else {
        mp.game.controls.enableAllControlActions(0)
    }
})
Да, но:
1. mp.players.local.vehicle может быть undefined, если игрок не находится в машине, а обращение к свойству объекта, который является undefined/null приведёт к NullException.
Поэтому перед проверкой vehicle.isInAir нам нужно проверить существует ли vehicle.

2. disableAllControlActions отключает группу только на конкретный кадр (render срабатывает каждый кадр), таким образом, если это будет кадр, в котором твой первый if не пройдёт проверку, то второй и не нужен, т.к. нечего включать назад, ведь ничего и не отключалось.

Таким образом конечный вариант выглядит так:
JavaScript:
const localplayer = mp.players.local;

mp.events.add('render', () =>
{
    if (!localplayer.vehicle || !localplayer.vehicle.isInAir()) return;
   
    mp.game.controls.disableAllControlActions(0);
})
 
Последнее редактирование:

SHIMANO

Новый участник
10 Апр 2022
7
1
67

Its Working, thanks. But now AirVehicle cant fly with it.
 

XDeveluxe

⚡️BackEnd Developer
Команда форума
Moderator
High developer
BackEnd developer
30 Авг 2021
3,013
1,743
211
28
Its Working, thanks. But now AirVehicle cant fly with it.
Thats why you need to make adjustements.
In order to do that you need to get vehicle class, if its where's all the air vehicles - dont disable controls for them.
0: Compacts
1: Sedans
2: SUVs
3: Coupes
4: Muscle
5: Sports Classics
6: Sports
7: Super
8: Motorcycles
9: Off-road
10: Industrial
11: Utility (and Trailers)
12: Vans
13: Cycles
14: Boats
15: Helicopters
16: Planes
17: Service
18: Emergency
19: Military
20: Commercial
21: Trains
22: Open Wheels

JavaScript:
const localplayer = mp.players.local;

mp.events.add('render', () =>
{
    if (!localplayer.vehicle || !localplayer.vehicle.isInAir()) return;
  
    let vehClass = localplayer.vehicle.getClass();
    if (vehClass == 15 || vehClass == 16 || vehClass == 18) return;
    
    mp.game.controls.disableAllControlActions(0);
})
 
Реакции: qweqweqwe123123123

Similar threads