Solved Lua execute command

Discussion in 'Mod Support' started by slowgergo, Nov 1, 2018.

  1. slowgergo

    slowgergo
    Expand Collapse

    Joined:
    May 3, 2017
    Messages:
    25
    I made a scenario where i have multiple prop cars. I want to make the car turn off. I could see people use "command":"electrics.toggle_ignition()", but it wont work for me and in the scenarios it is used in. I dont want to make another .pc file for this with no engine or something.
    I attached the file, the console is giving errors so it reacts to the code.

    I searched for this problem but i didnt find anything. But if someone asked it before me then Im sorry and please link it.

    Thank You!
     

    Attached Files:

  2. slowgergo

    slowgergo
    Expand Collapse

    Joined:
    May 3, 2017
    Messages:
    25
    Today i saw a thread where someone said this: powertrain.getDevice("mainEngine"):setIgnition(0) will turrn of the cars engine. I put it vehicle lua in console and it works.
    But how to execute it for the prop car when the scenario starts?

    So how to execute lua command for just one specified vehicle?

    Sorry, clearing things up: How to make a car (NOT PLAYER CAR) in a scenario shut off instantly with lua or the json.
     
    #2 slowgergo, Nov 2, 2018
    Last edited: Nov 2, 2018
  3. RyvyLo

    RyvyLo
    Expand Collapse

    Joined:
    May 15, 2014
    Messages:
    438
    You can queue a vehicle lua command in the scenario lua by using the command : helper.queueLuaCommandByName('vehicleName', 'vehicleLuaCommand'), after importing the scenario helper (local helper = require('scenario/scenariohelper'))

    This would give a code like this (save this text as yourScenarioNameHere.lua in the same folder as your scenario .json)
    Code:
    local M = {}
    local helper = require('scenario/scenariohelper')
    
    local function shutdownEngines()
        
        helper.queueLuaCommandByName('scenario_vehicle0', 'powertrain.getDevice("mainEngine"):setIgnition(0)') -- shutdown the engine for scenario_vehicle0
        
    end
    
    M.onScenarioRestarted = shutdownEngines
    M.onScenarioLoaded = shutdownEngines
    
    return M
    You'll just need to duplicate the queueLuaCommandByName line as much as you have vehicles to shut down
     
  4. slowgergo

    slowgergo
    Expand Collapse

    Joined:
    May 3, 2017
    Messages:
    25

    Oh this makes much more sense than what I wrote. I'll try it out when I got computer near again after school.

    Thank you for your answer!
     
  5. slowgergo

    slowgergo
    Expand Collapse

    Joined:
    May 3, 2017
    Messages:
    25
    I got home, tried it and worked perfectly!!!
    Thank you!
    Now i just have to recreate everything that lost in the file transfering between the new windows and the old one... :(
    I hope nothing like this problem comes up again and i can finish this little story. ;)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice