[HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

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

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

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

[HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Tue, 16. Feb 21, 06:41

Hi,

From the beginning of X4, I was very annoyed by the far too simple target switching. In order to rarely have to go to the menu while controlling via HOTAS (and of course in battles), I not only want to be able to select the next targets or the very nearest enemy, I want to be able to select missiles, switch through enemy fighters and capital ships separately, as well as gates, stations, etc. Actually pretty much the same as X3-Freak-Cartman this for X3 already once in the MOD optimized target acquisition implemented...
Now, with SirNuke's Mod Support APIs incl. hotkey engine, this is within reach.
BUT: Where do I start? How do I even address the target mechanics via MOD? Has anyone ever tried this? Do I have to mod the UI for this or are there direct "commands"?
Thanks for the help!
Regards

Schmollo
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Sun, 7. Mar 21, 01:47

Hey guys, does just nobody have an idea (so it doesn't work) or does nobody find this exciting? Or has the translator (D->EN) eaten something here that nobody can do anything with my question?
I want to start working on it myself, but I need some kind of approach, maybe a few script lines that simply mark some ship that meets certain criteria, then I can experiment with it...
Egosoft can't hear my criticism of the lack of hotkeys in the German forum anymore, I guess, and I'm not alone there. Unfortunately, the German modder scene is hardly present in the German forum.

Thanks already, I believe in you ;-)

Greetings Schmollo


Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

Cyres
Posts: 61
Joined: Tue, 5. Jan 16, 08:22
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Cyres » Sun, 7. Mar 21, 21:08

The translation is totally fine. In general, deepl is great at translating.

I'd love to see a mod for this but sadly I can't help you here, I never was into modding for XR or X4.

SirNukes
Posts: 546
Joined: Sat, 31. Mar 07, 23:44
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by SirNukes » Mon, 8. Mar 21, 03:03

Well, I don't know if anyone here has experience with selecting targets from code. At a glance, the normal x4 scripts don't have a way to change the target. Looking through the lua, ffi functions like SetSelectedMapComponents (used in the menu_map.lua code) may provide a way to switch player targets. However, it would mostly be up to you to experiment and figure it out.

If/when you do get target selection working, the rest is just some fun md scripting for the various functions you want to add.

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Mon, 8. Mar 21, 07:28

Sir Nuke's correct. No way to target objects except through Lua.

The methodology is:
1. From the Mission Director (md, XMLScript), find an appropriate target (via closest, next, prev, etc.)
2. Send it to Lua via md's "raise_lua_event" function.
E.g.

Code: Select all

<raise_lua_event name="'kShipScnr_set_target'" param="$ship" />
3. Lua then triggers the C.SetSoftTarget () function.
E.g.

Code: Select all

function newFuncs.kShipScnr_set_target (_, object)
	-- DebugError ("kuertee_ship_scanner.lua.kShipScnr_set_target.object " .. tostring (object))
	local object64Bit = ConvertStringTo64Bit (object)
	-- DebugError ("kuertee_ship_scanner.lua.kShipScnr_set_target.object64Bit " .. tostring (object64Bit))
	C.SetSofttarget(object64Bit, "")
end
My mods, "Ship Scanner" and "Loot Mining" both acquire targets of different types and in different conditions then sets them to either be a "soft target" or a "mission guidance".
So ... all doable. Just need someone to put it all together.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Wed, 10. Mar 21, 22:02

Ha! That's great news for a start! Also that it is obviously a meaningful project.

Above all, thanks for the approach - it's a lot of stuff for me with little programming experience, so it will take time, but I'll gladly accept such a challenge and start by trying to understand Kuertee's scripts. I'm sure I'll have questions here though.... But first, let's get started...

@Kuertee: Did I understand correctly that you can actually do "real" target switching (is that what you mean by "soft target")? Because I tried your mods, and you always have to accept a task then, and that would be way too cumbersome. What you are looking for is that a target is simply unlocked with a key, like in the regular target switching from Egosoft (press 1 key = next target)? However, I may have done something wrong. Where exactly (which mod, which situation) did you really switch on targets? I would also appreciate a short reference to the script in which I can find this...

Otherwise, thank you very much, I'll be in touch :-)

Schmollo

PS: Wasn't there an introduction to the MD somewhere? Unfortunately I can't find it quickly. Also maybe a command overview? Would help...

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Thu, 11. Mar 21, 01:08

schmollo wrote:
Wed, 10. Mar 21, 22:02
@Kuertee: Did I understand correctly that you can actually do "real" target switching (is that what you mean by "soft target")? Because I tried your mods, and you always have to accept a task then, and that would be way too cumbersome. What you are looking for is that a target is simply unlocked with a key, like in the regular target switching from Egosoft (press 1 key = next target)? However, I may have done something wrong. Where exactly (which mod, which situation) did you really switch on targets? I would also appreciate a short reference to the script in which I can find this...
"soft target" is just what egosoft calls their weapon targeting system - the white square.
i just use it for consistency. because there are also, of course, travel/mission targeting system and the "invisible" targeting system that keeps track of what's in front of you (e.g. for signal leaks, station and ship scanning).

my mods that change soft targets are my QOL mods:
1. Loot Mining: once an asteroid is mined, the nearest asteroid of the same mineral is soft targeted.
2. Ship Scanner: once you finish a ship scan, the nearest ship that has not been scanned is both soft targeted and mission targeted. this is probably a good mod to look at for research. and the script name is md\kuertee_shipscnr.xml.

but, yes, the "soft target" can be changed on a keypress. and the code can target specific objects/components based on that keypress. E.g. ship_xl, ship_l, ship_m, engines, shield generators, turrets, etc. changing soft targets don't need an active mission.

i learned modding on these 3 resources:
1. looking at another mod, specifically: loktide's original signal leak hunter
2. mission director guide: https://www.egosoft.com:8444/confluence ... ctor+Guide
3. these links from this page: viewtopic.php?t=402382: PSA about Linux compatibility, md/ui reload commands, XML patch

usually, i'd take on requests/suggestions that interests. but I'm busy with my mod at the moment.
and this does interest me. i wanted to build a mod that targets ship components nearest the player, rather than current system of cycling through all of a ship's components. i never got around to it.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Thu, 11. Mar 21, 14:59

kuertee wrote:
Thu, 11. Mar 21, 01:08
...
Many, many thanks! That helps a lot and I will get to it as soon as I have time.

As for your idea with the ship components, I can try to integrate that as well. It also bothers me a lot that I always have to switch through everything. And once I get the hang of it, it's probably just hard work. The question is anyway how I distinguish between near and far targets, especially since that changes constantly in flight, but I'm sure I'll figure that out. Probably a third key is needed: component in close proximity...

Yes, there are many projects :-) For me, everything is grouped around the hotkeys, because that's where the immersion gets lost for me, when I have to go to the map for every crap, including releasing the HOTAS and grabbing the mouse... And there are many ideas. Target switching, missile favourites, wing commands, direct jumps to submenus like personnel management (marked ship) or whatever.


Well, and music. I have a small MOD with little code (only DIFF replacements) but a lot of searching and testing in progress (not published), which assigns exactly ONE music to each sector, which of course only works with all the music from X-BTF to X4. But now there's a lot of confusion again due to 4.0, after adjusting it I'll surely publish it sometime...

Until then :-)

