User Tag List

Results 1 to 7 of 7

Thread: eluna api: GetIcon() ruturn itemIcon

  1. #1
    Enthusiast
    Join Date
    Dec 2013
    Location
    China
    Posts
    33
    XP
    2,410
    Level
    13
    Thanks
    18
    Thanked 18 Times in 5 Posts

    eluna api, return item icon

    src\server\game\DataStores\DBCfmt.h
    Code:
    ---- //char const ItemDisplayTemplateEntryfmt[] = "nxxxxxxxxxxixxxxxxxxxxx";
    ++++  char const ItemDisplayTemplateEntryfmt[] = "nxxxxsxxxxxxxxxxxxxxxxxxx";
    src\server\game\DataStores\DBCStores.cpp

    Code:
    ---- //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
    ++++ DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt);
    src/server/game/DataStores/DBCStores.h
    Code:
    ---- //extern DBCStorage <ItemDisplayInfoEntry>      sItemDisplayInfoStore; -- not used currently
    ++++ extern DBCStorage <ItemDisplayInfoEntry>         sItemDisplayInfoStore;
    src/server/game/DataStores/DBCStructure.h
    Code:
        uint32      ID;                                         // 0        m_ID
                                                                // 1        m_modelName[2]
                                                                // 2        m_modelTexture[2]
    ---                                                            // 3        m_inventoryIcon
    +++    char*       inventoryIcon;                  // 3        m_inventoryIcon
                                                                // 4        m_geosetGroup[3]
                                                                // 5        m_flags
                                                                // 6        m_spellVisualID
    src\LuaEngine\GlobalMethods.h
    Code:
    int GetIcon(lua_State* L)
    	{
    		 Item* item = Eluna::CHECKOBJ<Item>(L, 1, false);
    		const ItemDisplayInfoEntry* dispInfo;
            if (!item)
            {
    			uint32 entry = Eluna::CHECKVAL<uint32 >(L, 1);
    			const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
                            if (temp)
    			      dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
            }
    		else
    			dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);
    
    
    		std::ostringstream iconText;
    		
    		float w = Eluna::CHECKVAL<float >(L, 2);
    		float h = Eluna::CHECKVAL<float >(L, 3);
    		float x = Eluna::CHECKVAL<float >(L, 4,0);
    		float y = Eluna::CHECKVAL<float >(L, 5,0);
    
    		iconText << "|TInterface";
    		if (dispInfo)
    		{
    			iconText << "/ICONS/" << dispInfo->inventoryIcon;
    		}
    		else
    		{
    			iconText << "/InventoryItems/WoWUnknownItem01";
    		}
    		iconText << ":" << w << ":" << h << ":" << x << ":" << y << "|t";
    		Eluna::Push(L, iconText.str());
    		return 1;
    	}
    src\LuaEngine\ItemMethods.h
    Code:
    	int GetIcon(lua_State* L, Item* item)
    	{
    		std::ostringstream iconText;
    		float w = Eluna::CHECKVAL<float >(L, 2);
    		float h = Eluna::CHECKVAL<float >(L, 3);
    		float x = Eluna::CHECKVAL<float >(L, 4,0);
    		float y = Eluna::CHECKVAL<float >(L, 5,0);
    
    		const ItemDisplayInfoEntry* dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);
    
    		iconText << "|TInterface";
    		if (dispInfo)
    		{
    			iconText << "/ICONS/" << dispInfo->inventoryIcon;
    		}
    		else
    		{
    			iconText << "/InventoryItems/WoWUnknownItem01";
    		}
    		iconText << ":" << w << ":" << h << ":" << x << ":" << y << "|t";
    		Eluna::Push(L, iconText.str());
    		return 1;
    	}

    src\LuaEngine\LuaFunctions.cpp
    Code:
    void RegisterGlobals(lua_State* L)
    {
        // Getters
    ++++    lua_register(L, "GetIcon", &LuaGlobalFunctions::GetIcon);                                               //GetIcon(entry/item,high,width,x,y)
    Code:
    ElunaRegister<Item> ItemMethods[] =
    {
        // Getters
    ++++    { "GetIcon", &LuaItem::GetIcon },                             // :GetIcon(high,width,x,y)


    use:

    item:GetIcon(40,40,0,0)
    or
    GetIcon(item,40,40)
    or
    GetIcon(123456,40,40,-1,10)



    Thanks~
    Last edited by Ayase; 07-29-2016 at 01:43 PM.
    Achievements:
    Member 1 year registered Level X

  2. The Following 5 Users Say Thank You to Ayase For This Useful Post:


  3. #2
    Exalted Member <span style='color: #FFFFFF'><span class='glow_00FF00'>Wolord</span></span>'s Avatar
    Join Date
    Aug 2013
    Location
    I.R.A.N
    Posts
    123
    XP
    910,268
    Level
    167
    Thanks
    88
    Thanked 22 Times in 11 Posts
    Can u do it for spells, too?
    Achievements:
    Shopper 1 year registered Member Level XL Level C

  4. #3
    Enthusiast Erictemponi's Avatar
    Join Date
    Aug 2014
    Posts
    3
    XP
    1,749
    Level
    11
    Thanks
    0
    Thanked 4 Times in 2 Posts
    I didn't find this:
    void RegisterGlobals(lua_State* L)
    {

  5. #4
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,860
    XP
    13,531
    Level
    35
    Thanks
    95
    Thanked 591 Times in 418 Posts
    Quote Originally Posted by Erictemponi View Post
    I didn't find this:
    This is what you are looking for:
    https://github.com/ElunaLuaEngine/El...ns.cpp#L40-L43

    Add this to it:
    Code:
    { "GetIcon", &LuaGlobalFunctions::GetIcon },
    Also in GlobalMethods.h the function has to be
    Code:
    int GetIcon(Eluna* /*E*/, lua_State* L)
    instead of
    Code:
    int GetIcon(lua_State* L)
    and same thing with the itemmethods.h
    Code:
    int GetIcon(Eluna* /*E*/, lua_State* L, Item* item)
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  6. #5
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,860
    XP
    13,531
    Level
    35
    Thanks
    95
    Thanked 591 Times in 418 Posts
    Possible crash;
    const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
    dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
    if entry is invalid and temp will be nullptr and accessing temp.
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  7. #6
    Original Poster
    Enthusiast
    Join Date
    Dec 2013
    Location
    China
    Posts
    33
    XP
    2,410
    Level
    13
    Thanks
    18
    Thanked 18 Times in 5 Posts
    Code:
    	Item* item = Eluna::CHECKOBJ<Item>(L, 1, false);
    		const ItemDisplayInfoEntry* dispInfo = NULL;
    		if (!item)
    		{
    			uint32 entry = Eluna::CHECKVAL<uint32 >(L, 1);
    			const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
    ++			if (temp)
    				dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
    		}
    		else
    			dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);

    Add a judgment.

    0_0

  8. #7
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,860
    XP
    13,531
    Level
    35
    Thanks
    95
    Thanked 591 Times in 418 Posts
    Quote Originally Posted by Ayase View Post
    Code:
    	Item* item = Eluna::CHECKOBJ<Item>(L, 1, false);
    		const ItemDisplayInfoEntry* dispInfo = NULL;
    		if (!item)
    		{
    			uint32 entry = Eluna::CHECKVAL<uint32 >(L, 1);
    			const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
    ++			if (temp)
    				dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
    		}
    		else
    			dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);

    Add a judgment.

    0_0
    you should also add that red part to the script in main post :)
    Because atm its not there and dispInfo will be undefined causing undefined behavior when an entry with no item template is given.
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •