PDA

View Full Version : Creating Shortcuts from Items in Inventory


Stever1388
12-20-2011, 05:01 PM
Basically I want to take items that are in the inventory and create shortcuts out of them, so that I can then create quickslots. However, you need the string Data of the item to be able to create the quickslot, and as far as I can tell, the only way to get that string is to add the item to a quickslot and then output the result. Is there someway to gather the data string needed to create a shortcut from items in your inventory without knowing what is actually in your inventory?

I've tried using ItemControl, but it doesn't create the type of quickslot that you have on your mainbar, for instance you can't left click on a potion to use it, you either have to right click it or double left click it (as if it were in your inventory).

Any help would be appreciated. Thanks.

lunarwtr
12-20-2011, 07:46 PM
You can capture the item ids from lorebook mediawiki articles, or from the item event when u drag inventory item to a quickslot (forget event name offhand). You can call GetData on the quickslot shortcut (or maybe its the getitem method of quickslot.. I forget off top of my head) and keep track of those. Either way, you can create yourself a little database of the items you want prefab quickslots to. You can create the quickslot regardless of whether the item is in inventory. I use this for id analysis tool I use for Compendium development. If the item isn't in inventory the quickslot will be grayed out and not do much when clicked.

lunarwtr
12-20-2011, 07:55 PM
Convert the item ids from lorebook to hex value and u can then


...
local shortcut = Turbine.UI.Lotro.Shortcut(Turbine.UI.Lotro.Shortcu tType.Item , string.format( '0x0000000000000000,0x%s', hex ))
quicks:SetShortcut( shortcut );

Stever1388
12-20-2011, 08:40 PM
You can capture the item ids from lorebook mediawiki articles, or from the item event when u drag inventory item to a quickslot (forget event name offhand). You can call GetData on the quickslot shortcut (or maybe its the getitem method of quickslot.. I forget off top of my head) and keep track of those. Either way, you can create yourself a little database of the items you want prefab quickslots to. You can create the quickslot regardless of whether the item is in inventory. I use this for id analysis tool I use for Compendium development. If the item isn't in inventory the quickslot will be grayed out and not do much when clicked.

The problem I'm having is this:

You have a stack of morale potions and you set those potions into a quickslot. You then completely run out of that stack of potions. You buy more of the same exact type of potions. When you unload the plugin and reload it, your quickslot will be empty, or the Quickslot:SetShortcut() method will throw an error. Basically, the Shortcut:GetDat() is returning an invalid string, even though they are the same item. From my testing, a stack in your inventory of an item always returns the same Shortcut:GetData() but a different stack of the same item will return a different Shortcut:GetData(). You can test this by having two separate stacks in your inventory of an item and placing them on a quickslot that has the ShortcutChanged event function handled and have it print out Turbine.Shell.WriteLine(Quickslot:GetShortcut():Ge tData()). When you place both stacks on the quickslot you'll get different values returned.

As a very simple example of what I could do with this, is create 75 quickslots, and place each item in your inventory into each of the slots. The code would look something like this:


backpack = Turbine.GamePlay.LocalPlayer:GetInstance():GetBack pack()
quickslots = {}

