Do you want to "disable" the engine or "shutdown" the engine (eg simply "turn it off")? On the default game settings if the engine is simply "turned off" then the vehicle controller will attempt to restart it using the starter motor. So you can't really leave it shut down and expect to start it back up whenever you want to... the game will try to crank it as soon as it's off. This code should kill the engine if run in Vehicle Lua, although I don't know if it's the best way: Code: powertrain.getDevice("mainEngine"):lockUp() This should stall the engine, but as I said it's only for a brief time: the game will automatically attempt to restart the engine. As before, this should be run from Vehicle Lua. Code: powertrain.getDevice("mainEngine").isStalled = true
I feel like I addressed this above. If the engine is off then the vehicle controller will attempt to turn the engine back on. EDIT: In other words, the game does not currently have support for "the engine is just off until the player says to crank it up" when settings are on defaults. I think one of the "realistic" gameplay settings probably changes that but...
I just tried that line of code, and it didn't stall my vehicle.. I was referring to being able to run code that would mimic the user turning off their vehicle with the ignition control.
I edited my post above to clarify a bit. In response to your latest post: Did you run it in Vehicle Lua? Make sure you have your volume turned up enough to hear the engine stop/start.
Yes, my mistake, I tried it again and I did notice the message in the upper left hand corner very briefly gives the engine is off message when using your line of code for stalling the engine. However, I am able to press a button I have mapped to the ignition control, and when in realistic shifting mode, I can turn off the engine and it will stay off until I press and hold the ignition button, and it will start up for me, when I want it to. I am just wondering if you can use a line of lua code to mimic that control, and simply switch off the ignition like using the button would.
I'm not familiar with the input mapping you refer to as "ignition control", can you tell me the exact name I'd look for?
That simply activates the engines starter motor. Operating a switch for a starter motor is not the same as operating an ignition switch. Please try this exercise for me. Start up the game and load a level and vehicle with your gearbox mode set to realistic. From the vehicle lua console, run this code: Code: print(powertrain.getDevice("mainEngine").isStalled) The game will print to the console whether the engine is stalled, it should be "false". Now toggle out of the console, press a button you have mapped to "Activate the engine starter motor" in order to get the motor turned off. Now run the above lua command again. It should now read "true". See what I'm getting at? IMO there's no good way to do what you guys want right now.[/code]
I understand that. But when you say to press the button to shut the engine off, that's what I'm referring to when I say to use lua code to mimic turning the ignition off. If you're able to press a button to shut the motor off and keep it shut off until I want to restart it, it should be possible to use a lua code to do the same thing.
This could all be broken later, but here is code that will "turn the engine off"... given all the above caveats (it's not an ignition switch, etc etc): Code: powertrain.getDevice("mainEngine").outputAV1 = 0 And of course this will crank the engine back up: Code: powertrain.getDevice("mainEngine"):activateStarter() I would not be at all surprised if all of this was broken in an update or two. EDIT: doesn't seem very reliable either. I'm sure there's a better way, but I doubt that there's a good way right now. If you are really determined you can use a counter or timer to run the first code block over a few frames. That should get it to work consistently. --- Post updated --- Actually try using this one to shut the engine off, this seems effective and reliable. All of the above warnings still apply of course. ;-) Code: powertrain.getDevice("mainEngine").starterThrottleKillCoef = 0;
I actually implemented this properly for 0.9. Here's what you need to do: Code: controller.getController("vehicleController").setEngineIgnition(false) This works for anything that is controlled by a vehicleController (so any regular car). If you want to go more low level and talk to the powertrain directly you can also use this: Code: powertrain.getDevice("mainEngine"):setIgnition(0) However, the direct approach won't work correctly with the vehicleController since it will just try to restart the engine. (Also make sure to adapt the code to whatever your engine device is called)