Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AngelScript: added message queue bindings. #3025

Merged
merged 3 commits into from Mar 20, 2023

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Mar 7, 2023

There's a new script function game.pushMessage(MsgType, dictionary@) which allows you to do practically any state change within the game (load/unload terrain, actor, connect/disconnect multiplayer). The parameters are passed as dictionary. Documentation will be available at http://developer.rigsofrods.org/ after this PR is merged; for now here is a reprint:

    /**
    * Pushes a message to internal message queue. Parameters are listed in `Script2Game::MsgType` comments.
    * @return True if the message was pushed, false if it was rejected.
    */
    bool pushMessage(MsgType type, dictionary@ dict);
    // Application
    MSG_APP_SHUTDOWN_REQUESTED,                //!< Immediate application shutdown. No params.
    MSG_APP_SCREENSHOT_REQUESTED,              //!< Capture screenshot. No params.
    MSG_APP_DISPLAY_FULLSCREEN_REQUESTED,      //!< Switch to fullscreen. No params.
    MSG_APP_DISPLAY_WINDOWED_REQUESTED,        //!< Switch to windowed display. No params.
    MSG_APP_MODCACHE_UPDATE_REQUESTED,         //!< Rescan installed mods and update cache. No params.
    MSG_APP_MODCACHE_PURGE_REQUESTED,          //!< Request cleanup and full rebuild of mod cache.
    // Networking
    MSG_NET_CONNECT_REQUESTED,                 //!< Request connection to multiplayer server specified by cvars 'mp_server_host, mp_server_port, mp_server_password'. No params.
    MSG_NET_DISCONNECT_REQUESTED,              //!< Request disconnect from multiplayer. No params.
    MSG_NET_REFRESH_AI_PRESETS,                //!< Request refresh of AI presets menu in top menubar. No params.
    // Simulation
    MSG_SIM_PAUSE_REQUESTED,                   //!< Pause game. No params.
    MSG_SIM_UNPAUSE_REQUESTED,                 //!< Unpause game. No params.
    MSG_SIM_LOAD_TERRN_REQUESTED,              //!< Request loading terrain. Param 'filename' (string)
    MSG_SIM_LOAD_SAVEGAME_REQUESTED,           //!< Request loading saved game. Param 'filename' (string)
    MSG_SIM_UNLOAD_TERRN_REQUESTED,            //!< Request returning to main menu. No params.
    MSG_SIM_SPAWN_ACTOR_REQUESTED,             //!< Request spawning an actor. Params: 'filename' (string), 'position' (vector3), 'rotation' (quaternion) 'config' (string, optional), 'skin' (string, optional), 'enter' (bool, optional, default true), , 'free_position' (bool, default false)
    MSG_SIM_MODIFY_ACTOR_REQUESTED,            //!< Request change of actor. Params: 'type' (enum ActorModifyRequestType)
    MSG_SIM_DELETE_ACTOR_REQUESTED,            //!< Request actor removal. Params: 'instance_id' (int)
    MSG_SIM_SEAT_PLAYER_REQUESTED,             //!< Put player character in a vehicle. Params: 'instance_id' (int), use -1 to get out of vehicle.
    MSG_SIM_TELEPORT_PLAYER_REQUESTED,         //!< Teleport player character anywhere on terrain. Param 'position' (vector3)
    MSG_SIM_HIDE_NET_ACTOR_REQUESTED,          //!< Request hiding of networked actor; used internally by top menubar. Params: 'instance_id' (int)
    MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED,        //!< Request revealing of hidden networked actor; used internally by top menubar. Params: 'instance_id' (int)
    // GUI
    MSG_GUI_OPEN_MENU_REQUESTED,
    MSG_GUI_CLOSE_MENU_REQUESTED,
    MSG_GUI_OPEN_SELECTOR_REQUESTED,           //!< Use `game.showChooser()` instead.
    MSG_GUI_CLOSE_SELECTOR_REQUESTED,          //!< No params.
    MSG_GUI_MP_CLIENTS_REFRESH,                //!< No params.
    MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED,        //!< Use `game.showMessageBox()` instead.
    // Editing
    MSG_EDI_ENTER_TERRN_EDITOR_REQUESTED,      //!< No params.
    MSG_EDI_LEAVE_TERRN_EDITOR_REQUESTED,      //!< No params.

The demo script now displays a button "Launch simple test terrain" when in menu, as small test. To try it, open ingame console and say 'loadscript demo_script.as'.

This is an example how to spawn https://forum.rigsofrods.org/resources/1996-dodge-viper-gts-coupe.88/

game.pushMessage(MSG_SIM_SPAWN_ACTOR_REQUESTED, { 
    {"filename", "ViperGTS.car"},
    {"config", "Progressive_5"},
    {"skin", "Viper Yellow/Black Stripe"},
    {"enter", false},
    {"position", vector3(500,1,500)},
    {"rotation", quaternion()}
});

This console snippet spawns Viper GTS directly in front of you: as quaternion qrot = quaternion((radian(3.14) - game.getPersonRotation()), vector3(0,1,0)); vector3 v3pos = game.getPersonPosition() + (qrot*vector3(-5,0,0)); game.pushMessage(MSG_SIM_SPAWN_ACTOR_REQUESTED, {{'filename', 'vipergts.car'}, {'position', v3pos}, {'rotation', qrot}, {'enter', false}});

`eventCallbackEx()` has precedence over `eventCallback()`. Normal `game.registerForEvent()` mechanic applies. Extended arguments are described in 'gameplay/ScriptEvents.h' `enum scriptEvents`.

TBD: The 'type' param of SE_EVENTBOX_ENTER/EXIT is the same as for `defaultEventCallback()`, which means "always 0".

Per request by @AnotherFoxGuy on Discord: https://discord.com/channels/136544456244461568/189904947649708032/1074385401571184740
New script function: `game.pushMessage(msgType, dictionary@)` allows you to do practically any state change within the game (load/unload terrain, actor, connect/disconnect multiplayer). The parameters are passed as dictionary, documentation was added to /docs/angelscript.

The demo script (open ingame console and say 'loadscript demo_script.as') now displays a button "Launch simple test terrain" when in menu, as small test.
added `game.getAllTrucks()`
Removed `game.getNumTrucks()` to avoid confusion.
added missing SE_EVENTBOX_ENTER/EXIT docs
@ohlidalp ohlidalp merged commit fa904b1 into RigsOfRods:master Mar 20, 2023
2 checks passed
@ohlidalp ohlidalp deleted the angelscript_msgqueue branch March 20, 2023 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants