mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-19 19:39:41 +00:00
Add Lua script to handler ESM4 doors with Flag_AutomaticDoor
This commit is contained in:
parent
75c371de66
commit
773669e69b
5 changed files with 51 additions and 1 deletions
|
@ -106,5 +106,7 @@ namespace MWLua
|
|||
record["model"] = sol::readonly_property([vfs](const ESM4::Door& rec) -> std::string {
|
||||
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
|
||||
});
|
||||
record["isAutomatic"] = sol::readonly_property(
|
||||
[](const ESM4::Door& rec) -> bool { return rec.mDoorFlags & ESM4::Door::Flag_AutomaticDoor; });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace MWLua
|
|||
return &mActivatorsInScene;
|
||||
if (cls.isActor())
|
||||
return &mActorsInScene;
|
||||
if (cls.isDoor())
|
||||
if (ptr.mRef->getType() == ESM::REC_DOOR || ptr.mRef->getType() == ESM::REC_DOOR4)
|
||||
return &mDoorsInScene;
|
||||
if (typeid(cls) == typeid(MWClass::Container))
|
||||
return &mContainersInScene;
|
||||
|
|
|
@ -74,6 +74,7 @@ set(BUILTIN_DATA_FILES
|
|||
scripts/omw/console/player.lua
|
||||
scripts/omw/console/global.lua
|
||||
scripts/omw/console/local.lua
|
||||
scripts/omw/mechanics/playercontroller.lua
|
||||
scripts/omw/playercontrols.lua
|
||||
scripts/omw/settings/player.lua
|
||||
scripts/omw/settings/global.lua
|
||||
|
|
|
@ -7,6 +7,7 @@ PLAYER: scripts/omw/settings/player.lua
|
|||
|
||||
# Mechanics
|
||||
GLOBAL: scripts/omw/activationhandlers.lua
|
||||
PLAYER: scripts/omw/mechanics/playercontroller.lua
|
||||
PLAYER: scripts/omw/playercontrols.lua
|
||||
PLAYER: scripts/omw/camera/camera.lua
|
||||
NPC,CREATURE: scripts/omw/ai.lua
|
||||
|
|
46
files/data/scripts/omw/mechanics/playercontroller.lua
Normal file
46
files/data/scripts/omw/mechanics/playercontroller.lua
Normal file
|
@ -0,0 +1,46 @@
|
|||
local core = require('openmw.core')
|
||||
local nearby = require('openmw.nearby')
|
||||
local self = require('openmw.self')
|
||||
local types = require('openmw.types')
|
||||
|
||||
local cell = nil
|
||||
local autodoors = {}
|
||||
|
||||
local function onCellChange()
|
||||
autodoors = {}
|
||||
for _, door in ipairs(nearby.doors) do
|
||||
if door.type == types.ESM4Door and types.ESM4Door.record(door).isAutomatic then
|
||||
autodoors[#autodoors + 1] = door
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local autodoorActivationDist = 300
|
||||
|
||||
local lastAutoActivation = 0
|
||||
local function processAutomaticDoors()
|
||||
if core.getRealTime() - lastAutoActivation < 2 then
|
||||
return
|
||||
end
|
||||
for _, door in ipairs(autodoors) do
|
||||
if door.enabled and (door.position - self.position):length() < autodoorActivationDist then
|
||||
print('Automatic activation of', door)
|
||||
door:activateBy(self)
|
||||
lastAutoActivation = core.getRealTime()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onUpdate()
|
||||
if self.cell ~= cell then
|
||||
cell = self.cell
|
||||
onCellChange()
|
||||
end
|
||||
processAutomaticDoors()
|
||||
end
|
||||
|
||||
return {
|
||||
engineHandlers = {
|
||||
onUpdate = onUpdate,
|
||||
},
|
||||
}
|
Loading…
Reference in a new issue