ScriptUO
Scripting Resources & Utilities => Orion UO Client => Topic started by: Bulldog on June 06, 2022, 02:17:35 AM
-
Hello everyone I hope someone can help with this ..
I have a function that is returning durability on items as elements of an array these come out as arrayelement- /arrayelement[y] which is the durability say 234 / 255. I want to cast the strings into an integer but I am not sure what the Orion version of Integer.parseInt ?
eg:
int numberx = Integer.parseInt(arrayelement
int numbery = Integer.parseInt(arrayelement[y]);
-
Orion gives you: pairIntInt.Index, pairIntInt.Value, pairIntString.Index, and pairIntString.Text to work with.
-
Necroing a thread a bit, but figure I'd throw in a solution for this for anyone looking. In JavaScript there's a few options for changing a string to an integer. Number('1') and +'1' both work pretty much identically.
As for actually grabbing the durability values, RegEx is the way to go.
function DurabilityTest()
{
Orion.WaitForAddObject('myTarget');
Orion.Print(GetDurability('myTarget'));
}
function GetDurability(objSerial)
{
var obj = Orion.FindObject(objSerial);
var durabilityArr = obj.Properties().match(/Durability (\d+) \/ (\d+)/) //evaluates to e.g., ['Durability 250 / 255', '250', '255'] OR null if match isn't found
if(!durabilityArr) //if a match isn't found returns false
return false;
var minDurability = +durabilityArr[1]; //convert string to int
var maxDurability = Number(durabilityArr[2]); //convert string to int
return [minDurability, maxDurability]; //e.g. [250, 255]
}