Markk Posted June 19, 2017 Share Posted June 19, 2017 (edited) First, is there a direct way of doing it or does it have to be done through simulating player input? Would one method even have any foreseeable advantages over the other? Either way, can someone point me in the right direction? Regarding the former method, I have considered the following natives: VEHICLE::SET_VEHICLE_FORWARD_SPEEDVEHICLE::_SET_VEHICLE_HALT Under certain circumstances, the first native makes the vehicle fly. Therefore, it is not ideal unless I can find a way to prevent that. In one case, it is okay for the vehicle to instantly be set to a certain speed; I do not care about accelerating there "naturally". It would be useful to be able to constantly keep the vehicle at a certain speed by controlling its speed directly instead of its throttle. However, in another case, I do need it to accelerate naturally (though this case is less important). The second native does not make the vehicle stop in a natural manner; I need the vehicle to stop at the distance it would stop at if the brakes were applied, not some arbitrary distance I specify. Regarding the latter method, I have looked at some natives: CONTROLS::_SET_CONTROL_NORMALCONTROLS::ENABLE_CONTROL_ACTION However, after looking through their documentation, I am still unclear about their purpose and how they would be implemented to simulate player input. Another concern is the brake control also controlling reverse. I suppose I could apply the control until the vehicle's speed is at/near zero, but I do not think that would be ideal for my purposes. Edited June 19, 2017 by Markk Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/ Share on other sites More sharing options...
ikt Posted June 19, 2017 Share Posted June 19, 2017 CONTROLS::_SET_CONTROL_NORMAL simulates player input and can be used to to programmatically control the players' vehicle/movement. There aren't natives for accelerating/braking naturally afaik, but you should be able to assign tasks to peds. You can override throttle and brake in memory but the game keeps overriding those. I haven't checked how it affects non-player vehicles. Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069667018 Share on other sites More sharing options...
ins1de Posted June 19, 2017 Share Posted June 19, 2017 CONTROLS::_SET_CONTROL_NORMAL simulates player input and can be used to to programmatically control the players' vehicle/movement. There aren't natives for accelerating/braking naturally afaik, but you should be able to assign tasks to peds. You can override throttle and brake in memory but the game keeps overriding those. I haven't checked how it affects non-player vehicles. hey, there is a way to simulate acceleration or braking. You can use the void TASK_VEHICLE_TEMP_ACTION(Ped driver, Vehicle vehicle, int action, int time) native. Combined with key presses, you can control a vehicle (with a driver) without even having to control the ped itself. Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069667048 Share on other sites More sharing options...
Markk Posted June 19, 2017 Author Share Posted June 19, 2017 CONTROLS::_SET_CONTROL_NORMAL simulates player input and can be used to to programmatically control the players' vehicle/movement. There aren't natives for accelerating/braking naturally afaik, but you should be able to assign tasks to peds. You can override throttle and brake in memory but the game keeps overriding those. I haven't checked how it affects non-player vehicles. hey, there is a way to simulate acceleration or braking. You can use the void TASK_VEHICLE_TEMP_ACTION(Ped driver, Vehicle vehicle, int action, int time) native. Combined with key presses, you can control a vehicle (with a driver) without even having to control the ped itself. That native seems to be exactly what I need. What is function of the time parameter? My guess is the duration, in ms, of the action to be executed. Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069667153 Share on other sites More sharing options...
ins1de Posted June 19, 2017 Share Posted June 19, 2017 Yes it's the actual action duration in miliseconds. I would recommend you to use short values (100ms to 500ms) if you're using key events. Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069667171 Share on other sites More sharing options...
Markk Posted June 19, 2017 Author Share Posted June 19, 2017 Yes it's the actual action duration in miliseconds. I would recommend you to use short values (100ms to 500ms) if you're using key events. I intend to use it for unknown periods of time. For example, accelerating until a given speed is reached. What would be a good way to implement this - just call the native every frame until the speed is reached? Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069667194 Share on other sites More sharing options...
ins1de Posted June 19, 2017 Share Posted June 19, 2017 (edited) Yes it's the actual action duration in miliseconds. I would recommend you to use short values (100ms to 500ms) if you're using key events. I intend to use it for unknown periods of time. For example, accelerating until a given speed is reached. What would be a good way to implement this - just call the native every frame until the speed is reached? Sounds like a good plan. Check if the vehicle is on all wheels, has not collided with anything and keep calling the native (with short ms again, to avoid the function to be called outside your loop) until it reaches the defined limit. If the speed is suddenly higher (happens during last frame) you can adjust it by setting the vehicle speed directly to it's limit (VEHICLE::SET_VEHICLE_FORWARD_SPEED(float limit); to create a smooth effect. Edited June 19, 2017 by ins1de Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069667226 Share on other sites More sharing options...
Markk Posted June 19, 2017 Author Share Posted June 19, 2017 Yes it's the actual action duration in miliseconds. I would recommend you to use short values (100ms to 500ms) if you're using key events. I intend to use it for unknown periods of time. For example, accelerating until a given speed is reached. What would be a good way to implement this - just call the native every frame until the speed is reached? Sounds like a good plan. Check if the vehicle is on all wheels, has not collided with anything and keep calling the native (with short ms again, to avoid the function to be called outside your loop) until it reaches the defined limit. If the speed is suddenly higher (happens during last frame) you can adjust it by setting the vehicle speed directly to it's limit (VEHICLE::SET_VEHICLE_FORWARD_SPEED(float limit); to create a smooth effect. Thanks for all the help. I have got something working, for the most part. The collision check does not seem to do anything: void update() { Vehicle vehicle = PED::GET_VEHICLE_PED_IS_IN(playerPed, false); if (VEHICLE::IS_VEHICLE_ON_ALL_WHEELS(vehicle) && !ENTITY::HAS_ENTITY_COLLIDED_WITH_ANYTHING(vehicle)) { AI::TASK_VEHICLE_TEMP_ACTION(playerPed, vehicle, 32, 200); }} The vehicle continues to accelerate even if it is in contact with another vehicle. Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069667392 Share on other sites More sharing options...
ins1de Posted June 20, 2017 Share Posted June 20, 2017 (edited) Great! Well I guess it [ENTITY::HAS_ENTITY_COLLIDED_WITH_ANYTHING] doesn't return true because it is checking if your vehicle is on all its wheels at the same time. if((VEHICLE::IS_VEHICLE_ON_ALL_WHEELS(vehicle) && !ENTITY::HAS_ENTITY_COLLIDED_WITH_ANYTHING(vehicle)){ // we rollin' deep}else if((!VEHICLE::IS_VEHICLE_ON_ALL_WHEELS(vehicle) && ENTITY::HAS_ENTITY_COLLIDED_WITH_ANYTHING(vehicle)){// crashed into something, we hit something and at least one wheel left the ground} You can also create a system to prevent collisions at all by raycasting in front of the car. For further information about the TEMP_ACTION native : https://github.com/BenjaminFaal/TwoPlayerMod/search?utf8=%E2%9C%93&q=VehicleAction&type= Edited June 20, 2017 by ins1de Link to comment https://gtaforums.com/topic/889908-c-how-can-the-throttle-and-brakes-of-a-vehicle-be-programmatically-controlled/#findComment-1069669055 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now