There was a problem that did arise while I was working on my idea. Duplicate values for the current charges and the total charges don't show up in the gump texts. Meaning if the user has a book with 12 charges and 12 charges remaining there is only 1 value that shows up in the list. Whereas with 12 charges and 10 charges remaining 2 values show up in the list. These values have to be removed, so I came up with 2 solutions.
- Have the user use one of the 12 charges
- Remove the 2 first numerics from the front.
The second would fail if the user named their runes numerically. Consider 12 charges, 12 chareges left with the first rune being named 0. The list would look like [12, 0, ...]. Meaning the first rune would be removed and not taken into account.
Code: Select all
//book - The serial of the runebook that you want the runecount of.
function getRuneCount(book) {
var runeCnt = 0;
var lastGump = Orion.GetGump(any, '0x554B87F3');
if (lastGump)
lastGump.Close();
Orion.Wait(1000);
Orion.UseObject(book);
if (Orion.WaitForGump(1000)) {
var gump = Orion.GetGump(any, '0x554B87F3');
if ((gump !== null) && (gump.ID() === '0x554B87F3'))
runeCnt = removeBefore(removeAfter(gump.TextList(), 'Empty')).length;
if (runeCnt > 16)
runeCnt = 16;
lastGump = Orion.GetGump(any, '0x554B87F3');
if (lastGump)
lastGump.Close();
}
return runeCnt;
}
function removeAfter(list, key) {
var keyFound = false;
var indexOfKey = 0;
while (indexOfKey < list.length && !keyFound) {
if (list[indexOfKey] == key)
keyFound = true;
else
indexOfKey++;
}
var newList = [];
for (var i = 0; i < indexOfKey; i++) {
newList[i] = list[i];
}
return newList;
}
function removeBefore(list) {
var newList = [];
for (var i = 2; i < list.length; i++) {
newList[i-2] = list[i];
}
return newList
}
I will update this if I find a way around the problem above. Feel free to comment or ask questions.
Update: someone found that there is an edge case if the book is full. I have fixed that by saying if the book has more than 16 elements in the text list (it must be full) then its got 16 runes. Double checked. Still works as intended for books of smaller size. I also added in the delay I talked about, as it could be easy to miss my statement about giving 1000 ms for adequate time.
Thanks Edwin!