mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
[Lua] New overload Actor.equipment(actor, slot)
.
This commit is contained in:
parent
5ed22c4c7a
commit
7186ea8ab4
@ -88,7 +88,7 @@ namespace MWLua
|
||||
[](const LObject& o) { return Inventory<LObject>{o}; },
|
||||
[](const GObject& o) { return Inventory<GObject>{o}; }
|
||||
);
|
||||
actor["equipment"] = [context](const Object& o)
|
||||
auto getAllEquipment = [context](const Object& o)
|
||||
{
|
||||
const MWWorld::Ptr& ptr = o.ptr();
|
||||
sol::table equipment(context.mLua->sol(), sol::create);
|
||||
@ -106,6 +106,20 @@ namespace MWLua
|
||||
}
|
||||
return equipment;
|
||||
};
|
||||
auto getEquipmentFromSlot = [context](const Object& o, int slot) -> sol::object
|
||||
{
|
||||
const MWWorld::Ptr& ptr = o.ptr();
|
||||
sol::table equipment(context.mLua->sol(), sol::create);
|
||||
if (!ptr.getClass().hasInventoryStore(ptr))
|
||||
return sol::nil;
|
||||
MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr);
|
||||
auto it = store.getSlot(slot);
|
||||
if (it == store.end())
|
||||
return sol::nil;
|
||||
context.mWorldView->getObjectRegistry()->registerPtr(*it);
|
||||
return o.getObject(context.mLua->sol(), getId(*it));
|
||||
};
|
||||
actor["equipment"] = sol::overload(getAllEquipment, getEquipmentFromSlot);
|
||||
actor["hasEquipped"] = [](const Object& o, const Object& item)
|
||||
{
|
||||
const MWWorld::Ptr& ptr = o.ptr();
|
||||
|
@ -108,12 +108,14 @@
|
||||
|
||||
---
|
||||
-- Get equipment.
|
||||
-- Returns a table `slot` -> @{openmw.core#GameObject} of currently equipped items.
|
||||
-- Has two overloads:
|
||||
-- 1) With single argument: returns a table `slot` -> @{openmw.core#GameObject} of currently equipped items.
|
||||
-- See @{#EQUIPMENT_SLOT}. Returns empty table if the actor doesn't have
|
||||
-- equipment slots.
|
||||
-- equipment slots.
|
||||
-- 2) With two arguments: returns an item equipped to the given slot.
|
||||
-- @function [parent=#Actor] equipment
|
||||
-- @param openmw.core#GameObject actor
|
||||
-- @return #map<#number,openmw.core#GameObject>
|
||||
-- @param #number slot (optional argument)
|
||||
|
||||
---
|
||||
-- Set equipment.
|
||||
|
Loading…
x
Reference in New Issue
Block a user