Greetings Schmollo

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Tue, 27. Apr 21, 00:22

Good evening :-)

There is news: I have started :-) And a lot of beginner questions, sorry...

Thanks to Forleyor, I now have a kind of functioning basic framework for the MOD, especially with the targets "targeting" and the direct jump to some menus. However, he doesn't have time to work on the MOD any further and, according to his own statement, hates MD scripts :-)

He seems to have processed the original code for switching on enemies - which of course I want to change. This is how it looks:

Code: Select all

    <cue name="Mhk_TargetNearestEnemy" instantiate="true" namespace="this">
      <conditions>
        <event_cue_signalled/>
      </conditions>
      <actions>
        <find_ship name="$ships" class="[class.ship]" space="player.zone" multiple="true" sortbydistanceto="player.entity">
          <match owner="faction.player" negate="true"/>
          <match_attention min="attention.visible"/>
        </find_ship>
        <set_value name="$ship" exact="null" />
        <do_all counter="$i" exact="$ships.count">
          <do_if value="$ships.{$i}.ishostileto.{faction.player}">
            <set_value name="$ship" exact="$ships.{$i}" />
            <break />
          </do_if>
        </do_all>
        <do_if value="$ship">
          <raise_lua_event name="'MoreHotkeys.targetNearestEnemy'" param="$ship" />
        </do_if>
      </actions>
    </cue>
So there is a function "find_ship". Elsewhere in I found "find_object". What else is there? For example, is a goal an object? And a factory? What is that?

Is there a description of these functions somewhere, what you can specify there and what it must be called? Unfortunately I didn't find anything in the XR-Wiki, "find_ship" doesn't lead to any hits, not even Google.

Next: Is there a list somewhere of the other variables? What else is there besides "player.zone", for example? I want to search sector-wide, but of course only what has already been discovered.
Then: What does it mean?

Code: Select all

<match owner="faction.player" negate="true"/>
<match_attention min="attention.visible"/>
In this case, an enemy ship is being searched for, what does that have to do with the player? And is "visible" that it is already detected or simply not too far away and thus visible on the radar? For gates, this would have to be cancelled out... What does negate="true" mean?

Let's take the example above - what should the search look like, for example, if I don't want to find enemies, but only the player's own ships? Or factories (for landing). Or discovered gates...

