Check if player is currently in first-person mode

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

azaghal
Posts: 393
Joined: Wed, 21. Mar 07, 13:19
xr

Check if player is currently in first-person mode

Post by azaghal »

Hello,

Is there any simple way to determine if the player is currently in first-person mode (walking/flying) or the player has one of the menus (map, station editor etc) open?

To provide some context - I am trying to extend the Report current status mod to display the notification in form of help/hint (using the show_help for cases where the player is not flying or maybe has the docking menu open). In essence when neither the notification nor the interaction boxes are visible. Primary reason I want to do this is in order to not have to interrupt my current activity, yet still have an idea who reported and what (I am aware that the notifications can be sent out to logbook, but I consider that to be equally tedious).

I have poked around a bit through the tutorial scripts to see how EgoSoft takes care of this detection - that code in particular keeps kind of an internal state on whether the map is open or not (which is based on some of the events - namely the event_ui_triggered one). But before I go down that route, just thought I could throw a quick message to see if anyone knows of a simpler solution to get the current state instead.

Best regards,
Branko

UPDATE/SOLUTION

For anyone who runs this one, my initial solution that I posted with reacting to all kinds of UI events is needlessly complicated, and Dj_FRedy has provided a way simpler solution. Simply check for:

Code: Select all

player.isinfullscreenmenu
Last edited by azaghal on Fri, 21. Jun 24, 23:11, edited 1 time in total.
azaghal
Posts: 393
Joined: Wed, 21. Mar 07, 13:19
xr

Re: Check if player is currently in first-person mode

Post by azaghal »

So... I still don't know if it's possible to perform this check in some easier manner, but... I've managed to come up at least with some kind of solution.

There's probably some caveats around this - one is that the cues will trigger a lot (every time you open/close window etc), and the other is the way I've went for global variable set-up. Not quite sure what would be the best way to handle it, but this was also a bit of a quick hack for myself so I can continue playing :)

Another thing is that the list of menus is a bit static - I almost managed to get around this by using a single UI triggered registration, but unfortunately that one did not cover the case where you move around on foot. There is a TopLevelMenu or some such which basically corresponds to your cockpit view - so as you open the map and close it, that one will be getting opened/closed.

In the process I've also found it useful to log the event.param, event.param2, and event.param3 on a blank event_ui_triggered condition. However... Take not that you will most likely want to filter out the Time menu in that case (triggers all the time - all puns intended). The interesting part is that you will also get the Hotkey events as well, which can probably be misused in some rather diabolical ways.

If any modder out there happens to know of a better solution, just let me know, and I'll try to at least update this code snippet here.

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<mdscript name="ReportCurrentStatus" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
  <cues>

    <cue name="Initialise">
      <actions>
        <!-- The RCS_ thing was used mainly as a kind of namespace clutch - just in case someone else decides to name variable $player_can_read_notifications. -->
        <set_value name="global.$RCS_player_can_read_notifications" exact="true" comment="Assume that the player is flying or walking and can read notifications."/>
      </actions>
    </cue>

    <cue name="MenuOpened" instantiate="true">
      <conditions>
        <check_any>
          <!-- Empty control string means the UI was opened. -->
          <event_ui_triggered screen="'OptionsMenu'" control="''"/>
          <event_ui_triggered screen="'PlayerInfoMenu'" control="''"/>
          <event_ui_triggered screen="'DockedMenu'" control="''"/>
          <event_ui_triggered screen="'MapMenu'" control="''"/>
          <event_ui_triggered screen="'EncyclopediaMenu'" control="''"/>
          <event_ui_triggered screen="'HelpMenu'" control="''"/>
          <event_ui_triggered screen="'ShipConfigurationMenu'" control="''"/>
          <event_ui_triggered screen="'StationConfigurationMenu'" control="''"/>
          <event_ui_triggered screen="'StationOverviewMenu'" control="''"/>
          <event_ui_triggered screen="'TransactionLogMenu'" control="''"/>
          <event_ui_triggered screen="'ResearchMenu'" control="''"/>
          <event_ui_triggered screen="'TerraformingMenu'" control="''"/>
        </check_any>
      </conditions>
      <actions>
        <set_value name="global.$RCS_player_can_read_notifications" exact="false"/>
        <debug_text text="'Player can no longer read notifications after opening menu: ' + event.param" />
      </actions>
    </cue>

    <cue name="MenuClosed" instantiate="true">
      <conditions>
        <check_any>
          <event_ui_triggered screen="'OptionsMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'PlayerInfoMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'DockedMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'MapMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'EncyclopediaMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'HelpMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'ShipConfigurationMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'StationConfigurationMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'StationOverviewMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'TransactionLogMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'ResearchMenu'" control="'menu_close'"/>
          <event_ui_triggered screen="'TerraformingMenu'" control="'menu_close'"/>
        </check_any>
      </conditions>
      <actions>
        <set_value name="global.$RCS_player_can_read_notifications" exact="true"/>
        <debug_text text="'Player can read notifications after closing menu: ' + event.param" />
      </actions>
    </cue>

  </cues>
</mdscript>
User avatar
Dj_FRedy
Posts: 245
Joined: Mon, 27. Jun 11, 05:58
x4

Re: Check if player is currently in first-person mode

Post by Dj_FRedy »

Hi azaghal,
Try the following property:

Code: Select all

<keyword name="player" description="Access to player-specific data">
  <property name="isinfullscreenmenu" result="true if any fullscreen menu is shown, false otherwise" type="boolean" />
It may work for your purposes.
"All my contributions to the Technical Support and Public Beta Feedback sections will be concise and to the point, no diatribes, that's what the other sections are for".
Thank you for your efforts.
azaghal
Posts: 393
Joined: Wed, 21. Mar 07, 13:19
xr

Re: Check if player is currently in first-person mode

Post by azaghal »

Dj_FRedy wrote: Fri, 21. Jun 24, 20:32

Code: Select all

<keyword name="player" description="Access to player-specific data">
  <property name="isinfullscreenmenu" result="true if any fullscreen menu is shown, false otherwise" type="boolean" />
It may work for your purposes.
Oh man... Where were six days ago? :)

Perfect, based on what I can tell, this works exactly as expected/needed. Thank you so much! This will make the code way cleaner.

Best regards,
Branko

Return to “X4: Foundations - Scripts and Modding”