ScriptUO
Scripting Resources & Utilities => Orion UO Client => Topic started by: The Ghost on May 21, 2022, 11:46:37 AM
-
Trying to learn by making small function
so I 'm Trying to send some wood into a bag at the bank. Find some documentation and trying to get this to work.
I build a list into Orion assistant , no error is present when i run it. Any idea what I'm dong wrong.
var runebook = "0x429C9158"
var bankbag = "0x40CF7E6A"
function LootToBank()
{
Orion.Say('Bank');
var sorttobag = Orion.FindList('Loot', 'backpack', '1');
if(sorttobag.length) {
var sort = sorttobag.length;
for (i = 0; i < sort; i++) {
Orion.MoveItem(sorttobag[i], 0, bankbag);
Orion.Wait(600);
}
}
}
-
function LootToBank()
{
Orion.Say('Bank');
var sorttobag = Orion.FindList('Loot', 'backpack', '1');
if(sorttobag.length) {
var sort = sorttobag.length;
for (i = 0; i < sort; i++) {
Orion.MoveItem(sorttobag, 0, bankbag);
Orion.Wait(600);
}
}
}
Orion.Say("Bank"); This will open your bank box but without a delay after (like Orion.WaitForContainerGump()) the next commands can be processed before your bank even opens.
Orion.FindList(list, container, flags); flags are listed in the help tab under FindFlags, in this case you just need 'item' instead of '1'
-You'll also need to have a list named "Loot" in your Lists->Find Tab with each item you want moved (If you don't).
Orion.MoveItem(serial, qty, container); For moving to a bank box, the easy way is to use Player.BankSerial()
I added a pile of gold to my "Loot" list and ran the following, it worked.
function LootToBank()
{
Orion.Say('Bank');
Orion.WaitForContainerGump();
var sorttobag = Orion.FindList('Loot', 'backpack', 'item');
if(sorttobag.length) {
for (i = 0; i < sorttobag.length; i++) {
Orion.MoveItem(sorttobag[i], 0, Player.BankSerial());
Orion.Wait(600);
}
}
}
This will only move 1 item from the Loot list though, changing if(sorttobag.length) to while() will keep it going til there are no found items left in the list.
Here is another example that does the same thing using some JavaScript magic :)
function LootToBank(){
Orion.Say('Bank');
Orion.WaitForContainerGump();
Orion.FindList('Loot', 'backpack', 'item').forEach(function(item){
Orion.MoveItem(item, 0, Player.BankSerial());
Orion.Wait(600);
});
}
-
I think in your for loop you should declare i as var.. so
for (var i = 0; i < sort; i++)
not sure if that helps
-
I think in your for loop you should declare i as var.. so
for (var i = 0; i < sort; i++)
not sure if that helps
Javascript allows you to set a variable without the var as long as you add a value to it.
var i, or i=0 is the same thing as far as its concerned.
-
Thx altiric for the clarification,
event with your function nothing moving. Since if work on your side, for me it back to learning how to make list again.
-
ok ty, now i know :)
try setting backpack not as a string. in Orion scripts section you will notice it will highlight, i think thats the way to use it.
-
Go into your Lists Tab->Find Tab.
One the left side, Click New, add "Loot" as List Name
On the right side, click New->Select by Target
Add each item you want moved to that list.
Post Merge: May 21, 2022, 12:41:02 PM
ok ty, now i know :)
try setting backpack not as a string. in Orion scripts section you will notice it will highlight, i think thats the way to use it.
You are correct. Instead of using a string you can use 'backpack' which is a global variable with you backback.Serial() :)
Post Merge: May 21, 2022, 12:43:56 PM
Sorry, had not noticed the picture before. Your Loot name named 'Loot' not Loot (take out the ('))
-
I have my list name as 'loot' , so I name it LOOT and it work.
-
*NECRO*
I am late to the party but can someone explain .length and what the 2nd line is telling Orion to do?
if(sorttobag.length) {
for (i = 0; i < sorttobag.length; i++) {
-
The ".length" property is a property of an array in JavaScript that returns the number of elements in the array.
The 2nd line of the code uses a for loop to iterate over the elements in the "sorttobag" array. The loop starts from 0 and goes until the end of the array, which is determined by "sorttobag.length". The variable "i" is used as the loop counter and is incremented on each iteration.
Sorry, I had this to chatgpt and it seems correct 😅