One last question: How does X4 handle the switching of targets if there are several? Do I understand correctly that once an arrey is defined with e.g. "find_ship", then X4's own buttons for switching through the targets in this array will work? Or would I then have to write routines for "next" and "prev" or define only keys in both directions?

Thanks for the answers and sorry for all the beginner questions. My last serious programming was Basic and a little Assambler on an Atari 8-bit, but that was pretty extensive... Long time ago. :-)

So maybe one more question: Are the MD scripts perhaps based on a concrete programming language that can be learned? So completely outside of X4? And where is the description of the "adaptation" by Egosoft, i.e. the additional, game-based commands? Surely can't hurt to broaden one's horizons....

THANK YOU for all the answers...
Greetings Schmollo aka Trajan from Olb

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Wed, 28. Apr 21, 04:07

So there is a function "find_ship". Elsewhere in I found "find_object". What else is there? For example, is a goal an object? And a factory? What is that?
there are other find_* functions, like find_station.


Is there a description of these functions somewhere, what you can specify there and what it must be called? Unfortunately I didn't find anything in the XR-Wiki, "find_ship" doesn't lead to any hits, not even Google.
Next: Is there a list somewhere of the other variables? What else is there besides "player.zone", for example? I want to search sector-wide, but of course only what has already been discovered.
Then: What does it mean?
in my ide, sublime, i have these files open in the 2nd frame:
  • common.xsd: you'll find most functions, like find_station, here.,
  • md.xsd: this is mission specific functions, like create_mission. you won't need this for this targeting mod, i don't think)
  • scriptproperties.xml: this lists all the datatypes in accessible in the md and the datatype's properties. e.g.: station.modules.
  • aiscripts.xsd: for aiscripts. you may want to look at this for this specific mod.
  • the language file: 0001-l044.xml. i use this to find things in X4's base scripts that's been extracted from the *.cats. e.g. if i hear somewthing spoken in the game, e.g. "i need back-up". i look for that text in here. then use its text id to find where in the game it gets used.
note that some may have these files loaded in personal web server so that they can be navigated in a browser easier. but i find reg-ex search on the base scripts for keywords that i need to be much faster. for e.g. i need to find a turret on a station. i don't know how. so i search for "find.*turret" in the base folder. usually, that will turn up the solution. at the least, it will point to how it can be done, if not.

but a user from discord (https://discord.com/channels/3370982909 ... 0877228042) did host the scriptproperties.html file here: https://x4-docs.s3.amazonaws.com/x4_4_0 ... rties.html


Code: Select all

<match owner="faction.player" negate="true"/>
<match_attention min="attention.visible"/>
In this case, an enemy ship is being searched for, what does that have to do with the player? And is "visible" that it is already detected or simply not too far away and thus visible on the radar? For gates, this would have to be cancelled out... What does negate="true" mean?
well, the ship needs to be an enemy of the player, right? so you need the player reference there.

"attention.visible" is a constant. there is also "attention.nearby", "attention.zone", etc. this determines the state of the object in relation to the player. "attention.*" is listed in common.xsd.

EDIT: "negate" simply means that if a ship is found with owner set as "faction.player", skip that match. i.e. do not match ships owned by the player.


Let's take the example above - what should the search look like, for example, if I don't want to find enemies, but only the player's own ships? Or factories (for landing). Or discovered gates...
find_ship and set the owner to "faction.player". for gates, it's similar. find_object and set class to "gate" or something like that. you'll know how once you get the hang of the xsds - the reference files.


One last question: How does X4 handle the switching of targets if there are several? Do I understand correctly that once an arrey is defined with e.g. "find_ship", then X4's own buttons for switching through the targets in this array will work? Or would I then have to write routines for "next" and "prev" or define only keys in both directions?
i don't know, sorry.


Thanks for the answers and sorry for all the beginner questions. My last serious programming was Basic and a little Assambler on an Atari 8-bit, but that was pretty extensive... Long time ago. :-)
no worries. i'm happy to help whenever i can. I bugged SirNuke's (on this forum and on the unofficial Discord) and Unitrader (on the unofficial Discord) for months when I started modding X4 8 months ago.


So maybe one more question: Are the MD scripts perhaps based on a concrete programming language that can be learned? So completely outside of X4? And where is the description of the "adaptation" by Egosoft, i.e. the additional, game-based commands? Surely can't hurt to broaden one's horizons....
XML scripting. it's only a "format"? (i don't know). the actual X4 API is in those xsds.



Good luck! Ask questions again. Join that Discord. You'll find a more immediate response there.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Sun, 2. May 21, 04:34

Hi,

first of all, thank you very much, dear Kuertee, for the informative text, which really, really helped. :)

After a few teething problems, things really progressed today. I now have a version in which I can already switch through stations, gates and my own ships. At the moment I'm thinking about making only two of them instead of many forward-backward buttons for each purpose, which evaluate the current destination and switch forward or back accordingly. Plus, of course, buttons for each to switch the mode to "own" or "goals" or "enemies". This will be good :-)

