Conditional Selection?

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

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

mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Conditional Selection?

Post by mailleweaver »

I am trying to find a way to set a variable equal to the nearest ship while ignoring spacesuits. Is it possible?/How can it be done?
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren »

mailleweaver

<RetVar/IF> find ship: sector=<Var/Sector> class or type=<Value> race=<Var/Race> flags=<Var/Number> refobj=<Value> maxdist=<Var/Number> maxnum=<Var/Number> refpos=<Var/Array>

You could try this one, found under -> Universe and Sector Commands.

For class or type,
This you set to what your looking for, however, if you set 'Ship' or 'Moveable Ship', bith of these include astronauts.

To find nearest,
For flags, in the SE Constants, find and select [find nearest]

This may help ..

MarCon
mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Post by mailleweaver »

I got that far but could not find any way to make it ignore space suits.
The purpose of the script is to allow me to target the nearest unclaimed ship and it's really annoying to have to pick up astronauts to do it. The existing script for this that's downloadable from Xai Corp says it has fixed this bug, but it hasn't. I've found a workaround for now but it's not very clean.

Code: Select all

003   GetShip:
004   $Ship =  find ship: sector=$Sector class or type=Ship race=Neutral Race flags=[Find.Nearest] refobj=[PLAYERSHIP] maxdist=1000000000 maxnum=1 refpos=null
005   if $Ship -> is of type Space Suit
006   |$Ship -> set owner race to Unknown
007   |goto label GetShip
008   else
009   |set player tracking aim to $Ship ->
010   end
As you can see, I just set the script to change space suits to race "Unknown" as it encounters them and then try again. I imagine that if there are astronauts in sector that are quest related this could break their quest association, so this is only a temporary workaround that I would like to actually fix.
Last edited by mailleweaver on Sun, 7. Feb 10, 08:38, edited 1 time in total.
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

If objext is of class 'Space Suit' ?

Use that.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Post by mailleweaver »

No, I want it to select any ship of the race "Neutral" except space suits. (Because bailed ships are of the "Neutral" race.) Since I don't know how to do that, I made the script (for now) change Neutral space suits to race "Unknown" when it encounters them and then repeat until it finds something Neutral to select that's not a space suit. I want to know how to do this without changing space suits' races.
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren »

mailleweaver

Code: Select all

001   
002   $Object =[PLAYERSHIP]
003   GetShip: 
004   $Ship =  find ship: sector=$Sector class or type=Ship race=Neutral Race flags=[Find.Nearest] refobj=$Qbject maxdist=null maxnum=1 refpos=null 
005   if $Ship -> is of type Space Suit
006   |$Object = $Ship 
007   |goto label GetShip 
008   end 
010   set player tracking aim to $Ship ->
Give this a try

You could do it in a 'while' loop, just can't think right now of example to give you, sorry

MarCon
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Mark ahs shown you what I mean, I don't just mean 'If the object is a spacesuit' I undertsand you want to ignore those. I meant, if it's a spacesuit, and then say 'Ignore it!' as that script does. Goes back to the beginning.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Post by mailleweaver »

Wouldn't this then look for a ship that is closest to the space suit (if it finds a space suit before a ship) instead of a ship closest to my ship? Also it looks like that if there are two space suits closer to each other than either is to a ship, it will just jump back and forth between them forever -- infinite loop.
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren »

mailleweaver

You are absolutly right! .. Bad bad bad example, sorry

I think i'll just keep my mouth shut for a bit, rather than give bad advice.

MarCon
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Me too.

Shutting up. :oops:
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
LV
Sith Lord
Posts: 8255
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by LV »

what's wrong with this script which does what your trying?

http://forum.egosoft.com/viewtopic.php?t=219114
LV's TC Scripts
Readme's For All My Scripts


I felt a great disturbance in the forum, Like millions of voices cried out in terror, then were silenced

si tacuisses, philosophus mansisses
mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Post by mailleweaver »

EmperorJon wrote: I meant, if it's a spacesuit, and then say 'Ignore it!'
That's exactly what I want to do but don't know how.

@LV
That script creates an array containing every abandoned ship in the universe and posts it in the message log. How can I make the script search that array to find and target the ship closest to mine?
I'm afraid this is the first script that I've tried to write/edit, and I'm not very familiar with the command library. It seems that it takes hours of research to do even simple things because one must know every command and what it does to be able to choose the right one and then find it. My goal is such a simple one, I hoped someone just knew that "oh, such-and-such command will do that; you just need to define so-and-so variable to put in place of target object type." Or something similar.
User avatar
Nividium
Posts: 800
Joined: Tue, 21. Aug 07, 01:31

Post by Nividium »

Maybe the code shown below would work for you. It gathers all the abandoned ships with "no Pilots" and puts them into an array. Then, it moves your Playership to each abandoned ship and places a Player owned Nav Beacon beside each abandoned ship, so you can claim them now or later.
Don't forget to shoot the Nav Beacon after you claim each ship.

