RigsOfRods / rigs-of-rods

Main development repository for Rigs of Rods soft-body physics simulator
https://www.rigsofrods.org
GNU General Public License v3.0
991 stars 175 forks source link

Added ✉️ `MSG_APP_UN/LOAD_SCRIPT_REQUESTED` #3045

Closed ohlidalp closed 1 year ago

ohlidalp commented 1 year ago

obrazek

Suggested on Discord: https://discord.com/channels/136544456244461568/189904947649708032/1108018422102622299 - the request was specifically for AI script. I made a solution for any script, though I focused mainly on the AI.

Angelscript API changes:

Demo script updated to showcase the feature and provide useful hints:

    if (ImGui::Button("Start DAF semitruck in follow-mode"))
    {
        // the filename
        // first parameter is index - only use 0/1 for drag race and crash modes. Otherwise use 0.
        game.setAIVehicleName(0, "b6b0UID-semi.truck");

        // 0) Normal driving mode
        // 1) Race
        // 2) Drag Race
        // 3) Crash driving mode
        // 4) Chase the player mode
        game.setAIMode(4);

        // define the start position by inserting initial waypoint.
        game.addWaypoint(game.getPersonPosition() + vector3(6, 0, 6)); // 6 meters away from player

        // define the start direction by inserting another waypoint
        game.addWaypoint(game.getPersonPosition()); // look at player!

        // Request loading the AI script (asynchronously) - it will spawn the vehicle.
        // WARNING: this doesn't save off the setup values above - you can still modify them below and change what the AI will do!
        //          If you want to launch multiple AIs in sequence, register for SE_GENERIC_NEW_TRUCK event - when it arrives, it's safe to setup and launch new AI script.
        game.pushMessage(MSG_APP_LOAD_SCRIPT_REQUESTED, { {"filename", "AI.as"} });
    }
ohlidalp commented 1 year ago

I cherrypicked a few minor fixes which were rotting in the other unfinished branches.

Also I smuggled here one UI improvement that I really want in all dev branches: added Autoload and persistent "Recent scripts" to Console/ScriptMonitor UI - because typos happen and reloading a failed script should be easy. obrazek