[Help] How to detect player presence in a sector ?

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

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

Post Reply
Dr Reed
Posts: 76
Joined: Fri, 30. Nov 18, 00:05
x4

[Help] How to detect player presence in a sector ?

Post by Dr Reed » Mon, 29. May 23, 19:50

Lets get this out of the way first, my level of programming is on the extreme basic level and everything I have managed up till now has been copy/paste and try to adjust till it works kind of thing.
I have been getting by so far with basic timers to run some events but it's not very optimal to say the least and I am needing help with sorting it out.

What I am trying to do at the moment is detect when the player is in Pious Mists 2 and then start the timer. At first I tried to do a range check for a sector like at the start of the Hatikvah plot but that was too complicated so I looked through some of the other MD files as saw the <event_object_changed_sector> thing so tried that approach instead but cannot seem to get it to work either.

Here's part of what i'm trying to get to work

Code: Select all

<mdscript name="NH_newsectornames" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">

  <cues>
	<cue name="findsomesectors" checkinterval="1s" >
      <conditions>
        <check_value value="player.entity.exists" />
      </conditions>
	<actions>
            <find_sector name="$PiousMistsTwo" macro="macro.cluster_22_Sector001_macro" space="player.galaxy"/>
            <find_sector name="$HeartOfTranquility" macro="macro.NH_ClusterNHS07_Sector001_macro" space="player.galaxy"/>
	</actions>
	</cue>

    <cue name="nhrenamesectors" >
      <conditions>
        <event_object_changed_sector object="player.entity" sector="$PiousMistsTwo" />
      </conditions>
	  <actions>
           <signal_cue cue="powersurge"/>
	  </actions>
		<cues>
			<cue name="powersurge" > 
			<conditions>
				<event_cue_signalled/>
			</conditions>
			<delay exact="10s"/>
				<actions>
				<speak actor="player.computer" priority="90">
					<text page="1121073" line="121035" comment="Ship computer says Gate in Sacred Relic is now activated"/>
					<text page="1121073" line="121036" comment="Sacred Relic"/>
				</speak>
				</actions>
			</cue>
			
			<cue name="preacherclarity" >
				<delay exact="45min"/>
				<actions>
					<find_sector name="$NhUsAlphaOne" macro="macro.NH_ClusterNHS01_Sector001_macro"/>
					<set_object_name object="$NhUsAlphaOne.cluster" name="'{1121070,121087}'"/>
					<set_object_name object="$NhUsAlphaOne" name="'{1121070,121087}'"/>
					<speak actor="player.computer" priority="90">
						<text page="1121073" line="121029" comment="Incoming mapping signal"/>
					</speak>
				</actions>
				<delay exact="2s"/>
				<actions>
					<speak actor="player.computer" priority="90">
						<text page="1121073" line="121030" comment="Preacher's Clarity added to ship computer database"/>
					</speak>
				</actions>
			</cue>
When the sector check is removed the timers work fine and the sectors get renamed.

So in basic English, what an I missing and how to get it to work ?

jan12342203
Posts: 65
Joined: Sat, 14. May 16, 22:13
x4

Re: [Help] How to detect player presence in a sector ?

Post by jan12342203 » Tue, 30. May 23, 10:47

For an event check, we don't need a check interval. If you want this cue checked indefinitely, add an instantiation="true".
The 'check_any' function implies that at least one of the checks must be met in order to proceed to actions.

Try this may it will work for you :-)

Code: Select all

      <cue name="JP_TEST_MD" instantiate="true">
         <conditions>
            <event_object_changed_sector object="player.entity"/>
            <check_any>
               <check_value value="event.param.macro.id == 'cluster_22_Sector001_macro'"/>
               <check_value value="event.param.macro.id == 'NH_ClusterNHS07_Sector001_macro'"/>
            </check_any>
         </conditions>
         <actions>
            <show_help duration="5s" allowclose="true" log="true" custom="'Player entered Sector: ' + event.param.knownname + ' ~ ' + event.param.macro.id"/>
         </actions>
      </cue>

Dr Reed
Posts: 76
Joined: Fri, 30. Nov 18, 00:05
x4

Re: [Help] How to detect player presence in a sector ?

Post by Dr Reed » Wed, 31. May 23, 18:22

Thank you,
I have seen the instantiation="true" but had no idea what it did.

I set up the game with only one mod to run to clear out the chaff and it was this.

Code: Select all

<?xml version="1.0" encoding="utf-8"?>

<mdscript name="how_does_this_work" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
<cues>
      <cue name="do_some_voodoo" instantiate="true">
         <conditions>
            <event_object_changed_sector object="player.entity"/>
            <check_any>
               <check_value value="event.param.macro.id == 'cluster_14_Sector001_macro'"/> <!-- Argon Prime -->
               <check_value value="event.param.macro.id == 'cluster_12_Sector001_macro'"/> <!-- True Sight -->
            </check_any>
         </conditions>
         <actions>
		<speak actor="player.computer" line="[1, 23]" priority="90"/> <!-- chip computer says incomming mesage -->
		<show_help duration="5s" allowclose="true" log="true" custom="'Player entered Sector: ' + event.param.knownname + ' ~ ' + event.param.macro.id"/>
         </actions>
      </cue>
</cues>
</mdscript>
I checked the Xlog and there were no errors which is always a good thing but alas no joy. I also did a find sector $sectorname like in my first post and adjusted to have value="event.param.macro.id == '$sectorname'"

So far it's been easier working out how to add sectors to the game, setting up factions with a kinda balanced economy, race relations, jobs, ship variations, linked anomalies and adding new Betty voice files to the game and a few other things but trying to find where my ship is on the map has almost made me cry a couple of times. lol

Dr Reed
Posts: 76
Joined: Fri, 30. Nov 18, 00:05
x4

Re: [Help] How to detect player presence in a sector ?

Post by Dr Reed » Wed, 21. Jun 23, 16:56

Is there anyone who can shed more light on this for me ?

thanks

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13294
Joined: Sun, 15. Feb 04, 20:12
x4

Re: [Help] How to detect player presence in a sector ?

Post by euclid » Thu, 22. Jun 23, 19:42

I've never used this event but thought it's straightforward ... wrong! I could not get it to work with neither .macro nor .macro.id and guess it's a data type thing. However, I did the more "simple" approach by using the conditions

Code: Select all

<check_any>
      <check_value value="event.param.knownname" exact="{20005,1001}"/> 
      <check_value value="event.param.knownname" exact="{20005,3007}"/>
</check_any> 
and that works fine.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

Dr Reed
Posts: 76
Joined: Fri, 30. Nov 18, 00:05
x4

Re: [Help] How to detect player presence in a sector ?

Post by Dr Reed » Fri, 23. Jun 23, 23:32

Thank you so much for this.

Using the sector name has solved all my problems. :)

Post Reply

Return to “X4: Foundations - Scripts and Modding”