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