Nexus API - Need Assistance

edited August 2020 in Tech Support
Hello, I could use some assistance in understanding how to utilize API functions within scripts on the Nexus client.

An example of this would be the API functions made available in the Character db package:

/////////////API//////////////////////

You can use these commands in your scripts

cdb_exists(name)         return if a character exists in the DB, you should call this before calling other API functions!

cdb_getByName(name)        get character info and add to the DB, does not return anything
cdb_get_rank(name)         return ranking for the character
cdb_get_city(name)        return a players city
cdb_get_class(name)        return a players class
cdb_get_level(name)        return a players level
cdb_get_pk(name)        return a players kill count
cdb_get_house(name)        return a players house

However, it is not clear how I'm meant to actually utilize these or other such functions in a script.

In the Nexus documentation with regard to calling functions it states that, "Functions can be called from scripts by using run_function(name, args, package)" but in what way would I correctly use these in combination with this run_function command?

If anyone may be able to offer some help with this, I would greatly appreciate it.


Comments

  • edited August 2020
    I quickly tried it, it returns undefined for me, but perhaps it can point you in the right direction (I am rather new to Nexus as well, so this may be entirely wrong, but posting this in case you/someone else can make this work, better than nothing)

    //Enter the script here
    let functionArgs = ["Marmidon"];
    display_notice('starting calling function');
    let functionResult = run_function("cdb_exists", functionArgs, "Cdb");
    display_notice('result=' + functionResult);


    "Cdb" - name of your package you imported.

    I think it might not work, since after importing the package, I do not see those functions declared anywhere when browsing this reflex package in nexus.
  • edited August 2020
    Yeah, unfortunately even trying it through that method it returns as undefined for me as well. Under my reflex packages tab, the package was added with the name "Character db" rather than "Cdb" so that's what I used as the package name in my test.

    The functions themselves appear to be contained within the onLoad, they look like this:

    //API=============================================================

    //return if a character exists in the DB

    cdb_exists = function(name) {
        if (cdb.characterServerList[fixCaps(name)]) {
            return true;
        }else{
            return false;
        }
    }

    //get character info and add to the DB, does not return anything
    cdb_getByName = function(name) {
        getCharacterByName(name);
    }

    //return ranking for the character
    cdb_get_rank = function(name) {
        return cdb.characterServerList[fixCaps(name)].xp_rank; 
    }

    //return players city
    cdb_get_city = function(name) {
        return cdb.characterServerList[fixCaps(name)].city; 
    }

    //return players class
    cdb_get_class = function(name) {
        return cdb.characterServerList[fixCaps(name)].class; 
    }

    //return players level
    cdb_get_level = function(name) {
        return cdb.characterServerList[fixCaps(name)].level; 
    }

    //return PK count
    cdb_get_pk = function(name) {
        return cdb.characterServerList[fixCaps(name)].player_kills; 
    }

    //return house
    cdb_get_house = function(name) {
        return cdb.characterServerList[fixCaps(name)].house; 
    }

    //END API=========================================================


    Looking at that though it still isn't clear to me how exactly they should be called.

    However I noticed that the trigger it includes for angel presence has this script which uses the cdb_getByName function and I presume that would work. Perhaps the issue I'm having is that I haven't included any if statement to further specify like this script does.

    var output = $("div.line div:contains('"+args[1]+"')").last();
    if(cdb.characterServerList[args[2]]) {
        var acolour = cdb.city_colours[cdb.characterServerList[args[2]].city];
    } else {
        cdb_getByName(args[2]);
        var acolour = "grey";
    }

    aline = "Your guardian angel senses <span style='color: "+acolour+"'>"+args[2]+"</span> at " + args[3];
    ow_Write("#output_main","<div class='mono'>"+aline+"</div>");


    Thanks for taking the time to look in to it and offer help, you did give me a better idea as to how I should go about printing the result once I figure out how to grab it.

  • Did some more digging, it looks like user functions can be called directly:

    var result = cdb_exists("Marmidon");
    display_notice('result=' + result);

    This returned true for me. And false if I passed incorrect name.
  • edited August 2020
    Ah thank you so much, now it is beginning to make sense.

    I created a test using each of the functions to ensure that they work in the same manner and it was successful. Using the test alias, ^test (\w+)$, executes the following script:

    client.display_notice("NOW RUNNING TEST:");

    var testresult = cdb_exists(args[1]);
    print("Exists: " + testresult);

    if (testresult == true) {
    var testresult = cdb_get_rank(args[1]);
    print("XP Rank: " + testresult);

    var testresult = cdb_get_city(args[1]);
    print("City: " + testresult.charAt(0).toUpperCase() + testresult.slice(1));

    var testresult = cdb_get_class(args[1]);
    print("Class: " + testresult.charAt(0).toUpperCase() + testresult.slice(1));

    var testresult = cdb_get_level(args[1]);
    print("Level: " + testresult);

    var testresult = cdb_get_pk(args[1]);
    print("PKs: " + testresult);

    var testresult = cdb_get_house(args[1]);
    print("House: " + testresult.charAt(0).toUpperCase() + testresult.slice(1));
    }

    Using my own name, if exists returned true the result is:

    NOW RUNNING TEST:

    Exists: true
    XP Rank: 443
    City: Targossas
    Class: Monk
    Level: 92
    PKs: 276
    House: Dawnblade

    Or if exists returns as false then it will only print the first variable.

    Thank you once again!


Sign In or Register to comment.