Skip to content

Nexus Miniscripts

I get bored & write random scripts. Nexus needs a lot more user-side scripts.

Monospaced display on Nexus can be aggravating at times. As far as I can see, there is no way to modify the monospaced output from Nexus itself. Monospec is a script for until this option is built into Nexus.



BEFORE



AFTER



Download here.

Usage:
  1. -monos to display available monospaced fonts
  2. -monos # to select a specific font
  3. -monos # # to specify a font-size with a specific font
  4. -mono to reset to LiberationMono at 11pt
  5. Set monospec.default & monospec.size within the onLoad script to set a default setting
If you're interested you could extend to use the client's serverside memory to remember your settings; I haven't for several reasons.

For those interested in learning Javascript, this miniscript has a few extra things including a neat way to remove&inject CSS rules without re-polluting the page, a simple example of Promises (deferred functions), and jQuery's AJAX method.

NB: I wouldn't swap the monospace font too frequently within one session as there is no way to clean up the pre-existing CSS rule without trawling through the page's HTML.
vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

«13

Comments

  • Ever wondered it would be like to have a 3d healthbar in Nexus? Inspired by this gorgeous Codepen, Lifebar provides a sample to generate your own 3d gauges.



    Download here.

    Also happy to take requests if the required triggers are provided.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • edited December 2018
    Had a giggle.

    If you use Chrome & depending on your version of hardware + software, you can now talk to your ship to fly it.

    Download here.




    You have the conn, Starmourn Commander.

    -ssp to start voice recognition.

    May you have better luck without an accent. I may tweak it to improve the user experience but for whatever reason window.webkitSpeechRecognition works reliably only on my Mac not my Windows. So probably not.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • Does anybody know how to make a trigger based off of you changing targets with the TAB key?  I can echo target changes to the main output but it doesn't seem to trigger anything when I code for it.  Is there another way of knowing when a target changes?
  • edited January 2019
    duplicate post
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • edited December 2018
    @Yalau

    Yes, great request. Prescient thanks to you! It is fairly self explanatory but let me know if you can't get it to work.

    Download here.

      // remember that we call this every time we reload the script, so we have to tidy up our mess
      //   in this case, we overwrite our master call to 'prescient'
      
      $(document).off('prescient')
        
      // We create a master trigger so we can keep it clean
      $(document).on("prescient", function(e) {
         var name = arguments[1]
         var newv = arguments[2]
         var oldv = arguments[3]
         // your code here
         switch(name) {
           case 'tar':
             // console.log('Target changed from ' + oldv + ' to ' + newv + '.') // uncomment to check it working in console.log
             // if (typeof myCustomNameChangeFunction == 'function') { myCustomNameChangeFunction(newv, oldv) }
             break;
           default:
             break;
         }
      })

    You can place whatever code in the 'tar' case but cleaner to place in your own function saved somewhere else.

    If you need to know when
     1. target is changed AND
     2. the TAB key is being pressed at the time it is changed,
    not just when target is changed, please let me know.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • edited December 2018
    Could you explain how this detects the change in target when tab is pressed? Thank you
  • edited January 2019
    duplicate post
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • First we track down where TAB takes us in Nexus:
    This function does quite a number of things we may not want to interfere with, so we pick the last line as our target: client.set_current_target( id, true )

    This looks fairly complicated. Can we find a suitable place to insert our code? I picked line 1287's client.set_variable( name, value ) because that appears to be where variable assignment happens. Looking past it, the rest of the code appears to be involved in UI changes only, so inserting our code before it should be fine.

    Now we look at .set_variable. It is a fairly simple function with no variables that we might be scoped out of, so it is fairly safe to assume everything we overwrite will be correct.

    Then we look at our code:
    pre = typeof pre != 'undefined' ? pre : {}
    
    pre.init = function() {
      // rewrite the client.set_variable
      //    thankfully, the function is simple & doesn't invoke any scoped-out variables
       
      client.set_variable = function(name, value) {
        if (typeof name != 'string') { return }
        if (name.indexOf('"') >= 0)  { return }
        if (name.indexOf('\\') >= 0) { return }
        name = name.trim()
        
        var old = client.vars[name]
        client.vars[name] = value
        if (client.vars[name] != old) { $(document).trigger('prescient', [name, client.vars[name], old]) }
        // Personally would prefer it earlier but no insurance people won't go (trigger => retrieve variable [old])
      }
      
      // remember that we call this every time we reload the script, so we have to tidy up our mess
      //   in this case, we overwrite our master call to 'prescient'
      
      $(document).off('prescient')
        
      // We create a master trigger so we can keep it clean
      $(document).on("prescient", function(e) {
         var name = arguments[1]
         var newv = arguments[2]
         var oldv = arguments[3]
         // your code here
         switch(name) {
           case 'tar':
             // console.log('Target changed from ' + oldv + ' to ' + newv + '.') // uncomment to check it working in console.log
             // if (typeof myCustomNameChangeFunction == 'function') { myCustomNameChangeFunction(newv, oldv) }
             break;
           default:
             break;
         }
      })
    }
    
    pre.init()

    The bolded lines tell us how we remember things so that we can tell if things have changed.

    var old = client.vars[name] saves Nexus' remembered variable into old for us to test later.

    if (client.vars[name] != old) {...} checks to see if the new variable is different from old.

    { $(document).trigger(...) } is a neat jQuery way to fire off an event for something to listen for.

    { $(document).trigger( eventNamedata ) } lets us call this prescient and assign [name, client.vars[name], old] as our data to pass on to our listeners.

    Then,

    $(document).on(...) is our listener.

    $(document).on( "prescient", function(e) { ... } ) tells our listener to listen for prescient. When it does this, it runs the function.

    $(document).on( "prescient", function(e) { .. switch(name) { case 'tar' } ... }) is our internal evaluation of what prescient events is telling us; in this case it is evaluating to see if namearguments[2], is tar which is Nexus' holding name for Target (fully qualified, it is client.vars.tar). When it matches, we run our custom function.

    I hope this helps, and if you already knew most of this, maybe it might help someone else. The main thing here is leveraging jQuery which Nexus uses to fire off an event for us to listen to - this lets you write discontinuous code & not worry to much about where your code ends up. The nice thing about Javascript & jQuery is that if you've thought about it, someone else has already probably solved it on Stackoverflow.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • Awesome thank you so much for the detailed response!  This is amazing and exactly what I needed!  It's opened up so many coding possibilities.
  • Created a very rough DPS tracker for Nexus. 

    Key Commands:

    dpstoggle (alias) - activates/ deactivates DPS Tracker
    resetdps (alias) - resets the damage/ balance Tracking variables

    This is crude, executed using only the simplified scripting options. 
    https://ufile.io/95q9m
  • edited January 2019
    Does the OCD in you want to punch someone every time you see something like this?
    <div>A heap of rusty equipment indicates a JUNK shop here.<br></div><div>[s] -> A shining road filled with pedestrians and vehicles
    [nw] -> The back room of the Quickmark Pawn (closed)</div>
    Wouldn't you rather have a nice justified exit list?
    <div>[  s] -> A shining road filled with pedestrians and vehicles<br></div><div>[ nw] -> The back room of the Quickmark Pawn (closed)</div><div>Health: 1230/1230 NN: 6.50M SA: 100.00% [BW-]</div>

    Trigger
    ^\[(n|s|w|e|ne|nw|se|sw|u|d|in|out)\] \-&gt; (.*)$
    Code
    <div>var lpad = function(str, len, ch) {
      if (typeof str == 'number') { str = str.toString() }
      if (ch == null) { ch = ' ' }
      var r = len - str.length
      if (r < 0) { r = 0 }
      return ch.repeat(r) + str }<br></div><br><div>var matches = arguments[0]
    var exit    = matches[1]
    var named   = matches[2]
    var str     = ''
    
    exit = lpad(exit, 3)
    // console.log(exit + ' > ' + named)
    
    str = '[' + exit + '] -> ' + named
    
    Nexus.replace_current_line(0, matches[0].length, str) </div>
    Only downside is that Nexus doesn't allow tag insertion so you lose your exit clickability. There is a hack-around but it is a PITA.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • tysandr said:
    Does the OCD in you want to punch someone every time you see something like this?
    No, it doesn't!

    But nice script anyway, it certainly sheds light on how to achieve certain things in nexus.
  • Is there a script where I can use my numpad to fly my ship? And can it be toggled on/off? I'm so clueless with coding, I tried to go in there and fiddle and it blew up in my face almost literally. Thanks in advance to any kind soul out there who can help me...
  • Rhea asked for a way to improve the readability of the input line;
    onLoad
    
    $('#data_form').css('font-size','23pt')
    
    This should do the trick. I was over-engineering again.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • Pretty sure CORS-Anywhere is (rightfully) limiting requests so we'll wait on a Starmourn CORS fix. GG.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • A couple of updates:

      added in qw parsing
      added in Minei's XML headers for the CORS bypass
      added in chaining so the API calls are sent in sequence
      
      added a little processing at the end of db.a
      
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • CORS headers should be available on the API now.
  • tysandr said:
    So this isn't quite a miniscript but:


    Sometimes I start to think I am finally figuring out Nexus and Javascript in general... and then you post something.  :(
  • H'okay. :| A few thing-a-ma-bobs

    There is quite a bit of new code so let me know if/when/how it breaks. Now stretching to over 1,000 lines of code which in retrospect means I should've not designed it like a namespaced module. :| Live & relearn I guess.

    Firstly, 'qw' no longer does a capture & update; this should've been a separate command from the start & is now 'qwf'.

    Secondly, the module now polls for updates:
     - every minute, it checks for when you last sent data to the Starmourn server
     - if you have not passed a new command to Starmourn for 5 minutes, it will go into an IDLE mode
     - every 3 minutes, if it is in IDLE mode, the module will grab 20 random entries from your DB that has not been updated for at least 90 minutes
     - it will then request API data for these 20 entries
     - you can 'db.ps' to stop the polling.

    Thirdly, 'db.u' now only requests updated API data for DB entries that have not been updated for at least 90 minutes

    Fourthly, 'db.fu' is now the syntax for forcing an API update of all entries in the DB.

    Fifthly, I have added a whole bunch of calculations to db.s which are likely to have errors, so please let me know.

    Sixthly, 'db.del <player>' is added.


    On the coding side of things, there are plenty of new places for shit to break. :| Currently, there's no way to change the settings on the polling, i.e. the frequency of checking & size of requests per batch but will probably add that in in an update.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • tysandr said:

    The new version is exponentially faster than the first with updating and populating the names from qwf, awesome job there!

    I did get a couple random errors when testing the db.u command

    "(ndb): ndb requesting truncated update of 122 from 277 records.
    (ndb): Error accessing name: Beardedwhispers, error is [object Object].
    (ndb): Error accessing name: Bishop, error is [object Object].
    (ndb): ndb completed retrieval of 122 records."
  • Yes, sorry, haven't found a consistent way to recognise the error messages without hanging the Promise chain; it's probably an easy fix that I haven't had time to look into yet. Those messages are (hopefully just) the server telling us those players no longer exist.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • So the best I can come up with so far is this:
      var chainUpdate = function(list) {
        // reset progress meter 
        progress = []
          
        // UI control
        if ($('#ndb-progress-meter').length) { $('#ndb-progress-meter').remove() }
        $('body').append('<div id="ndb-progress-meter"><div id="ndb-progress-outer"><div id="ndb-progress-inner"></div></div><div id="ndb-progress-current"></div><div id="ndb-progress-total"></div><div id="ndb-progress-closer" onclick="$(\'#ndb-progress-meter\').remove()">x</div></div>')
          
        var url = urlAPI
        if (useCORS) { url = urlCORS + url }
    <b>
        var dels = []</b>
        list.forEach(function(item,index) {
          p = p.then(function() { return retrieveAPI(url.replace('ALPHA', item)) }).then( function(data) {
             // console.log(data)  
             if (typeof data == 'string') { report(data) } else {
               add(data.name, data.faction, data.class, data.race, doSuppress)
               db[data.name].keyed = new Date().getTime() // last update time
             }
             // update progress UI here
             var r = progress.length / list.length * 100
             if ($('#ndb-progress-inner').length) { $('#ndb-progress-inner').css('width', r + 'px') }
          }).catch(function(data) {
    <b>        var err = ', error is '
            if (typeof data.state == 'function') {
              var nerr = data.state()
              if (nerr == 'rejected') {
                err += ' player no longer exists. Attempting deletion.'
                dels.push(item)
              } else {
                err += nerr  
              }
            } else { err = '' }
            report('Error accessing name: ' + item + err + '.') </b>
          })
        })
        p.then(function() {
          console.log('Completion with progress at ' + progress.length + '.')
          report('<span class="ndb gold">ndb</span> completed retrieval of ' + progress.length + ' records.')
    <b>      if (dels.length > 0) {
            report('Attempting deletion of ' + dels.length + ' records.')
            for (var i = 0; i < dels.length; i++) {
              remove(dels[i])   
            }
          }</b>
        })
      }

    For some reason, I cannot locate where ajax receives the 404 code, so the best I can get is a .state() returning "rejected". This code will replace current code inside of chainUpdate if you want to update it yourself, but I will include it at some stage in the formal .nxs file. :|


    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • @tysandr Hey, just wanted to say this is really great.  Can't wait to tear into the code to see how you did all this.  It's really cool.
    Download Montem System for Nexus Client - https://pastebin.com/MBEn7S0u
  • Tired of trying to remember your aliases?

    Type .sal for all your Nexus aliases, or .sal <search-term> to filter your aliases for a specific term.


    Download here.
    vote ∘ Explore Nexus mods for Starmourn & Achaeandb for Nexus

  • edited January 2019
    Here's a quick little tool that shows you just the value of all the junk currently on you, without the big list of each individual piece of junk, when you use the alias 'jc' (short for junk count):

    Junk Counter
  • @tysandr Many many thanks for your code, I discovered the awesome Ow_write function which lets me color all my letters individually! Still learning how javascript and nexus work but it's been really great to look at your code so far!
  • edited January 2019
    Jinresh said:
    tysandr said:

    The new version is exponentially faster than the first with updating and populating the names from qwf, awesome job there!

    I did get a couple random errors when testing the db.u command

    "(ndb): ndb requesting truncated update of 122 from 277 records.
    (ndb): Error accessing name: Beardedwhispers, error is [object Object].
    (ndb): Error accessing name: Bishop, error is [object Object].
    (ndb): ndb completed retrieval of 122 records."
    Yeah I always get these exact same errors

    (ndb): ndb requesting truncated update of 294 from 294 records.
    (ndb): Error accessing name: Beardedwhispers, error is [object Object].
    (ndb): Error accessing name: Eidi, error is [object Object].
    (ndb): Error accessing name: Sigrun, error is [object Object].
    (ndb): ndb completed retrieval of 294 records.
  • Sephem said:
    Jinresh said:
    tysandr said:

    The new version is exponentially faster than the first with updating and populating the names from qwf, awesome job there!

    I did get a couple random errors when testing the db.u command

    "(ndb): ndb requesting truncated update of 122 from 277 records.
    (ndb): Error accessing name: Beardedwhispers, error is [object Object].
    (ndb): Error accessing name: Bishop, error is [object Object].
    (ndb): ndb completed retrieval of 122 records."
    Yeah I always get these exact same errors

    (ndb): ndb requesting truncated update of 294 from 294 records.
    (ndb): Error accessing name: Beardedwhispers, error is [object Object].
    (ndb): Error accessing name: Eidi, error is [object Object].
    (ndb): Error accessing name: Sigrun, error is [object Object].
    (ndb): ndb completed retrieval of 294 records.
    They are either deleted or renamed, it'd be nice if the script would just purge them from the collection or take some action based on what error is returned (I imagine there might be something useful in the object but I've never checked).
Sign In or Register to comment.