Script AI Manager scriptable?

Discussion in 'Programming' started by Harrikan, Jul 11, 2019.

  1. Harrikan

    Harrikan
    Expand Collapse

    Joined:
    Oct 9, 2018
    Messages:
    1
    Hello everyone,
    I have a question about the Script AI Manager, in itself it is possible to display the trips via the GUI. Is it also possible to record the trips via script (except the BeamNGNodeStreamPhysFS class)?

    So, record the trip for a vehicle, call the saved file via script and let it play for another vehicle and also drive behind it?
    Thanks in advance :)
     
  2. Signaltonsalat

    Signaltonsalat
    Expand Collapse
    Goose-typed
    Staff Member

    Joined:
    May 24, 2018
    Messages:
    10
    Heyo, the AI extension for vehicles exposes the recording functionality. In vehicle Lua, you can do this, for example:

    Code:
    ai.startRecording()
    -- Drive around for some time to actually record a script
    -- When finished, stop the recording. The function returns the recorded script
    rec = ai.stopRecording()
    ai.startFollowing(rec)
    In game engine Lua things get a bit trickier because you need to transfer the recording from the vehicle's Lua VM to the game engine's. You can do this via command queueing:

    Code:
    local M = {}
    
    M.startRecording = function()
      local veh = be:getPlayerVehicle(0) -- or whichever you want
      veh:queueLuaCommand('ai.startRecording()')
    end
    
    M.stopRecording = function()
      local veh = be:getPlayerVehicle(0) -- or whichever you want
      local cmd = 'obj:queueGameEngineLua("extensions.hook(\\"onVehicleSubmitRecording\\","..tostring(objectId)..","..serialize(ai.stopRecording())..")")'
      veh:queueLuaCommand(cmd)
    end
    
    M.onVehicleSubmitRecording = function(vehId, data)
      local veh = be:getPlayerVehicle(0) -- or whichever you want
      if veh:getID() == vehId then
        veh:queueLuaCommand('ai.startFollowing(' .. serialize(data) .. ')')
      end
    end
    
    return M
    This is a small sample extension that would allow you to control the scriptAI from game engine Lua. The key line here is the cmd in stopRecording; it makes the vehicle queue a command in game engine Lua which calls onVehicleSubmitRecording on all extensions with the recording obtained from ai.stopRecording(). This way you get the script from vehicle Lua to game engine Lua.
     
  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