Access your Class Specific Stats directly with this script in Nexus

I had a problem recently trying to access my Kai points (monk) from scripting in Nexus reflexes.  My plan is to reflexively use Kai abilities only when I have the required amount of kai.  Many hours later, I figured out how to access my Kai.  The Kai points of a monk, because they are class specific are only included to the gmcp of a monk.  To see your class specific stats, use the following code.  It will output a notice to your GUI.  You can make a small alteration to output to the console instead.  The output will be all of your character's vitals, including hp, mana, endurance, etc.  Class specific skills are found in the final index of the resulting array, and are in a string that contains them all, seperated by commas.

let object;
let array1=[];
if (args.gmcp_method == 'Char.Vitals') // is an object containing all your vitals
 {
  myVitalsArray = Object.entries(args.gmcp_args);   // convert myVitals to an array
  display_notice('myVitalsArray: '+myVitalsArray, 'blue'); // shows all keys and values of args.gmcp_args   
}

This Char.vitals object is returned by the system periodically.  To force it, use a command that will require the system to check your vitals.  I use 'med' or 'meditate.'  The resulting 'myVitalsArray' can be parsed to grab the string at the last index, and then you can parse that to get the specific stat you need.
I am assuming the class specific stats is always the final index, [12] in the case of Shreg the monk.  In my code however, I parse myVitalsArray[ ] and further parse any index returned that is '.length > 0' for '.contains( 'Kai').  That way, if a future update changes which index contains my Kai, I won't have to change the code.

Sir Shreggleton The Amazing

Shreg

Comments

  • I saw Shreg asking for help with this one so I took my own stab at it and completed a few minutes after him. The class specific values are stored in charstats array in Char.Vitals, and each entry is a string of the form: <name>: <value>. For example, the entry for kai may be in position 2 in the array with value "Kai: 5%".

    if (args.gmcp_method == "Char.Vitals")
    {
        charstats=args.gmcp_args.charstats; //first give a short name to charstats
        len_charstats=charstats.length; //record its length for looping
        //pos0=charstats[0];
        //print(charstats[2].search("Kai")==0)
        for (i=0;i<len_charstats;i++){
            if (charstats[i].search("Kai")!=-1){ //replace "Kai" with name of relevant entry
                //print(charstats[i]);
                kaistring=charstats[i]; //this step isn't really necessary, but was useful for my understanding
                kainum=kaistring.match(/\d+/); //captures the numeric part of the string
                //print(kainum)
           }
        }
        //print(kaistring)
       
        client.set_variable('mykai',Number(kainum));
        //client.set_variable('charstats', charstats);
        //client.set_variable('len_charstats',len_charstats);
        //client.set_variable('kaistring',kaistring);
        //client.set_variable('pos0',pos0);
        //client.set_variable('kainum',charstats[2].kai);
    }

    Keneanung's GMCP documentation (https://github.com/keneanung/GMCPAdditions) proved instructive as always.
  • You can add kai to your prompt and get it from there much easier, no? 

  • As in by parsing the prompt? That's a neat idea. The problem I have with it is people may want different prompt settings and it could end up difficult developing general/shareable scripts. This is probably more of an issue for people who multiclass or switch between tekura and shikudo.

    Besides, my code is only about 8 lines. Everything else was me figuring out Javascript and Nexus, which I left in because they could be useful for debugging in the future.
  • The way I would personally do it is have a trigger that is in a "Monk" group that is only on then.

    Not sure if Nexus can do that or not. 

  • I realized that this:
    let object;
    let array1=[];
    is not actually part of the code I meant to share.  It's part of the more lengthy code where I did the parsing (two loops) and display_notice() the kai %

Sign In or Register to comment.