[LIBRARIES] [2008.12.06] My assortment of lib scripts v1.01

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

Post Reply
alex2069
Posts: 205
Joined: Thu, 22. Dec 05, 21:19
x3tc

[LIBRARIES] [2008.12.06] My assortment of lib scripts v1.01

Post by alex2069 » Fri, 5. Dec 08, 11:43

A bunch of library files
by alex2069

:arrow: Install
  • SPK (recommended)

    [ external image ] GameFront (.spk)
    To install, use Cycrow's Plugin Manager.
  • ZIP

    [ external image ] GameFront (.zip)
    To install, extract to your X3TC directory, or more specifically, open the zip file, files in the scripts folder go in scripts folder, t in the t folder.
    If it asks to overwrite any files, do so (will just be an older/same versions or my library files from some of my other scripts).
:arrow: Description
  • I figure I might as well post my libraries for peoples to use. Some of them are probably not very "library-like" and are a bit application specific, but I'm sure there are some that would be very helpful to some people out there.
:arrow: Usage
  • Script a2069.lib.array.merge
    Description: Returns a new merged array
    Arguments:
    * 1: arg.ar1 , Value , 'array1'
    * 2: arg.ar2 , Value , 'array2'

    I got sick of constantly doing the whole get sizes, add them together, create new array, copy first, copy second, etc. So I made it into a script for laziness, lol.
    Usage is simple: i.e.

    Code: Select all

    009 @ $shipyards = [THIS] -> call script 'a2069.lib.array.merge' :  array1=$shipyards1  array2=$shipyards2
    It will return a new array. However if either of the arguments are null, it'll return the array that isn't. Otherwise if both null; it'll return null.
  • Script a2069.lib.array.sort
    Description: Returns a sorted array
    Arguments:
    * 1: arg.ar , Value , 'array'
    * 2: arg.sortBy , Value , 'sort by'

    This is probably the most useful of them all. I was previously using a bubble sort by X-Freak Cartman, but with X3TC there is a new (at least I think it's new to X3TC) array sort function that allows sorting an array based on an array of values. With this, it is MUCH faster.
    sort by:
    Can be a string or an array.
    If it's a string, it will be turned into an array of strings (tokenised by ',').
    However if you need to supply extra sort arguments, you'll need to supply it an array. i.e.
    For my Universal locator it is used as follows:

    Code: Select all

    032   if $arg.isbb
    033   |$sortAr =  create new array, arguments='ware.price', $arg.ware, 'ware.quantity/d', $arg.ware, 'jumps'
    034 @ |$stations = [THIS] -> call script 'a2069.lib.array.sort' :  array=$stations  sort by=$sortAr
    035   else
    036   |$sortAr =  create new array, arguments='ware.price/d', $arg.ware, 'jumps', null, null
    037 @ |$stations = [THIS] -> call script 'a2069.lib.array.sort' :  array=$stations  sort by=$sortAr
    038   end
    Currently the only "sort by" arguments are:
    ware.price - requires a ware
    ware.quantity - requires a ware
    jumps - can have a sector, if it's not supplied assumes [SECTOR] (current ship/object running the script).

    Do not that even though the sort by options are limited at the moment, since the sort script itself is done, and it sorts based on an array of values, it is very trivial to add other sort arguments (ask and it shall be done).
    To order in descending order, add '/d' to the string (like X-Freak Cartman's script).
  • Script a2069.lib.interface.confirmbox
    Description: Easy confirmation box script (returns [TRUE] for OK, otherwise [FALSE])
    Arguments:
    * 1: arg.title , Var/String , 'title'
    * 2: arg.desc , Var/String , 'description'
    * 3: arg.question , Var/String , 'question'
    * 4: arg.heading , Var/String , 'heading (op)'
    * 5: arg.sel1 , Var/String , 'selection1 (op)'
    * 6: arg.sel2 , Var/String , 'selection2 (op)'
    * 7: arg.wide , Var/Boolean , 'wide (op)'

    Simple confirmation box. I was beginning to want it a couple of times throughout my scripts and decided it'd make a nice lib script.
    The first 3 arguments are self explanatory. As for the rest:
    4 - Heading: Defaults to "Confirmation" (the little heading above the "Ok" and "Cancel"
    5 - Selection1: Defaults to "Ok"
    6 - Selection2: Defaults to "Cancel"
    7 - Wide: Defaults to [FALSE] - The pictured is the wide version (info menu), the "normal" version is just a standard menu.

    [ external image ]

    From my auto shop script:

    Code: Select all

    042   if ! $this.transporter AND ! $deliveryTarget.transporter
    043   |if not $deliveryTarget -> is docking possible of [THIS]
    044   ||$question = sprintf: pageid=$pageId textid=300, [THIS], $this.idcode, $deliveryTarget, $deliveryTarget.idcode, null
    045 @ ||skip if [THIS] -> call script 'a2069.lib.interface.confirmbox' :  title='Automated Shopper'  description='Confirm'  question=$question  heading (op)=null  selection1 (op)=null  selection2 (op)=null  wide (op)=[TRUE]
    046   |||return null
    047   |end
    048   end
  • Script a2069.lib.string.fill
    Description: Returns a string with spaces to a specified width to simulate columns
    Arguments:
    * 1: arg.string , Var/String , 'string'
    * 2: arg.fillPos , Var/Number , 'position (l: -1, m: 0, r:1)'
    * 3: arg.width , Var/Number , 'width'

    Another very useful script. Using this will enable you to give your outputs neat "columns". It does this by "filling" the string with spaces up to a specified pixel count.
    I was previously using the function from chem's string library, but it's slow and for some reason didn't work with info menus. I wrote my own version which is MUCH faster, and more accurate (not to mention simpler to use).
    It hasn't had extensive testing yet, so if it produces weird outputs please let me know so I can get it stable.

    Argument Details:
    string: the string, lol
    position: (anything less than -1 = -1, greater than 1 = 1)
    -1 = add spaces to the left of the text
    0 = add on both sides - 1/2 on the left, 1/2 on the right (very little testing)
    1 = add spaces to the right of the text
    width: (this is in PIXELS)
    Most characters are 5 pixels with 1 pixel following, a space = 2 pixels + 1 following. (see the t file for character sizes if you really want).
    Note however that since a space is 3 pixels, it can never be pixel perfect. There may (most likely) be an offset of +/- 1 pixel (nothing I can do about it).

    Example output:
    [ external image ]

    Example using it (from my universal locator):

    Code: Select all

    065   |$output.credits =  convert number $station.ware.price to string
    066 @ |$output.credits = [THIS] -> call script 'a2069.lib.string.fill' :  string=$output.credits  position (l: -1, m: 0, r:1)=-1  width=83
    067   |
    068   |$output.jumpCount =  convert number $station.jumpCount to string
    069 @ |$output.jumpCount = [THIS] -> call script 'a2069.lib.string.fill' :  string=$output.jumpCount  position (l: -1, m: 0, r:1)=-1  width=71
    070   |
    071   |$line = sprintf: fmt=$message.wareText, $station, $station.ware.count, $output.credits, $output.jumpCount, null
  • Script a2069.lib.string.tokenize
    Description: Returns an array of strings based on the string and the token string
    Arguments:
    * 1: arg.string , Var/String , 'string'
    * 2: arg.tokens , Var/String , 'tokens (default: ',')'

    After ditching chems string library (which was cumbersome and slow to use), I needed my own string split/tokenizer.

    Simple to use, and mostly self explanatory:

    Code: Select all

    005 @ |$arg.sortBy = [THIS] -> call script 'a2069.lib.string.tokenize' :  string=$arg.sortBy  tokens (default: ',')=null
  • Script a2069.lib.waremenu
    Version: 210
    for Script Engine Version: 42
    Description: Creates an organised ware menu
    Arguments:
    * 1: arg.title , Var/String , 'Title'
    * 2: arg.desc , Var/String , 'Desc'
    * 3: arg.onlyTraded , Var/Boolean , 'Only Traded?'
    * 4: arg.includeNatural , Var/Boolean , 'Include Natural type?'
    * 5: arg.ship , Var/Ship , 'Ship (op)'

    A handy script for when you want the user to select a ware.

    Argument Details:
    Title: The title of the menu (pictured = "Universal Locator")
    Desc: The description (pictured = "Select a Ware")
    Only Traded?: If [TRUE] will only display wares that can be bought and sold over the universe.
    Include Natural type?: The "Natural" ware type doesn't have anything that can be bought or sold (at least not from my experience), so I figured there's no point having it unless you actually want it.
    Ship (op): If you wish you can specify a ship for the menu to obtain the usable lasers/missiles/shield sub-menu details from. If null, it will revert to [THIS].

    Also note that this menu uses a "caching" scheme... Sort of thing...
    The menu is only generated one (upon using), and is then saved allowing instant use for next time. The most noticeable is selecting "All Wares" which gives a 2-3 second lag on first use, and is instant there-after.
    This "cache" is reset each game load so that any changes/additions to the game wont be missed.

    The main menu:
    [ external image ]

    Usable Lasers sub-section:
    [ external image ]

    Usage is very simple: (from my Universal Locator)

    Code: Select all

    001 @ $ware = $null -> call script 'a2069.lib.waremenu' :  Title='Universal Locator'  Desc='Select a Ware'  Only Traded?=[TRUE]  Include Natural type?=[FALSE]  Ship (op)=[THIS]
  • There are a few others in there that aren't really worth mentioning, but I just kept them all in there since it was easy (and a couple of the mentioned scripts use them).
    The only other one slightly worth mentioning one is: a2069.lib.debug.dump.array
    Give it an array, pageId, etc (self explanatory really), and it dumps it. I plan on adding more detail to what's in the array (ware details/station detail/ship detail, etc) and likely will as I want it (if someone really wants more added ask). It will also dump multidimensional arrays (there is a fail-safe recursion check).
:arrow: Disclaimer
  • I make no guarantees of their functionality or usefulness, lol.
    I wouldn't be surprised at all if there were easier ways to do some of the above things, and if there is, please do tell me.
    I am by no means an expert at scripting, and am constantly learning how to do things in different (read: correct, lol) ways, so if something isn't working correctly, or there is something you'd like added/changed, ask away and I'll see what I can do.
:arrow: Uninstall
  • Uninstall via. the script package.
:arrow: Technical
  • -Uses Text File and Text Page 2068.
:arrow: Version History
  • v1.01 - 2008.12.06 - Fixed null ware menu bug + The ware menu can now accept a ship as an argument.
  • v1.00 - 2008.12.05 - Initial release.
Last edited by alex2069 on Tue, 18. Oct 11, 06:22, edited 3 times in total.

ThisIsHarsh
Posts: 1135
Joined: Sun, 19. Oct 08, 18:46
x3tc

Post by ThisIsHarsh » Fri, 5. Dec 08, 12:07

Some interesting libraries, I can see a few uses for some of them in my own upcoming scirpts.

One comment I'll make on a2069.lib.waremenu. To run it requires you run it on a ship, i.e. $ship->call script ... The problem with that is if the ship is currently doing something it will overrule its current command. Would be better to have e.g. $nul->call script ... : target ship=$ship. That way you can call the script from somewhere else and get a list of wares without interrupting the ships current command.

alex2069
Posts: 205
Joined: Thu, 22. Dec 05, 21:19
x3tc

Post by alex2069 » Fri, 5. Dec 08, 12:14

That's user specific really.
In my case (the code example above - from 'a2069.uniloc.bb'), it's run from a preload script, so it never has an effect on the autopilot or whatever.

ThisIsHarsh
Posts: 1135
Joined: Sun, 19. Oct 08, 18:46
x3tc

Post by ThisIsHarsh » Fri, 5. Dec 08, 12:18

alex2069 wrote:That's user specific really.
In my case (the code example above - from 'a2069.uniloc.bb'), it's run from a preload script, so it never has an effect on the autopilot or whatever.
Well say you want to shop for wares for your brand new carrier using a TS, then you need to fetch the wares for the carrier via the TS, but don't want to interrupt the carrier's current command. That's what I was thinking anyway.

alex2069
Posts: 205
Joined: Thu, 22. Dec 05, 21:19
x3tc

Post by alex2069 » Fri, 5. Dec 08, 12:23

Ahhh... I get you now, lol.
I misread your first reply, now I understand. That's actually a good idea; I'll have to do that (gave me an idea for use with another of my scripts as well).

alex2069
Posts: 205
Joined: Thu, 22. Dec 05, 21:19
x3tc

Post by alex2069 » Sat, 6. Dec 08, 09:29

Minor update v1.01 - parts of the waremenu were still referring to the old libs, and the waremenu can now accept a ship as an argument. If not supplied (null), defaults to [THIS].

dmatter
Posts: 25
Joined: Tue, 10. Oct 06, 14:41
xr

Post by dmatter » Sun, 11. Jan 09, 09:21

hello

I wanted to know if I could translate your script in French

and your library on the English text takes in the code, do you can put it in a "t" file does so that we can translate your library in french

best regards

Post Reply

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