Code: Select all

001   $sector = [PLAYERSHIP] -> get sector
002   $abandoned.ship.array =  find ship: sector=$sector class or type=Moveable Ship race=Neutral Race flags=[Find.Multiple] refobj=[PLAYERSHIP] maxdist=null maxnum=null refpos=null
003   if $abandoned.ship.array
004    $abandoned.ship.array.size =  size of array $abandoned.ship.array
005    while $abandoned.ship.array.size > 0
006     dec $abandoned.ship.array.size = 
007     $abandoned.ship = $abandoned.ship.array[$abandoned.ship.array.size]
008     $abandoned.ship.id.code = $abandoned.ship -> get ID code
009     $is.abandoned.ship.already.scan = $abandoned.ship -> get local variable: name=$abandoned.ship.id.code
010     if not $is.abandoned.ship.already.scan
011      $abandoned.ship.pilot.name = $abandoned.ship -> get pilot name
012      if $abandoned.ship.pilot.name == 'No Pilot'
013       $abandoned.ship -> set local variable: name=$abandoned.ship.id.code value=$abandoned.ship.id.code
014       $abandoned.ship -> set known status to [TRUE]
015       $ship.x = $abandoned.ship -> get x position
016       $ship.y = $abandoned.ship -> get y position
017       $ship.z = $abandoned.ship -> get z position
018       $ship -> set command target: $abandoned.ship
019       $ship -> set destination to $abandoned.ship
020 @     = [PLAYERSHIP] -> move to position: x=$ship.x y=$ship.y z=$ship.z with precision 1000 m
021       $ship.nav.beacon =  create ship: type=Navigational Beacon owner=Player addto=$sector x=$ship.x y=$ship.y z=$ship.z
022       $ship.nav.beacon -> set name to 'abandoned ship'
023      end
024     end
025 @   = wait 2 ms
026    end
027   end
028   
029   return null
mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Post by mailleweaver »

You guys gave me an idea with those arrays.

Code: Select all

001   $sector = [PLAYERSHIP] -> get sector
002   
003   $ship.array =  find ship: sector=$sector class or type=Moveable Ship race=Neutral Race flags=[Find.Multiple] refobj=null maxdist=null maxnum=9999 refpos=null
004   $ship.array.size =  size of array $ship.array
005   while $ship.array.size
006   |dec $ship.array.size = 
007   |$ship = $ship.array[$ship.array.size]
008   |$pilot.name = $ship -> get pilot name
009   |if $ship -> is known
010   ||if $pilot.name == 'No Pilot'
011   |||$ship.distance = get distance between [PLAYERSHIP] and $ship
012   |||if not $target.distance
013   ||||$target.distance = $ship.distance
014   |||end
015   |||if $ship.distance <= $target.distance
016   ||||$target.distance = $ship.distance
017   ||||$target.ship = $ship
018   |||end
019   ||end
020   |end
021   end
022   
023   set player tracking aim to $target.ship ->
024   if not $target.ship -> exists
025   |$failure.message = 'No known unclaimed ships in current sector.'
026   |display subtitle text: text=$failure.message duration=5000 ms
027   end
028   return null
It works! Now, just one more thing.

Code: Select all

009   |if $ship -> is known
This causes the script to only target ship the ship if it has been within scanner range of one of the player's ships sometime in the past regardless of whether they are currently within scanner range. (Or so I assume. I didn't test it against derelict ships that have never been seen.) Is there a way to exclude the ones that are currently out of scanner range of player ships?
User avatar
Nividium
Posts: 800
Joined: Tue, 21. Aug 07, 01:31

Post by Nividium »

Try this: (the get scanner range command is located in the "Fly" commands)

Code: Select all

001   $sector = [PLAYERSHIP] -> get sector
002   $scanner.range = [PLAYERSHIP] -> get scanner range
003   $ship.array =  find ship: sector=$sector class or type=Moveable Ship race=Neutral Race flags=[Find.Multiple] refobj=[PLAYERSHIP] maxdist=$scanner.range maxnum=null refpos=null
mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Post by mailleweaver »

I used that to start with but it excludes ships out of range of Playership even if they are within range of unmanned player-owned ships. I basically want it to include everything that's visible (within scanner range of any player-owned ships) on the sector map at the time the script is run.
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren »

mailleweaver

Ready for some more bad advice ? sorry about the other day.

If you what to check if they are in range of any of your other ships in sector, you will also then need to get your ship array from sector, then include a while loop inside the one you have to get thier scanner range, and you will need to check each ship for this. Some may have duplex and some triplex, and check to see if the derilict ship is in thier scanner range.

This will check all ships you have in sector to see if its in any of thier scanner ranges.

MarCon
mailleweaver
Posts: 79
Joined: Wed, 4. Nov 09, 04:39
x4

Post by mailleweaver »

Thanks everyone. Got it working and posted.

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”