Solved Delete/Spawn Vehicles via Scripting

Discussion in 'Mod Support' started by RecklessPancake, Jan 6, 2017.

  1. RecklessPancake

    RecklessPancake
    Expand Collapse

    Joined:
    Aug 25, 2014
    Messages:
    18
    Hi guys,

    How would I script in deleting and spawning in vehicles via scripting? I've looked through the Lua reference and those don't have much info on how to use those functions. I want to make it so that when the player passes through a waypoint, it deletes some farther-away vehicles, and spawns in new vehicles closer to the player. How would I pull this off?

    Thanks!
     
  2. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    173
    This command seems to work.
    TorqueScript.eval('if(isObject("vehicle3'")) {"vehicle3'".delete(); }')

    I do get an error after doing the delete in a scenario. I haven't received a reply to my post.
     
  3. RyvyLo

    RyvyLo
    Expand Collapse

    Joined:
    May 15, 2014
    Messages:
    438
    I don't know of any way of deleting the vehicles without errors (and frankly, looking at the console while playing the demolition derbies with <4 players I don't think the devs have figured it out yet either).

    So there's 2 options here :
    - ignore the errors and use
    Code:
    TorqueScript.eval('if(isObject("vehicle3'")) {"vehicle3'".delete(); }')
    - Or in your case, if you just want to delete vehicles to create others which are closer, you could just teleport the cars and eventually change their jbeam and part config
    I think this code should work; but I haven't tested it since a few version so the result is not guaranteed

    Code:
    TorqueScript.eval([[
                scenario_player0.JBeam = "pickup";
                scenario_player0.partConfig = "vehicles/pickup/v8_4wd.pc";
                scenario_player0.position = "0 0 0.42";
                scenario_player0.rotation = "1 0 0 0";
                scenario_player0.requestReload();
            ]])
     
    #3 RyvyLo, Jan 9, 2017
    Last edited: Jan 9, 2017
  4. RecklessPancake

    RecklessPancake
    Expand Collapse

    Joined:
    Aug 25, 2014
    Messages:
    18
    You guys rock, thanks! I will give that a try when I can.

    I'm assuming/hoping this would also work for AI cars, as that's what I'm hoping to use this for. Is that also the code that should delete/remove objects from a map at the start of a scenario, like theForest from the East Coast USA?

    Most importantly, what reference/API are you guys using to find those commands? I looked through the Lua reference from BeamNG's site (http://wiki.beamng.com/Lua:Reference) but those commands aren't listed.
     
  5. RyvyLo

    RyvyLo
    Expand Collapse

    Joined:
    May 15, 2014
    Messages:
    438
    It should work for any car yes, and I used a similar code to delete a forest object once. (TorqueScript.eval([[theForest.delete();]]) )

    I don't think there's a comprehensive reference of all the commands, here's what I usually do then I want to do something but I have no idea how :
    1- Search for scenarios using a similar function
    2- Search on Internet
    3- Search keywords in the folder BeamNG.drive\lua with the Find in files option with Notepad++, hoping to find something
    4- Trying to write some lines hoping to guess the function names
    5- Try to do it with another method (restart from point 1)
    6- Ask on the forums
     
  6. RecklessPancake

    RecklessPancake
    Expand Collapse

    Joined:
    Aug 25, 2014
    Messages:
    18
    Glad to know I wasn't overlooking an API then. Thanks for the tips!
     
  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