However, I have a few problems and therefore questions. :gruebel:

1. at the moment ALL things that are in the sector are switched through - regardless of whether they have already been discovered. It doesn't matter with your own stuff, but finding undiscovered stations or gates this way is not good. Any idea how I can limit this already in the search (find_station and find_gate) so that only the already known (or with the scanner uncovered) things get into the target? With "visible" it doesn't work, that's just the distance.... At the moment it looks like this (here the example with the stations):
Spoiler
Show

Code: Select all

    <cue name="Mhk_TargetNextStation" instantiate="true" namespace="this">
      <conditions>
        <event_cue_signalled/>
      </conditions>
      <actions>
        <find_station name="$stations" space="player.sector" multiple="true" sortbydistanceto="player.entity">
<!--           <match owner="faction.player" negate="false"/> -->
          <!-- <match_attention min="attention.visible"/> -->
        </find_station>
        <set_value name="$station" exact="null" />
        <set_value name="$ptarget" exact="player.target" />
        <set_value name="$ptindex" exact="$stations.indexof.{$ptarget}" />
		<do_if value="($ptindex gt 0) and ($ptindex lt $stations.count)">
			<set_value name="$station" exact="$stations.{$ptindex + 1}" />
		</do_if>
		<do_else>
			<set_value name="$station" exact="$stations.{1}" />
		</do_else>
        <do_if value="$station">
          <raise_lua_event name="'MoreHotkeys.targetAllThings'" param="$station" />
        </do_if>
      </actions>
    </cue>
2. with find_gate I can only open jump gates and accelerators. How can I also get to the entrances to the superhighways (at best in one go)? find_object + something? I can't really see through the "class" things yet...

3. is there any way to find out the "object" of the missile fired at you in order to unlock it? There is "event_object_incoming_missile", but how do I deal with it to unlock the next incoming missile at the push of a button?

4. I would like to define favourites as targets (the current target), which can then - if in the sector - be selected directly or marked as a waypoint in the entire universe with an extra button. Can I use global variables somehow? And how do I have to define them beforehand?

5. I would like to add sound, how do I call it up? Just as well as spoken texts (they are already there, you just have to search for them)...?

Thanks for the answers...

Greetings Schmollo aka Trajan von Olb

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Sun, 2. May 21, 05:01

That's good news, Schmollo.

Here are my answers. I hope they can help.

1. <property name="isknown" result="true iff the component is known to the player" type="boolean" />
2. hmmm... i don't know, actually. but these are specific classes that may help: class.highwayentrygate, class.highwayexitgate
3. the param3 of event_object_incoming_missile is the ship that fired it. maybe you can use that with event_lock_acquired.
4. you can add your variables to the "global" scope. e.g. <set_value name="global.$my_var" exact="true" />
5. how to play sounds, I don't know. But to play a voice file, you'll need an NPC. E.g. <speak />. Note that your ship's computer is also an NPC. Search the language files for what she can speak.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Sun, 2. May 21, 15:14

Thanks again for the help!!! :)

Unfortunately, the problem is somewhat different. For example, I have already found "unknown", as well as "class.highwayentrygate"... But how do I use the knowledge? Do I have to do something with "match"? Where do I get the correct command? Or do I have to do something directly after "find_station"? If so, how? I already tried this yesterday, but without success! Unfortunately, I always need concrete examples. :gruebel:

My real problem is that I haven't quite understood the Mechanics behind the syntax of the programming language. Yesterday I made a lot of progress in one day - a lot of things are also logical if you have examples 8) - but just using all the additions, e.g. to "find_ship" or others, I have to try everything out. How do I deal with the classes? I also don't yet understand the many special characters that are used. When does a $ have to come before a variable? When not? When does something belong in these brackets: {}? Not everything is in the MD Guide.
At the moment, the sources I have are the common.xsd directly from the directory in Firefox, this "Script Property Documentation" under x4-docs (where a lot is missing!), the MD-Guide from Egosoft and, of course, many foreign mod scripts, which I have to search through. Most of the time I logically find the things I'm looking for, but I can't do anything with the following code, for example.
Spoiler
Show

Code: Select all

<xs:element name="find_station">
<xs:annotation>
<xs:documentation> Find matching station(s) </xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="matchbase">
<xs:attributeGroup ref="action"/>
<xs:attributeGroup ref="findstation"/>
<xs:attribute name="space" type="spacelist" use="required"/>
<xs:attribute name="append" type="findappend"/>
<xs:attribute name="multiple" type="findmultiple"/>
<xs:attribute name="required" type="findrequired"/>
<xs:attributeGroup ref="sortresultwithlimit"/>
<xs:attribute name="name" type="lvaluename"/>
<xs:attribute name="groupname" type="groupname"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
What is that supposed to tell me? :? :? :?

