DarkflameServer/dScripts/VeBricksampleServer.cpp
EmosewaMC 7a051afd97 loot source for item drops
Added support for Items to have a loot source attached to them when dropped or rolled.  This fixes the issue where achievements would give the item before it appeared in the achievement window.
2022-04-23 20:35:34 -07:00

21 lines
925 B
C++

#include "VeBricksampleServer.h"
#include "InventoryComponent.h"
#include "EntityManager.h"
#include "GameMessages.h"
void VeBricksampleServer::OnUse(Entity *self, Entity *user) {
auto* missionComponent = user->GetComponent<MissionComponent>();
if (missionComponent != nullptr && missionComponent->GetMissionState(1183) == MissionState::MISSION_STATE_ACTIVE) {
const auto loot = self->GetVar<int32_t>(m_LootVariable);
auto* inventoryComponent = user->GetComponent<InventoryComponent>();
if (loot && inventoryComponent != nullptr && inventoryComponent->GetLotCount(loot) == 0) {
inventoryComponent->AddItem(loot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY);
for (auto* brickEntity : EntityManager::Instance()->GetEntitiesInGroup("Bricks")) {
GameMessages::SendNotifyClientObject(brickEntity->GetObjectID(), u"Pickedup");
}
}
}
}