for i=1, backpack:GetSize() do
item = backpack:GetItem(i)
quickslots[i] = Turbine.UI.Lotro.Quickslot()
quickslots[i]:SetShortcut(Turbine.UI.Lotro.Shortcut(Turbine.UI. Lotro.ShortcutType.Item, ITEMDATA)
end



However, I have no idea how to get the ITEMDATA needed to create the shortcut. Normally you can use the Shortcut:GetData() method to get that, but in this case I don't have the quickslot/shortcut set up yet and I'm trying to build it dynamically regardless of what is actually in the users inventory.

I'd also like to know how you get the grayed out icons. If I run out of an item it goes gray but if I unload the plugin and then load it back in the plugin will either throw an error or it will be blank.

lunarwtr
12-20-2011, 08:47 PM
There is no API way of getting the item id directly from an item unless it is dragged to a quickslot -or- linked to chat from a vendor.

However, on lorebook they show ~340 potions total. A person could make a name to id mapping and keep that in one of their plugin files. That way when you scan through your bag, if any match one of those 340, then you have the id to convert to hex and thus make quickslot.

If you download LOTRO Compendium addon (shamless plug), you can grep through the item database for rows that have a category of potion and get all the ids :

$ grep '"Potion"' Items/CompendiumItemsDB.lua | more
{rl=1,l=15,n="+1 Hope Token (15 min)",c={"Potion"},q="Rare",id="70027FE6"},
{rl=25,l=25,n="+2 Hope Token (15 min)",c={"Potion"},q="Rare",id="70027FE3"},
{rl=30,l=30,n="+3 Hope Token (15 min)",c={"Potion"},q="Rare",id="70027FE5"},
{rl=35,l=35,n="+4 Hope Token (15 min)",c={"Potion"},q="Rare",id="70027FE7"},
{rl=40,l=40,n="+5 Hope Token (15 min)",c={"Potion"},q="Rare",id="70027FE8"},
{rl=51,l=51,n="+5 Hope Token (30 min)",c={"Potion"},q="Rare",id="70027FE4"},
{rl=35,l=35,c={"Potion","Champion","Craftable"},n="Artisan Potion of Fervour",cl="Champion",q="Uncommon",id="70024348",lb="Artisan Potion of Fervour Recipe"},
{rl=35,l=35,c={"Potion","Hunter","Craftable"},n="Artisan Potion of Focus",cl="Hunter",q="Uncommon",id="70024345",lb="Artisan Potion of Focus Recipe"},
{rl=51,l=66,n="Asteric Edhelharn Token",c={"Potion","Craftable"},q="Incomparable",id="70028075",lb="Vitreous Edhelharn Token Recipe"},
{rl=1,l=1,c={"Potion"},ib="BoA",n="Battle Potion of Defilement",q="Common",id="70028F9A"},
{rl=1,l=1,c={"Potion","Quest Reward"},ib="BoA",n="Battle Potion of Restoration",q="Common",id="70026944",qu="Vol. III, Book 4, No Mercy for Traitors"},
{rl=1,l=1,c={"Potion"},ib="BoA",n="BOO!",q="Common",id="70022C5A"},
{rl=75,l=75,n="Bottled Orc Scream",c={"Potion"},q="Common",id="7001985B"},
{rl=75,l=75,n="Bottled Spider Chitter",c={"Potion"},q="Common",id="7001985E"},
{rl=75,l=75,n="Bottled Uruk Effluvium",c={"Potion"},q="Common",id="7001985C"},

lunarwtr
12-20-2011, 08:59 PM
To answer your other questoin Its my understanding that in item shortcuts..

Turbine.UI.Lotro.Shortcut( 2, '0x0000000000000000,0x70004842');

The digits to left of comma in the data string differentiates where a distinct stack in inventory is refering to, and as a result its quantity. The right hand side is the hex for what kind of item the item will be. If you zero the left side out the game seems to take a guess at which inventory slot you mean that happens to match the item id.

Stever1388
12-20-2011, 09:09 PM
To answer your other questoin Its my understanding that in item shortcuts..

Turbine.UI.Lotro.Shortcut( 2, '0x0000000000000000,0x70004842');

The digits to left of comma in the data string differentiates where a distinct stack in inventory is refering to, and as a result its quantity. The right hand side is the hex for what kind of item the item will be. If you zero the left side out the game seems to take a guess at which inventory slot you mean that happens to match the item id.

Wow thank you! I've messed with those numbers so much and I was sure the whole number was different but the only the first part is.

Where are you getting the id numbers from the Lorebook?

lunarwtr
12-20-2011, 09:24 PM
if your desire is for a few items.. you can get item codes by viewing the "source" of the wiki article for the item in question...

i.e.

http://lorebook.lotro.com/index.php?title=Item:%2B1_Hope_Token_%2815_min%29&action=edit

results in

<noedit>
<seo title="Item DB: - Items - +1 Hope Token (15 min)" metak="lotro, Lord of the Rings Online, wiki, database, Lorebook, LOTR, Middle-earth, Tolkien, Item DB: , Items , +1 Hope Token (15 min),Potion" metad="+1 Hope Token (15 min): In the darkest of times, even the faintest glimmer of hope can make all the difference." />
<official type="game">
<item id="1879212006" name="+1 Hope Token (15 min)" />
</official>
[[Category:Potion|+1 Hope Token (15 min)]]
</noedit>


the id="........." portion is what you want.

In the past it was much easier as the JSON response of the search form returned them all en mass.

Stever1388
12-20-2011, 09:34 PM
if your desire is for a few items.. you can get item codes by viewing the "source" of the wiki article for the item in question...

i.e.

http://lorebook.lotro.com/index.php?title=Item:%2B1_Hope_Token_%2815_min%29&action=edit

results in

<noedit>
<seo title="Item DB: - Items - +1 Hope Token (15 min)" metak="lotro, Lord of the Rings Online, wiki, database, Lorebook, LOTR, Middle-earth, Tolkien, Item DB: , Items , +1 Hope Token (15 min),Potion" metad="+1 Hope Token (15 min): In the darkest of times, even the faintest glimmer of hope can make all the difference." />
<official type="game">
<item id="1879212006" name="+1 Hope Token (15 min)" />
</official>
[[Category:Potion|+1 Hope Token (15 min)]]
</noedit>


the id="........." portion is what you want.

In the past it was much easier as the JSON response of the search form returned them all en mass.

I very much appreciate the help, thank you!

Garan
12-20-2011, 09:42 PM
i.e.

http://lorebook.lotro.com/index.php?title=Item:%2B1_Hope_Token_%2815_min%29&action=edit

results in

If you have the Rich Text Editor on, you have to click on "Disable rich editor" to see the actual source text.

Stever1388
12-21-2011, 01:17 PM
Thanks for your help again, I was messing around with this yesterday and still came to a problem (one ill turn deserves another I guess): The quickslots are semi-broken if you try to set an invalid shortcut using the 0x0000000000000000 for the first part of the string and then ever reacquire the item in question.

Here's some test code to try it out:

import "Turbine";
import "Turbine.Gameplay";
import "Turbine.UI";
import "Turbine.UI.Lotro";

Window=Turbine.UI.Window();
Window:SetSize(200,200);
Window:SetPosition(Turbine.UI.Display:GetWidth()/2-100,Turbine.UI.Display:GetHeight()/2-100);
Window:SetText("Test");
Window:SetVisible(true);

quickslots = Turbine.UI.Lotro.Quickslot();
quickslots:SetParent(Window);
quickslots:SetVisible(true);
quickslots:SetOpacity(1);
quickslots:SetSize( 36, 36 );
quickslots:SetPosition( 0, 0);

quickslots:SetShortcut(Turbine.UI.Lotro.Shortcut(2 , "0x0000000000000000,0x700017E2")) -- this sets the shortcut to traveling rations whether you have them in your inventory or not
Turbine.Shell.WriteLine("Test Item name: "..quickslots:GetShortcut():GetItem():GetName())
Turbine.Shell.WriteLine("Test Shortcutdata: "..quickslots:GetShortcut():GetData())

function quickslots:ShortcutChanged(sender, args)
Turbine.Shell.WriteLine("Name: "..quickslots:GetShortcut():GetItem():GetName())
Turbine.Shell.WriteLine("Data: "..quickslots:GetShortcut():GetData())
end

If you don't have any traveling rations in your inventory, you'll see a quickslot in the middle of your screen that is grayed out and can't be used. If you do have traveling rations in your inventory, you'll see a quickslot that is normal looking, however, if you try to left or right click on it, nothing happens (the sandglass icon should briefly appear in the quickslot if it were working correctly).

To get it to work, you must REMOVE the stack of traveling rations from your inventory (into your bank or sell them), and then add them back into your inventory. If you then click on the quickslot again nothing will happen, but you'll get the chat output of the name and data string. Then clicking it again and it'll work like a normal quickslot. It seems the quickslot doesn't try to update until you click on it, and then once you do it finds the link its looking for, which is why it updates (it changes the data string to match the one found in inventory).

Any suggestions on getting the event to fire prior to clicking the quickslot? Is there a way to maybe make the quickslot think it's been clicked even if it hasn't?

So far this is a pretty good solution to the problem I've been having but the fact that you have to click the slot twice the first time you use it is a bit frustrating and not to my liking.

lunarwtr
12-21-2011, 05:01 PM
I'll have to try it when I'm at my other pc as I "had" a working example of just such a thing a while back.

Off top of my head things to try would be to see if you need to set the quickslot enabled or something upon initialization. I could be getting mixed up but I think there was a bug regarding something that had to be toggled. Also, dont' use the hard coded number "2" for the first part of the shortcut.. use Turbine.UI.Lotro.ShortcutType.Item instead.. just incase the number is wrong.

lunarwtr
12-21-2011, 08:19 PM
Whatever they did, it must have broken in this release. The one I have doesn't work either anymore. If I think of a work around I'll post.

Mirar
03-12-2024, 11:18 AM
Anyone found a workaround for this yet?