Maybe it doesn't make sense to do everything as before with Notepad++, supposedly you can make your life easier with other tools by including the XSDs directly in the programme so that you get suggestions right away - is there maybe a guide somewhere about a (free or cheap) software? What do you work with, for example, Kuertee?

But again briefly to the actual questions, to get ahead there, see also the code in the spoiler of the previous post):

1. do you have a concrete example (see above)? What should a "find_station" statement look like? Or does it have to be followed by something with "match"? What exactly? For example, what does the "min" mean in the "<match_attention min="attention.visible"/>" that I commented out? And can I also use a "not" somewhere? Because I want to find known and not unknown stations... The other day I tried it with "<match_attention min="not attention.unknown"/>" - without success, nothing was found afterwards.
Alternatively, I can also (very reluctantly, because then I can't use "+1") query this with an additional do loop, which however must not start with 1 but with the position after the current target (at the moment "$ptindex+1"), but what do I put after "do all" to achieve this? And how do I query the object itself? So what has to be put behind e.g. "$stations{$i}.??? == ???"?
2. likewise: how exactly would I have to insert this? Then presumably with "find_object", right? Maybe you can provide such a line that looks right. UNd are normal goals also objects, so that I can find everything with one search? Or I have to do two searches and put them together, but then gates would no longer be sorted by distance...
Do you mean that I first have to find the firing ship in order to find the missile above it? Or have we misunderstood each other - I want to unlock the rocket myself (although the ship is also an idea)...
Thank you, that helps!
5. ok, that's a good hint, it's about Betty, of course. I would love to find her much more talkative :-) And many sounds are there, you just have to call them up (which the game unfortunately doesn't do)...

So, now I have to apologise again for all the questions. But it will get better, I promise :-)

Greetings Schmollo

Translated with www.DeepL.com/Translator (free version)
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Sun, 2. May 21, 17:38

schmollo wrote:
Sun, 2. May 21, 15:14
My real problem is that I haven't quite understood the Mechanics behind the syntax of the programming language. Yesterday I made a lot of progress in one day - a lot of things are also logical if you have examples 8) - but just using all the additions, e.g. to "find_ship" or others, I have to try everything out. How do I deal with the classes? I also don't yet understand the many special characters that are used. When does a $ have to come before a variable? When not? When does something belong in these brackets: {}? Not everything is in the MD Guide. At the moment, the sources I have are the common.xsd directly from the directory in Firefox, this "Script Property Documentation" under x4-docs (where a lot is missing!), the MD-Guide from Egosoft and, of course, many foreign mod scripts, which I have to search through.
Ahhh yes, I understand. I find that the best examples are Egosoft's base code. I use Sublime Text editor. And if I do a reg-ex search of all instances of "find_object" in Egosoft's base code, I get something like this. See? I get an example on how to use matches. Then I just go down the list of search results to find something that I matches my need as close as possible. Then, if that doesn't produce anything usable, I start to search what sort of matches I use, by search for "match.*whatever". Then if that doesn't produce anything, I'll try a different search. E.g. looking at Egosoft's code, I can guess how they name their variables. So I search for something like "$foundShips".
Spoiler
Show

Code: Select all

D:\games\steam\steamapps\common\X4 Foundations\extensions\base\md\conversations.xml:
  557              <do_elseif value="['shipyard', 'wharf', 'equipmentdock', 'tradestation', 'piratebase'].indexof.{event.param2.{1}}">
  558                <set_value name="$target" exact="null" />
  559:               <find_station name="$targets" space="player.galaxy" multiple="true"
  560                              shipyard="event.param2.{1} == 'shipyard'"
  561                              wharf="event.param2.{1} == 'wharf'"
  ...
  565                  <match owner="faction.player" negate="true" />
  566                  <match_relation_to object="player.entity" comparison="ge" relation="dock" />
  567:               </find_station>
  568                <do_if value="$targets.count">
  569                  <!-- Get all targets that are at the minimal gate distance -->
  ...
 1598              <set_value name="$localclusters" exact="$localclusters.keys.sorted"/>
 1599              <do_all exact="$localclusters.count" counter="$i">
 1600:               <find_station name="$locequipmentdock" space="$localclusters.{$i}" equipmentdock="true" known="true">
 1601                  <match_content class="class.buildmodule" checkoperational="true"/>
 1602                  <match_relation_to object="event.object.assignedcontrolled" relation="enemy" comparison="not"/>
 1603:               </find_station>
 1604                <do_if value="$locequipmentdock">
 1605                  <debug_text text="'found equipment dock %s %s %s, %s gates away.'.[$locequipmentdock.idcode, $locequipmentdock.knownname, $locequipmentdock, event.object.gatedistance.{$locequipmentdock}]" chance="100"/>

