An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.
C++
Isowind 7f4fca8: MMO: what quest scripts do to the world is per player
Isowindc185aa798d47
diff --git a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua b/isowind/server/CoreScripts/scripts/custom/isowindMmo.luaindex 61c73d6..4b0b048 100644--- a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua+++ b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua@@ -4,7 +4,9 @@-- theirs alone (kept per player in the cell's data, isowindLoot, and replayed to them when they load the cell).-- Containers players placed stay shared.-- * Loose items from the game's files (not ones players dropped) are picked up per player too (isowindTaken).--- * Quests, topics, factions, bounties, reputation and kill counts are each player's own.+-- * Quests, topics, factions, bounties, reputation and kill counts are each player's own, and so is what quest scripts+-- do to the world's own people and things: enabling or disabling them (isowindStates) or deleting them (isowindTaken),+-- so a quest that removes someone for one player leaves them there for the others.-- * Enemies and NPCs come back after they die, once no player is in or next to their cell, after a time from how-- tough they were (WoW-like tiers, from their health): trash 1.5 minutes, normal 5, elite 15, bosses 60, divided by-- the host's respawn speed. Ones from the game's files are reset on each client ("isowind respawn", a console@@ -206,9 +208,18 @@ end-- --- Loose items per player --------------------------------------------------------------------------------------+-- A script or dialogue (a quest's), rather than the player's hands or the console+local function isFromScript(packetOrigin)+ return packetOrigin == enumerations.packetOrigin.CLIENT_SCRIPT_LOCAL or+ packetOrigin == enumerations.packetOrigin.CLIENT_SCRIPT_GLOBAL or+ packetOrigin == enumerations.packetOrigin.CLIENT_DIALOGUE+end+local function onObjectDelete(eventStatus, pid, cellDescription, objects)+ local packetOrigin = tes3mp.GetObjectListOrigin()+ local fromScript = isFromScript(packetOrigin)if eventStatus.validDefaultHandler == false or- tes3mp.GetObjectListOrigin() ~= enumerations.packetOrigin.CLIENT_GAMEPLAY then+ (packetOrigin ~= enumerations.packetOrigin.CLIENT_GAMEPLAY and not fromScript) thenreturnendlocal cell = LoadedCells[cellDescription]@@ -216,10 +227,12 @@ local function onObjectDelete(eventStatus, pid, cellDescription, objects)returnend+ -- The game's own things a player picks up, or a quest of theirs deletes (people too); bodies a player disposes of+ -- stay sharedlocal mine, shared = {}, {}for uniqueIndex, object in pairs(objects) dolocal _, mpNum = splitIndex(uniqueIndex)- if mpNum == 0 and not isActor(cell, uniqueIndex) then+ if mpNum == 0 and (fromScript or not isActor(cell, uniqueIndex)) thenmine[uniqueIndex] = objectelseshared[uniqueIndex] = object@@ -250,6 +263,46 @@ local function onObjectDelete(eventStatus, pid, cellDescription, objects)return customEventHooks.makeEventStatus(false, true)end+-- A quest script enabling or disabling one of the game's own people or things: for that player only+local function onObjectState(eventStatus, pid, cellDescription, objects)+ if eventStatus.validDefaultHandler == false or not isFromScript(tes3mp.GetObjectListOrigin()) then+ return+ end+ local cell = LoadedCells[cellDescription]+ if cell == nil then+ return+ end++ local mine, shared = {}, {}+ for uniqueIndex, object in pairs(objects) do+ local _, mpNum = splitIndex(uniqueIndex)+ if mpNum == 0 then+ mine[uniqueIndex] = object+ else+ shared[uniqueIndex] = object+ end+ end+ if next(mine) == nil then+ return+ end++ local name = playerKey(pid)+ cell.data.isowindStates = cell.data.isowindStates or {}+ for uniqueIndex, object in pairs(mine) do+ local record = cell.data.isowindStates[uniqueIndex] or { refId = object.refId, players = {} }+ record.players[name] = object.state+ cell.data.isowindStates[uniqueIndex] = record+ end++ -- The rest as the default handler does+ if next(shared) ~= nil then+ cell:SaveObjectsByPacketType("ObjectState", shared)+ cell:LoadObjectsByPacketType("ObjectState", pid, shared, tableHelper.getArrayFromIndexes(shared), true)+ end+ cell:QuicksaveToDrive()+ return customEventHooks.makeEventStatus(false, true)+end+-- A player loading a cell gets their own loot and pickups there on top of the shared state just sentlocal function onCellLoad(eventStatus, pid, cellDescription)local cell = LoadedCells[cellDescription]@@ -274,6 +327,23 @@ local function onCellLoad(eventStatus, pid, cellDescription)endend+ if cell.data.isowindStates ~= nil then+ tes3mp.ClearObjectList()+ tes3mp.SetObjectListPid(pid)+ tes3mp.SetObjectListCell(cellDescription)+ local count = 0+ for uniqueIndex, record in pairs(cell.data.isowindStates) do+ local state = record.players[name]+ if state ~= nil then+ packetBuilder.AddObjectState(uniqueIndex, { refId = record.refId, state = state })+ count = count + 1+ end+ end+ if count > 0 then+ tes3mp.SendObjectState(false)+ end+ end+if cell.data.isowindLoot ~= nil thenfor _, action in ipairs({ enumerations.container.ADD, enumerations.container.REMOVE }) dotes3mp.ClearObjectList()@@ -485,7 +555,8 @@ local function respawnInCell(cellDescription, uniqueIndexes)for _, uniqueIndex in ipairs(uniqueIndexes) dolocal objectData = cell.data.objectData[uniqueIndex]local moved = objectData ~= nil and (objectData.cellChangeTo ~= nil or objectData.cellChangeFrom ~= nil)- -- One a script disabled (a quest removing someone) stays gone+ -- One disabled for everyone (by the console, or before the server was MMO) stays gone; what a player's quest+ -- disabled stays that way for them (it's in isowindStates, which a respawn keeps)local disabled = objectData ~= nil and objectData.state == falselocal _, mpNum = splitIndex(uniqueIndex)if not moved and not disabled then@@ -581,6 +652,7 @@ endcustomEventHooks.registerHandler("OnServerPostInit", function(eventStatus)customEventHooks.registerValidator("OnContainer", onContainer)customEventHooks.registerValidator("OnObjectDelete", onObjectDelete)+ customEventHooks.registerValidator("OnObjectState", onObjectState)customEventHooks.registerHandler("OnCellLoad", onCellLoad)customEventHooks.registerHandler("OnObjectSpawn", onObjectSpawn)customEventHooks.registerHandler("OnActorDeath", onActorDeath)diff --git a/isowind/server/tests/mmotest.lua b/isowind/server/tests/mmotest.luaindex f40dcbc..b5082ee 100644--- a/isowind/server/tests/mmotest.lua+++ b/isowind/server/tests/mmotest.lua@@ -128,6 +128,37 @@ local function runTests()check("pickup sent to the player only", delete ~= nil and delete.args[1] == false)check("pickup not saved as shared", not tableHelper.containsValue(cell.data.packets.delete or {}, "5678-0"))+ -- A quest script disabling someone does it for that player only+ sent = {}+ receive({ objects = {}, origin = enumerations.packetOrigin.CLIENT_SCRIPT_GLOBAL })+ status = validate("OnObjectState", { pid, CELL, { ["4444-0"] = { refId = "quest_giver", uniqueIndex = "4444-0",+ state = false } }, {} })+ check("quest disable skips the shared save", status.validDefaultHandler == false)+ check("quest disable kept for the player", cell.data.isowindStates["4444-0"].players.alpha == false)+ check("quest disable not shared", cell.data.objectData["4444-0"] == nil or cell.data.objectData["4444-0"].state == nil)+ check("quest disable not sent to others", lastSent("SendObjectState") == nil)++ -- The player's hands enabling or disabling things (none do) and the console stay as they were+ receive({ objects = {}, origin = enumerations.packetOrigin.CLIENT_CONSOLE })+ status = validate("OnObjectState", { pid, CELL, { ["4445-0"] = { refId = "x", uniqueIndex = "4445-0",+ state = false } }, {} })+ check("console disable stays shared", status.validDefaultHandler ~= false)++ -- A quest script deleting a person: that player only+ receive({ objects = {}, origin = enumerations.packetOrigin.CLIENT_SCRIPT_LOCAL })+ cell.data.objectData["4446-0"] = { refId = "quest_npc_2", stats = { healthBase = 80 } }+ status = validate("OnObjectDelete", { pid, CELL, { ["4446-0"] = { refId = "quest_npc_2", uniqueIndex = "4446-0" } },+ {} })+ check("quest delete of a person is the player's own", status.validDefaultHandler == false and+ cell.data.isowindTaken["4446-0"].alpha == true)++ -- Loading the cell: the disable comes back for them+ sent = {}+ customEventHooks.triggerHandlers("OnCellLoad", customEventHooks.makeEventStatus(true, true), { pid, CELL })+ local stateReplay = lastSent("SendObjectState")+ check("cell load replays the quest disable to the player only", stateReplay ~= nil and stateReplay.args[1] == false+ and stateReplay.objects[1] ~= nil and tostring(stateReplay.objects[1].refNum) == "4444")+-- A dead mudcrab comes back after 1.5 minutes, once no one is nearcell.data.objectData["999-0"] = { refId = "mudcrab", stats = { healthBase = 35 } }customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),