1. Stuck, Having problems with creating your mod? Let us help you: Mod Support

Unsolved 3, 2, 1, GO! "Ai engages at set parameters"

Discussion in 'Mod Support' started by krallopian, Feb 14, 2019.

  1. krallopian

    krallopian
    Expand Collapse

    Joined:
    Dec 5, 2013
    Messages:
    446
    Is this going to be possible? I have a bit of coding experience and know how to write this logically but I don't know if the game will be responsive.

    My plan has been to make a level and use AI as the stars for videos. Now I want more than the usual, "here's a car smashing into another car, like and subscribe and give me money." So an INTRO that is automated - thus controlled consistency - something along the lines of;

    Countdown lights animation plays, after 10 seconds, activate current ai mode.

    Code:
    for(%countDown = 0; %countDown< 3; %countDown++)
    {
        echo(%countDown);
    }
    Or a while,

    }
    Code:
    while(%countDown<= 3)
    {
       echo("Almost ready!");
       %count++;
    }
    }
    As I see it that should work fine, but I'm not sure about setting a countdown STARTER - could probably just command console it - and then inside either the for/while loops just have the "if it has done it's thing, then AI START DOING YOURS!" but that's where I don't yet know where to go with this, or how to find the necessary commands.
     
  2. thomatoes50

    thomatoes50
    Expand Collapse
    Staff Member

    Joined:
    Jan 31, 2013
    Messages:
    585
    you cannot do loops to wait because you will block everything else, Lua is single threaded.
    if you need to wait you can use one of the function that get called really often and count (bad explanation)

    Here is a sample code (it's incomplete and will need modification to work)

    Code:
    local M = {}
    
    local logTag = "myScenario"
    local running = false
    local timer = 0
    
    local function onScenarioRestarted()
        running = false
       timer = 0
    end
    
    local function onScenarioLoaded() --get the map object you want to interract with or the init the AI
        log('I', logTag, "onScenarioLoaded called")
        mylights = scenetree.findObject("mylights1")
    end
    
    local function onRaceStart()
        running = true
    end
    
    -- called every 250ms. use `updateGFX` if you need high frequency/better resolution
    local function onRaceTick(raceTickTime)
        if not running then
            return true
        end
        timer = timer + raceTickTime
    
        if timer > 10 and not activatedAI then
            --foobar()
        end
    end
    
    
    M.onScenarioRestarted = onScenarioRestarted
    M.onScenarioLoaded    = onScenarioLoaded
    M.onRaceStart         = onRaceStart
    M.onRaceResult        = onRaceResult
    
    M.onRaceTick = onRaceTick
    
    return M
     
    • Informative Informative x 1
  3. krallopian

    krallopian
    Expand Collapse

    Joined:
    Dec 5, 2013
    Messages:
    446
    Holy crap porty!! I'll need time to dissect that as my first run through doesn't make sense of it fully, but thank you so much for taking the time!!
    --- Post updated ---
    Pretty certain I'll have to look into creating scenarios afterall haha!
     
  4. thomatoes50

    thomatoes50
    Expand Collapse
    Staff Member

    Joined:
    Jan 31, 2013
    Messages:
    585
    i think your best bet is play one scenario and look at the code to understand what happen backstage.
    you can still ask more question here or in a new subject
     
    • Like Like x 1
  5. krallopian

    krallopian
    Expand Collapse

    Joined:
    Dec 5, 2013
    Messages:
    446
    Thank you again, I'll load up utah and take a look at those as there were camera angles and other things I was interested in there. *cheers!
     
  6. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    5,900
    Sorry, this is bit offtopic.

    This claims to provide multithreading on LUA, without need of coding on C side of things, it uses lua states as threads if I understood correctly:
    https://lualanes.github.io/lanes/

    I have no idea if one could use such inside BeamNG LUA.

    Just thought it might be interesting thing to bring up.
     
  7. thomatoes50

    thomatoes50
    Expand Collapse
    Staff Member

    Joined:
    Jan 31, 2013
    Messages:
    585
    It's a fake multi-threading as it use coroutines
    I don't think that library will work nicely with luajit

    Coroutines are already available in game and there is a module written to simplify the use of it.

    Code:
    local initDB = extensions.core_jobsystem.wrap(function(job)
        --...
       job.yield()
       --...
    end, 0.5)
    
     
    • Informative Informative x 1
  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