mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Merge branch 'lua_players' into 'master'
[Lua] Add `nearby.players` and `world.players` See merge request OpenMW/openmw!3150
This commit is contained in:
commit
6adcd122a8
7 changed files with 16 additions and 5 deletions
|
@ -222,6 +222,7 @@ namespace MWLua
|
|||
addTimeBindings(api, context, true);
|
||||
addCellGetters(api, context);
|
||||
api["activeActors"] = GObjectList{ worldView->getActorsInScene() };
|
||||
api["players"] = GObjectList{ worldView->getPlayers() };
|
||||
api["createObject"] = [](std::string_view recordId, sol::optional<int> count) -> GObject {
|
||||
// Doesn't matter which cell to use because the new object will be in disabled state.
|
||||
MWWorld::CellStore* cell = MWBase::Environment::get().getWorldScene()->getCurrentCell();
|
||||
|
|
|
@ -246,6 +246,7 @@ namespace MWLua
|
|||
return;
|
||||
if (!mPlayer.isEmpty())
|
||||
throw std::logic_error("Player is initialized twice");
|
||||
mWorldView.setPlayer(ptr);
|
||||
mWorldView.objectAddedToScene(ptr);
|
||||
mPlayer = ptr;
|
||||
LocalScripts* localScripts = ptr.getRefData().getLuaScripts();
|
||||
|
|
|
@ -136,6 +136,7 @@ namespace MWLua
|
|||
api["containers"] = LObjectList{ worldView->getContainersInScene() };
|
||||
api["doors"] = LObjectList{ worldView->getDoorsInScene() };
|
||||
api["items"] = LObjectList{ worldView->getItemsInScene() };
|
||||
api["players"] = LObjectList{ worldView->getPlayers() };
|
||||
|
||||
api["NAVIGATOR_FLAGS"]
|
||||
= LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, DetourNavigator::Flag>({
|
||||
|
|
|
@ -51,10 +51,13 @@ namespace MWLua
|
|||
ObjectIdList getContainersInScene() const { return mContainersInScene.mList; }
|
||||
ObjectIdList getDoorsInScene() const { return mDoorsInScene.mList; }
|
||||
ObjectIdList getItemsInScene() const { return mItemsInScene.mList; }
|
||||
ObjectIdList getPlayers() const { return mPlayers; }
|
||||
|
||||
void objectAddedToScene(const MWWorld::Ptr& ptr);
|
||||
void objectRemovedFromScene(const MWWorld::Ptr& ptr);
|
||||
|
||||
void setPlayer(const MWWorld::Ptr& player) { *mPlayers = { getId(player) }; }
|
||||
|
||||
void load(ESM::ESMReader& esm);
|
||||
void save(ESM::ESMWriter& esm) const;
|
||||
|
||||
|
@ -78,6 +81,7 @@ namespace MWLua
|
|||
ObjectGroup mContainersInScene;
|
||||
ObjectGroup mDoorsInScene;
|
||||
ObjectGroup mItemsInScene;
|
||||
ObjectIdList mPlayers = std::make_shared<std::vector<ObjectId>>();
|
||||
|
||||
double mSimulationTime = 0;
|
||||
bool mPaused = false;
|
||||
|
|
|
@ -20,11 +20,7 @@ local function getRandomOffset()
|
|||
end
|
||||
|
||||
local function getPlayerLevel()
|
||||
for i, actor in pairs(world.activeActors) do
|
||||
if (types.Player.objectIsInstance(actor)) then
|
||||
return types.Player.stats.level(actor).current
|
||||
end
|
||||
end
|
||||
return types.Player.stats.level(world.players[1]).current
|
||||
end
|
||||
|
||||
local function spawnFish(cell)
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
-- Everything that can be picked up in the nearby.
|
||||
-- @field [parent=#nearby] openmw.core#ObjectList items
|
||||
|
||||
---
|
||||
-- List of nearby players. Currently (since multiplayer is not yet implemented) always has one element.
|
||||
-- @field [parent=#nearby] openmw.core#ObjectList players
|
||||
|
||||
---
|
||||
-- Return an object by RefNum/FormId.
|
||||
-- Note: the function always returns @{openmw.core#GameObject} and doesn't validate that
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
-- List of currently active actors.
|
||||
-- @field [parent=#world] openmw.core#ObjectList activeActors
|
||||
|
||||
---
|
||||
-- List of players. Currently (since multiplayer is not yet implemented) always has one element.
|
||||
-- @field [parent=#world] openmw.core#ObjectList players
|
||||
|
||||
---
|
||||
-- Loads a named cell
|
||||
-- @function [parent=#world] getCellByName
|
||||
|
|
Loading…
Reference in a new issue