D:\games\steam\steamapps\common\X4 Foundations\extensions\base\md\drain_stations.xml:
  117                  <set_value name="$Sector" exact="$Sectors.{$SectorIdx}"/>
  118                  <do_if value="$Sector.owner">
  119:                   <find_station name="$Stations" space="$Sector" tradestation="true" multiple="true">
  120                      <match_attention max="attention.insector" />
  121                      <match owner="faction.player" negate="true"/>
  122:                   </find_station>
  123                    <debug_text text="'Drain_Stations processing %1 stations in %2'.[$Stations.count, $Sector.knownname]" chance="$Debugchance"/>
  124                    <do_all exact="$Stations.count" counter="$i">
As for the Syntax of X4's XML Script, I learned from examples. You'll get it after a while.
Most of the time I logically find the things I'm looking for, but I can't do anything with the following code... SNIPPED ...
Yes, that is a little obscure. When loaded in an XSD reader, you'll get a graphical diagram linking those node to each other. But I found that I don't need it.

When I first started, I refered to how Egosoft used "find_station" in their base code while looking at this find_station entry in the common.xsd. Now that I'm more familiar with reading these XSDs via their raw XML, I simply read the node names, then search for it in the xsds. E.g. for attributeGroup ref="findstation", I would search for "group.*findstation" to see "findstation" attributes. You'll get the hang of searching through these files soon enough.
...What do you work with, for example, Kuertee?
I use Sublime Text Editor. And I learnt how to reg-ex search the folders.




Question 1
1. do you have a concrete example (see above)? ... SNIPPED ...
I would do a loop of all stations found and add only those stations known in another array that I then use. By the way, I was also confused with the "attention" property. Now I know that "attention" determines what the game shows you visually and simulates in front of you and what the game simulates in the background (what you can't see, e.g. in another sector).

Anyway, onto how I would use "isknown" to filter stations that are not know to the player.

Code: Select all

<find_station name="$stations" ... your code here ... />
<create_group groupname="$knownStations" />
<do_all counter="$i" exact="$stations.count">
    <do_if value="$stations.{$i}.isknown">
        <add_to_group name="$knownStations" object="$stations.{$i}" />
    </do_if>
</do_if>



Question 2
2. likewise: how exactly would I have to insert this? Then presumably with "find_object", right? Maybe you can provide such a line that looks right. UNd are normal goals also objects, so that I can find everything with one search? Or I have to do two searches and put them together, but then gates would no longer be sorted by distance...
I think you can do a find_object and put all the classes that you want to find in a list. Use the same match parameters that you use. I don't know all of them. I look-up Egosoft's code whenever I need a match parameter that I don't know of.

Code: Select all

<find_object name="$objectsIWant" class="[class, station, class.highwayentrygate, class.gate]" space="player.galaxy" multiple="true" sortbydistaneto="player.entity" />



Question 3
Do you mean that I first have to find the firing ship in order to find the missile above it? Or have we misunderstood each other - I want to unlock the rocket myself (although the ship is also an idea)...
I think I misunderstood your question. Particularly, what you mean by "unlock the rocket". Can you rephrase the question a different way? Hopefully, DeepL would translate it a different way to before. Or if you want, you can describe it as a picture. E.g. enemy ship fires missile at you -> missile approaches your ship -> I want to target the missile.




Question 5
5. ok, that's a good hint, it's about Betty, of course. I would love to find her much more talkative :-) And many sounds are there, you just have to call them up (which the game unfortunately doesn't do)...
Yeah, she's got many voiced lines. I think you can do something like: <speak actor="player.computer" line="X" />
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Sun, 2. May 21, 18:29

Hey, that was fast! Thanks a lot!

And it helps a lot. I'll deal with the "Sublime Text editor" later, is it right that it compares the syntax with the xsd files from Egosoft and shows errors? That would be an added value compared to Notepad++. And the "reg-ex" search, does it search all Egosoft files? Because I don't know exactly what you mean by Egosoft's base code. Where is it? The common.xsd? Or the many files in the original MD folder? I have looked there, but it is very tedious and I have not found much... For example, I'm desperately looking for the code for switching on a target directly ahead. This is so unreliable, surely it can be improved (and extend, why not switch on a destination that is known, even if it is far away, a gate for example)...

About the questions:
1. thanks, sure, I could have thought of that myself, a pre-loop to sort out.... Damn :-) So there's no way to narrow it down already in the "find_..." command....
2 All right, great, I'll try it out. Just one question of understanding: Why does it say in the code "class, station" again, if I only need the concrete gates? Is that a definition of some kind? And: I use "player.sector" for the targets, which is the sector, i.e. everything you can fly to without gates, right? Is there any reason to do something different?
3 Exactly, only simpler. It's not about automation but about hotkeys. If I press, then it should find the next enemy missile that has me as a target. Better still an array (list) with something like "find_", then I can switch through that. Only: what are enemy missiles? objects with their own class?
5. i LOVE betty! A little side project is to let me announce (in VRO, where there are the "old" missile types) the switched-on missile, because it's so hard to tell otherwise.... Later there could also be hotkeys for favourites again (or at least sorted by type), because I find it extremely exhausting to always find the right rocket immediately when I want to annoy someone...

