What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[Plugin] GUID usage

Status
Not open for further replies.

Croga

Well-Known Member
Joined
Jun 7, 2010
Messages
1,636
Reaction score
27
Hey Fellow Developers,

For a plugin I'm working on I need to fill a WoWItem with an object that's in my bags.
When I look at ObjectManager I can only get an object by GUID. Is that the right way to go? Or is there a way I can get an object by Entry?

I'm not sure what GUID does exactly. Is there an easy explanation as to why I can (or why I shouldn't) use GUID to get my WoWItem?
 
why not easily query the inventar directly with the list of inventar objects? :)
PHP:
// the complete inventar
private List<WoWItem> myInventar { get { return ObjectManager.Me.Inventory.Items.ToList(); } }
// by Entry
private List<WoWItem> myItemFromInventar { get { return ObjectManager.Me.Inventory.Items.Where(p=>p.Entry==123123).ToList(); } }


The GUID is the GLOBAL UNIQUE IDENTITY ... but i think this one is changing with every login, so u'll need the Entry to get items with the id u wish to have
 
Last edited:
why not easily query the inventar directly with the list of inventar objects? :)
Yeah, that's what I'm doing now. Is there any way to put p into a WoWItem instead of an entry in a list? It seems like a lot of code just to get my hands on an item in my inventory :(
 
this code returns a list of WoWItems
but u can do this
PHP:
private WoWItem ItemInInventar { get { return ObjectManager.Me.Inventory.Items.Where(p=>p.Entry==123123).First(); } }
this will return ONE item :) (or null if not existent)
 
this will return ONE item :) (or null if not existent)
Thanks! Very good stuff! That shortened my code by a lot and made it a lot more readable.

(I'm actually using an even shorter implementation ;))
PHP:
ObjectManager.GetObjectsOfType<WoWItem>().Where(u => (u.Entry == 62829)).First();
 
Thanks! Very good stuff! That shortened my code by a lot and made it a lot more readable.

(I'm actually using an even shorter implementation ;))
PHP:
ObjectManager.GetObjectsOfType<WoWItem>().Where(u => (u.Entry == 62829)).First();
This one is wrong, it will return item with ID 62829 no matter if your character has it or not. Not entirely sure when exactly, but it might be loaded at startup or when you see it on auction house/on other player.

Use something like that:
PHP:
public WoWItem GetWornItem(uint entry)
{
    WoWItem item = Me.Inventory.Equipped.Items.First(i => i.Entry == entry);
    if (item.IsValid)
        return item;
    item = Me.BagItems.First(i => i.Entry == entry);
    if (item.IsValid)
        return item;
    return null;
}
public bool UseItem(WoWItem item)
{
    if (item.IsValid && item.Cooldown <= 0 && item.Usable && item.Use())
        return true;
    return false;
}
public bool UseItem(uint entry)
{
    if (UseItem(GetWornItem(entry)))
        return true;
    return false;
}

Then simply UseItem(12345)
 
Last edited:
This one is wrong, it will always return item with ID 62829 no matter if your character has it or not.
errr... I'm not looking for a wearable item. I'm looking for the magnet from the Tol Barad quest :) If it's in my bags, I can use it ;) There's nothing wearable about it either.
So yeah, thanks for confirming that my code will return the item with ID 62829, that's all I need it to do ;)
 
By worn i mean you wear it either on you (equipped) or you wear it inside bags, it will also prioritize items you have equipped above those in bags. No idea how else could i name function ;D

Your way still have no checks for anything and still could return item you cannot use.
 
Last edited:
By worn i mean you wear it either on you (equipped) or you wear it inside bags. No idea how else could i name function ;D
Your way still have no checks for anything and still could return item you cannot use.
No, it can't. It will always return the Magnet if it's in the bags. If the magnet is in the bags then I can use it, period. The magnet can never be equipped so I don't need to see if I have it equipped or whether it's equippable.
My way doesn't have any checks because there don't need to be any checks. If I have the item, I can use it so it can never return an item I cannot use.

Remember, Strix, this is not a generic function. This is a specific function for a specific use.
 
No, it can't. It will always return the Magnet if it's in the bags.
And also it will always return the Magnet if it's not in your bags but you saw it before (eg. you somehow dropped it in the middle), it might even be pre-loaded by default while logging into game.

My function is general use, but it also handles most (if not all) possible errors when coming to searching/using items.
It could've been ~10 lines of code simply put there, but it's good programming practice to wrap small pieces of code into functions when you expect to use them more than once anywhere in the future.
 
Last edited:
And also it will always return the Magnet if it's not in your bags but you saw it before (eg. you somehow dropped it in the middle), it might even be pre-loaded by default while logging into game.
But I won't really care, will I? Seeing as I do check whether I have the quest and if it does return the item without me having it, the item.use will simply return false.
- There's no possibility that I'll get the wrong item back
- There's no possibility that using the item even though I don't have it will go catastrofically wrong.
Hence, there's no reason to use more code then necessary as that will only cost me performance whilst gaining me nothing.
My function is general use, but it also handles most (if not all) possible errors when coming to searching/using items.
It could've been ~10 lines of code simply put there, but it's good programming practice to wrap small pieces of code into functions when you expect to use them more than once anywhere in the future.
Yes, your function is general use. I don't need general use, I need specific use.
It's bad programming practice to use more lines of code then you need as that will cost you performance and visibility.

As said; your code is nice, tidy and neat but it's not useful for what I want to do at the moment. It's way too bulky and doesn't gain me anything in this specific situation.
 
so let me get this right. you already fixed the issue and 10 posts later your still going back and forth about how to do it?
 
so let me get this right. you already fixed the issue and 10 posts later your still going back and forth about how to do it?
You're right CG....
"Arguing on the internet is about the same as competing in the special Olympics.... You may win but you're still a retard."

Issue fixed, case closed, end of story.
 
alright then, thread closed.

just FYI for anyone just joining, you only wanna use GUID when you need to tell 1 particular something apart from the other objects, like if you had 10 potions and you only needed 1 specific of the 10 Runic Mana Potions. or 1 specific Mob out of all the others.
 
Status
Not open for further replies.
Back
Top