PDA

View Full Version : eluna api: GetIcon() ruturn itemIcon



Ayase
05-01-2015, 11:26 AM
src\server\game\DataStores\DBCfmt.h


---- //char const ItemDisplayTemplateEntryfmt[] = "nxxxxxxxxxxixxxxxxxxxxx";
++++ char const ItemDisplayTemplateEntryfmt[] = "nxxxxsxxxxxxxxxxxxxxxxxxx";


src\server\game\DataStores\DBCStores.cpp



---- //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt) ; -- not used currently
++++ DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt) ;



src/server/game/DataStores/DBCStores.h


---- //extern DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore; -- not used currently
++++ extern DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore;


src/server/game/DataStores/DBCStructure.h


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

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

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


void RegisterGlobals(lua_State* L)
{
// Getters
++++ lua_register(L, "GetIcon", &LuaGlobalFunctions::GetIcon); //GetIcon(entry/item,high,width,x,y)





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~ :argh::argh:

Wolord
05-04-2015, 05:47 AM
Can u do it for spells, too?

Erictemponi
12-29-2015, 05:50 PM
I didn't find this:

void RegisterGlobals(lua_State* L)
{

Rochet2
12-29-2015, 06:18 PM
I didn't find this:

This is what you are looking for:
https://github.com/ElunaLuaEngine/Eluna/blob/c94ef51cbe596ab3ec23b313ea2f9f58b4ee29e9/LuaFunctions.cpp#L40-L43

Add this to it:

{ "GetIcon", &LuaGlobalFunctions::GetIcon },

Also in GlobalMethods.h the function has to be

int GetIcon(Eluna* /*E*/, lua_State* L)
instead of

int GetIcon(lua_State* L)

and same thing with the itemmethods.h

int GetIcon(Eluna* /*E*/, lua_State* L, Item* item)

Rochet2
06-12-2016, 01:11 AM
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.

Ayase
07-29-2016, 01:39 PM
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

Rochet2
07-29-2016, 02:12 PM
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.