Scripting help! Modifying an existing script to find all Pandora crates

The place to discuss scripting and game modifications for X³: Farnham's Legacy

Moderators: Scripting / Modding Moderators, Moderators for English X Forum, Moderators for the X3:FL Forums

fireanddream
Posts: 437
Joined: Sun, 13. Dec 15, 07:15
xr

Scripting help! Modifying an existing script to find all Pandora crates

Post by fireanddream »

So I have a script to find all floating crates and create a satellite at their location
Problem is my poor eyesight is suffering from identifying all the Engine Tunings + Rudder Optimizations from a sea of missiles & E-cells...
how can I identify the identity of a floating crate?
The original script looks like this

Code: Select all

    $Sector = get sector from universe index: x=$X, y=$Y
    if $Sector -> exists
      $Temp = find flying ware: sector=$Sector maintype=null subtype=null flags=[Find.Multiple] refobj=null maxdist=null maxnum=99, refpos=null
      $count = size of array $Temp
      while $count
        dec $count = 
        $obj = $Temp[$count]
        if $obj != null
          $num = $obj -> get flying ware count
          $pos = $obj -> get position as array
          $Xpos = $pos[0]
          $Ypos = $pos[1]
          $Zpos = $pos[2]
          $pos = sprintf: fmt='X=%s Y=%s Z=%s', $Xpos, $Ypos, $Zpos, null, null
          $text = sprintf: fmt='%s %s in %s (at %s)', $num, $obj, $Sector, $pos, null
          add non selectable menu item: $menu, text=$text
          $sat = create ship: type=Advanced Satellite owner=Player addto=$Sector x=$Xpos y=$Ypos z=$Zpos
          $text = sprintf: fmt='%s %s', $num, $obj, null, null, null
          $sat ->set name to $text
        end
      end
I believe I need to replace the line <if $obj != null> with something else or add another if beneath that line?
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22436
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Scripting help! Modifying an existing script to find all Pandora crates

Post by Cycrow »

The simplest way, would be to get the ware type and check its one you want

Code: Select all

    $Sector = get sector from universe index: x=$X, y=$Y
    if $Sector -> exists
      $Temp = find flying ware: sector=$Sector maintype=null subtype=null flags=[Find.Multiple] refobj=null maxdist=null maxnum=99, refpos=null
      $count = size of array $Temp
      while $count
        dec $count = 
        $obj = $Temp[$count]
        if $obj != null
          $waretype = $obj -> get ware type code
          if $waretype == Engine Tuning OR $waretype == Rudder Optimisation
            $num = $obj -> get flying ware count
            $pos = $obj -> get position as array
            $Xpos = $pos[0]
            $Ypos = $pos[1]
            $Zpos = $pos[2]
            $pos = sprintf: fmt='X=%s Y=%s Z=%s', $Xpos, $Ypos, $Zpos, null, null
            $text = sprintf: fmt='%s %s in %s (at %s)', $num, $obj, $Sector, $pos, null
            add non selectable menu item: $menu, text=$text
            $sat = create ship: type=Advanced Satellite owner=Player addto=$Sector x=$Xpos y=$Ypos z=$Zpos
            $text = sprintf: fmt='%s %s', $num, $obj, null, null, null
            $sat ->set name to $text
          end
        end
      end
      
Another way would be to use a table, so its easier to define/add more ware types

Code: Select all

    $table = table alloc
    $table[Engine Tuning] = TRUE
    $table[Rudder Optimisation] = TRUE
    
    $Sector = get sector from universe index: x=$X, y=$Y
    if $Sector -> exists
      $Temp = find flying ware: sector=$Sector maintype=null subtype=null flags=[Find.Multiple] refobj=null maxdist=null maxnum=99, refpos=null
      $count = size of array $Temp
      while $count
        dec $count = 
        $obj = $Temp[$count]
        if $obj != null
          $waretype = $obj -> get ware type code
          if $table[$waretype]
            $num = $obj -> get flying ware count
            $pos = $obj -> get position as array
            $Xpos = $pos[0]
            $Ypos = $pos[1]
            $Zpos = $pos[2]
            $pos = sprintf: fmt='X=%s Y=%s Z=%s', $Xpos, $Ypos, $Zpos, null, null
            $text = sprintf: fmt='%s %s in %s (at %s)', $num, $obj, $Sector, $pos, null
            add non selectable menu item: $menu, text=$text
            $sat = create ship: type=Advanced Satellite owner=Player addto=$Sector x=$Xpos y=$Ypos z=$Zpos
            $text = sprintf: fmt='%s %s', $num, $obj, null, null, null
            $sat ->set name to $text
          end
        end
      end
      
Then use add any number of additional table lines for other wares you might want to check

the, if $obj != null check is pretty much pointless though, as there will be no null entries in the array
fireanddream
Posts: 437
Joined: Sun, 13. Dec 15, 07:15
xr

Re: Scripting help! Modifying an existing script to find all Pandora crates

Post by fireanddream »

Cycrow wrote: Fri, 3. Jan 25, 19:22 The simplest way, would be to get the ware type and check its one you want

Then use add any number of additional table lines for other wares you might want to check

the, if $obj != null check is pretty much pointless though, as there will be no null entries in the array
Thanks Cycrow, every time I get the X3 itch I came back to more updates & contents. Truly one of a kind community.

Return to “X³: Farnham's Legacy - Scripts and Modding”