expose core functions
Exposed/added functions/methods: - IsPlayer() - GameObject:AddLoot(entry,amount)
This commit is contained in:
@@ -235,6 +235,66 @@ namespace LuaGameObject
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an [Item] to the loot of a [GameObject]
|
||||
*
|
||||
* @param uint32 entry : The entry of the [Item]
|
||||
* @param uint32 amount = 1 : amount of the [Item] to add to the loot
|
||||
* @return uint32 itemGUIDlow : low GUID of the [Item]
|
||||
*/
|
||||
|
||||
int AddLoot(lua_State* L, GameObject* go)
|
||||
{
|
||||
int i = 0;
|
||||
uint32 entry = Eluna::CHECKVAL<uint32>(L, ++i);
|
||||
uint32 amount = Eluna::CHECKVAL<uint32>(L, ++i, 1);
|
||||
int argAmount = lua_gettop(L);
|
||||
|
||||
#if defined TRINITY || defined AZEROTHCORE
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
#endif
|
||||
uint8 addedItems = 0;
|
||||
while (i + 2 <= argAmount)
|
||||
{
|
||||
uint32 entry = Eluna::CHECKVAL<uint32>(L, ++i);
|
||||
uint32 amount = Eluna::CHECKVAL<uint32>(L, ++i);
|
||||
|
||||
#if defined TRINITY || AZEROTHCORE
|
||||
ItemTemplate const* item_proto = eObjectMgr->GetItemTemplate(entry);
|
||||
#else
|
||||
ItemTemplate const* item_proto = ObjectMgr::GetItemPrototype(entry);
|
||||
#endif
|
||||
if (!item_proto)
|
||||
{
|
||||
luaL_error(L, "Item entry %d does not exist", entry);
|
||||
continue;
|
||||
}
|
||||
if (amount < 1 || (item_proto->MaxCount > 0 && amount > uint32(item_proto->MaxCount)))
|
||||
{
|
||||
luaL_error(L, "Item entry %d has invalid amount %d", entry, amount);
|
||||
continue;
|
||||
}
|
||||
if (Item* item = Item::CreateItem(entry, amount))
|
||||
{
|
||||
#if defined TRINITY || AZEROTHCORE
|
||||
item->SaveToDB(trans);
|
||||
#else
|
||||
item->SaveToDB();
|
||||
#endif
|
||||
LootStoreItem storeItem = LootStoreItem(item->GetEntry(), 0, 100, 0, LOOT_MODE_DEFAULT, 0, 1, 1);
|
||||
go->loot.AddItem(storeItem);
|
||||
#if defined TRINITY || AZEROTHCORE
|
||||
Eluna::Push(L, item->GetGUID().GetCounter());
|
||||
#else
|
||||
Eluna::Push(L, item->GetGUIDLow());
|
||||
#endif
|
||||
++addedItems;
|
||||
}
|
||||
}
|
||||
return addedItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves [GameObject] to the database
|
||||
*
|
||||
|
||||
@@ -180,6 +180,7 @@ ElunaRegister<Object> ObjectMethods[] =
|
||||
|
||||
// Boolean
|
||||
{ "IsInWorld", &LuaObject::IsInWorld },
|
||||
{ "IsPlayer", &LuaObject::IsPlayer },
|
||||
{ "HasFlag", &LuaObject::HasFlag },
|
||||
|
||||
// Other
|
||||
@@ -914,6 +915,7 @@ ElunaRegister<GameObject> GameObjectMethods[] =
|
||||
{ "Despawn", &LuaGameObject::Despawn },
|
||||
{ "Respawn", &LuaGameObject::Respawn },
|
||||
{ "SaveToDB", &LuaGameObject::SaveToDB },
|
||||
{ "AddLoot", &LuaGameObject::AddLoot },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -51,6 +51,17 @@ namespace LuaObject
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 'true' if the [Object] is a player, 'false' otherwise.
|
||||
*
|
||||
* @return bool IsPlayer
|
||||
*/
|
||||
int IsPlayer(lua_State* L, Player* player)
|
||||
{
|
||||
Eluna::Push(L, player->IsPlayer());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data at the specified index, casted to a signed 32-bit integer.
|
||||
*
|
||||
@@ -156,14 +167,14 @@ namespace LuaObject
|
||||
|
||||
/**
|
||||
* Returns the GUID of the [Object].
|
||||
*
|
||||
*
|
||||
* GUID is an unique identifier for the object.
|
||||
*
|
||||
*
|
||||
* However on MaNGOS and cMangos creatures and gameobjects inside different maps can share
|
||||
* the same GUID but not on the same map.
|
||||
*
|
||||
*
|
||||
* On TrinityCore this value is unique across all maps
|
||||
*
|
||||
*
|
||||
* @return ObjectGuid guid
|
||||
*/
|
||||
int GetGUID(lua_State* L, Object* obj)
|
||||
@@ -174,10 +185,10 @@ namespace LuaObject
|
||||
|
||||
/**
|
||||
* Returns the low-part of the [Object]'s GUID.
|
||||
*
|
||||
*
|
||||
* On TrinityCore all low GUIDs are different for all objects of the same type.
|
||||
* For example creatures in instances are assigned new GUIDs when the Map is created.
|
||||
*
|
||||
*
|
||||
* On MaNGOS and cMaNGOS low GUIDs are unique only on the same map.
|
||||
* For example creatures in instances use the same low GUID assigned for that spawn in the database.
|
||||
* This is why to identify a creature you have to know the instanceId and low GUID. See [Map:GetIntstanceId]
|
||||
|
||||
Reference in New Issue
Block a user