As always, thank you very much!

Best regards for Sunday

Schmollo
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Sun, 2. May 21, 19:03

schmollo wrote:
Sun, 2. May 21, 18:29
... SNIPPED ...is it right that it compares the syntax with the xsd files from Egosoft and shows errors? That would be an added value compared to Notepad++.
no. I'm sure there's a way to link the code to the definition files (XSDs). But I don't know how. You know that you can change your code and reload them in-game, right? By typing "/refreshmd" on the chat window. It won't work with new XMLs. But it reloads all the XMLs that already exist.
And the "reg-ex" search, does it search all Egosoft files? Because I don't know exactly what you mean by Egosoft's base code. Where is it? The common.xsd? Or the many files in the original MD folder? I have looked there, but it is very tedious and I have not found much...
Here's my Sublime Text X4 Project setup-up. And I find the reg-ex search results to be very informative in regards to how to use the functions found in the XSDs. look at the example of a search result that I posted in my previous reply.
Spoiler
Show
Image
For example, I'm desperately looking for the code for switching on a target directly ahead. This is so unreliable, surely it can be improved (and extend, why not switch on a destination that is known, even if it is far away, a gate for example)...
The targeting code that determines what is targeted is actually hard-coded and is not available to us modders. But you should be able to create a mod with your own key that determines what in front of the player is targeted. Just make sure the old target commands in the Settings is not bound to this new key. (I just released a mod, Surface Element Targeting, that goes about targeting the nearest surface element to the player but without the use of key commands (because that is hard coded). Instead, that mod targets the next nearest surface element AFTER the last one is destroyed. So ... that mod addresses the problem of needing to loop through all surface elements just to get to the surface element that you can target by solving it indirectly. That mod solves that problem by using code that is available to us: find nearest object, after destruction event.)
About the questions:1. thanks, sure, I could have thought of that myself, a pre-loop to sort out.... Damn :-) So there's no way to narrow it down already in the "find_..." command....
Maybe. I don't know how. Sometimes, there's no direct way of doing something, and doing it another way that works is never the wrong way because it works.
2 All right, great, I'll try it out. Just one question of understanding: Why does it say in the code "class, station" again, if I only need the concrete gates? Is that a definition of some kind? And: I use "player.sector" for the targets, which is the sector, i.e. everything you can fly to without gates, right? Is there any reason to do something different?
you can add all that you want to find in the list so that they are ordered by distance. if you search for them separately, then they won't be ordered by distance. i thought you wanted the gates to be ordered by distance along with the stations. if not, then do a separate find for the gates.
3 Exactly, only simpler. It's not about automation but about hotkeys. If I press, then it should find the next enemy missile that has me as a target. Better still an array (list) with something like "find_", then I can switch through that. Only: what are enemy missiles? objects with their own class?
Ahhh ... then you'll need to do a search ordered by distance, then do a loop to remove the currently targeted missile - similar to filtering out unknown stations. AFTER removing the currently targeted missile, the first missile in the search result must be the next nearest, right?
As always, thank you very much! Best regards for Sunday Schmollo
You're welcome. And it's Monday morning here. I'm in Sydney, always about 12 hours ahead.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Sun, 2. May 21, 19:59

Thank you very much!

The picture is not displayed, but there is no hurry, today I will continue with notepad++, there is even a way to match the syntax with the md.xsd, I am thrilled :-)
kuertee wrote:
Sun, 2. May 21, 19:03
The targeting code that determines what is targeted is actually hard-coded and is not available to us modders. But you should be able to create a mod with your own key that determines what in front of the player is targeted.
...
Yes, I have already looked at and analysed your mod. That was already helpful. But the challenge with "target ahead" is different. Because the current target capture is indeed not working well. It should specifically "capture" the target under the middle cursor according to my wish, so I guess I have to deal with 3d vectors. But that will have to wait. "Quick and dirty" would be to simply simulate a mouse click in the middle, which is how I currently do it with my HOTAS button :-)
Just one question of understanding: Why does it say in the code "class, station" again, if I only need the concrete gates?
you can add all that you want to find in the list so that they are ordered by distance.
...
That was a misunderstanding. I only need the gates for this hotkey. The stations are another. Nevertheless, the question with class="[class, station, class.highwayentrygate, class.gate]": why do I need the entry "class" at the beginning? Wouldn't "class.highwayentrygate, class.gate" be sufficient? Or is that some syntax rule that the umbrella term has to be at the beginning? Or could I just leave it out? I am trying to understand this.
Ahhh ... then you'll need to do a search ordered by distance, then do a loop to remove the currently targeted missile - similar to filtering out unknown stations. AFTER removing the currently targeted missile, the first missile in the search result must be the next nearest, right?
Sure, that's clear. Only: How do I search for rockets in the first place. I have not found a "find_missile" command. Do I have to use "find_object"? And what kind of class is that then? I have not been able to find that out yet...
And it's Monday morning here. I'm in Sydney, always about 12 hours ahead.
Ok, here in Leipzig / Germany it's almost 8 o'clock in the evening. Best regards to Sidney :-)

