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
"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.
The functions themselves appear to be contained within the onLoad, they look like this:
//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.
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.
This returned true for me. And false if I passed incorrect name.
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));
}