That reminds me: If you need German translations somewhere, I'll be happy to help... Just let me know and send me a t-file / content.xml. e-mail if necessary via PN (is easiest without webspace)...

Greetings Schmollo

PS (EDIT):
You know that you can change your code and reload them in-game, right? By typing "/refreshmd" on the chat window.
But sure, I have already built a keyboard macro :-) Without it, it would be very... boring with the waiting...
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Mon, 3. May 21, 03:29

schmollo wrote:
Sun, 2. May 21, 19:59
The picture is not displayed, but there is no hurry, today I will continue with notepad++, there is even a way to match the syntax with the md.xsd, I am thrilled :-)
sorry. try this direct link: https://lh6.googleusercontent.com/yrwT9 ... 20-h880-rw
... That was a misunderstanding. I only need the gates for this hotkey. The stations are another. Nevertheless, the question with class="[class, station, class.highwayentrygate, class.gate]": why do I need the entry "class" at the beginning? Wouldn't "class.highwayentrygate, class.gate" be sufficient? Or is that some syntax rule ...
nah, it was an error from me. it's suppose to be class.station. but, nevermind, because you don't need it.
... How do I search for rockets in the first place. I have not found a "find_missile" command. Do I have to use "find_object"? And what kind of class is that then? I have not been able to find that out yet...
maybe ... class.bullet with find_object. search for "classlookup" in the XSDs for other classes.
... That reminds me: If you need German translations somewhere, I'll be happy to help... Just let me know and send me a t-file / content.xml. ...
Oh, Thank you! I will keep that in mind.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Trajan von Olb
Posts: 545
Joined: Wed, 4. Feb 04, 21:39
x3tc

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by Trajan von Olb » Mon, 3. May 21, 03:47

Ok, after a hard fight, everything is now going well for a start. I have hotkeys for the next enemy (which will be supplemented by missiles later), the next own ship, the next factory and the next gate. also a forward and backward key that switches through the respective target types depending on the "mode".... Fine. However, it looks like I'd want to swap Egosoft's forward-backward buttons for my own entirely....
That's why there's a 5th mode with no filter (so it allows everything in the vicinity), which is activated, for example, when you press the forward and back hotkeys with no active target. So it's like Egosoft.This mode should always become active when I have changed or deselected the target with the mouse or an Egosoft key function.
It seemed to me that "<event_player_changed_target/>" would be suitable for this, and I saw that you have also made your experiences with it. Is it possible that this event is somehow unreliable? Or am I missing something? Or are global variables written with maybe delay, which messes everything up?
I use a global variable ("global.$mhkchangetarget") that is always set (=true) by my own target switch before the Lua event to flag my own action - unlike mouse actions or those of egosoft. The event (target change) should both set the targeting mode to 0 and reset the flag ("global.$mhkchangetarget")... But it does not work. Sometimes it works briefly, then not again... What am I doing wrong?
Here is the code of this event:

Code: Select all

    <cue name="Mhk_TargetChangeBaseGame" instantiate="true">
      <conditions>
        <event_player_changed_target/>
      </conditions>
      <actions>
		<do_if value="global.$mhkchangetarget">
			<set_value name="global.$mhkchangetarget" exact="false" />
		</do_if>
		<do_else>
			<set_value name="global.$targetingmode" exact="null" />
		</do_else>
      </actions>
    </cue>
Thanks for any answers... again... :-)

Greetings Schmollo
Mein Traum vom Glück ist der Traum von einer anderen Menschheit. (S. Lem)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [HELP / REQUEST / PROJECT] improved target activation with SirNuke's hotkeys

Post by kuertee » Mon, 3. May 21, 04:17

schmollo wrote:
Mon, 3. May 21, 03:47
...It seemed to me that "<event_player_changed_target/>" would be suitable for this, and I saw that you have also made your experiences with it. Is it possible that this event is somehow unreliable? Or am I missing something?
i found this event to work ok.
Or are global variables written with maybe delay, which messes everything up?
i don't know. but I don't think so.
I use a global variable ("global.$mhkchangetarget") that is always set (=true) by my own target switch before the Lua event to flag my own action - unlike mouse actions or those of egosoft. The event (target change) should both set the targeting mode to 0 and reset the flag ("global.$mhkchangetarget")... But it does not work. Sometimes it works briefly, then not again... What am I doing wrong?
hmmm ... i don't know again. sorry. but did you know that in Lua, false != 0? and true != 1? but in MD, when you set a variable to true it's set to 1 internally? try setting your var to 1 instead.
Here is the code of this event:
this code looks ok.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

Post Reply

Return to “X4: Foundations - Scripts and Modding”