Skip to content

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++

MMO: the game's other one-off events (Dagoth Ur's taunts, the plague warning, the Skaal ritual stones), each player's own

Alan Saunders5d600ab893c7
diff --git a/isowind/server/CoreScripts/scripts/config.lua b/isowind/server/CoreScripts/scripts/config.lua
index 46f4bd2..c7af647 100644
--- a/isowind/server/CoreScripts/scripts/config.lua
+++ b/isowind/server/CoreScripts/scripts/config.lua
@@ -143,13 +143,29 @@ config.synchronizedClientScriptIds = {
"helsethScript", "KarrodMovement"
}
--- Isowind MMO mode: the scripts of the game's one-off events, which happen once for each player, and once for the
--- players near them together (see custom/isowindMmo.lua; MMO mode adds these to synchronizedClientScriptIds for the
--- server to keep how far each player's got). Co-op mode leaves them as they are: one world, so each event happens once.
--- Scripts that go by a quest's journal stages don't belong here: they already go by each player's own journal
+-- Isowind MMO mode: the scripts of the game's one-off events (local scripts on objects), which happen once for each
+-- player (see custom/isowindMmo.lua; MMO mode adds these to synchronizedClientScriptIds for the server to keep how far
+-- each player's got). Co-op mode leaves them as they are: one world, so each event happens once. Two kinds of entry:
+-- * "scriptId": a shared event, one that changes the world (enables, disables or deletes things). It also happens for
+-- the players near the one it happens to who haven't had it, and counts as had for them too.
+-- * { "scriptId", own = true }: an own event, only sounds, voices or messages, which other players' games can't be
+-- shown. Each player has it once, on their own, whoever is near.
+-- Scripts that change the player (journal, items, topics, globals...), spawn things, bring in someone hostile, or follow
+-- quest or world state all the time don't belong here
config.isowindEventScriptIds = {
-- Tarhiel falling from the sky near Seyda Neen (the script is on his journal, on the ground below)
- "fallingScript"
+ "fallingScript",
+ -- Dagoth Ur's voice taunting you as you step on the plates through his citadel with Wraithguard (one per plate)
+ { "DagothTaunt_1", own = true }, { "DagothTaunt_2", own = true }, { "DagothTaunt_3", own = true },
+ { "DagothTaunt_4", own = true }, { "DagothTaunt_5", own = true }, { "DagothTaunt_6", own = true },
+ { "DagothTaunt_7", own = true },
+ -- Tribunal: the stench warning as you near the plague's source in Gedna Relvel's tomb, Old Mournhold
+ { "PlagueWarning", own = true },
+ -- Bloodmoon: the sound at each Skaal ritual's stone as that ritual (beasts, earth, sun, trees, water, wind) is done
+ { "stoneeffect1Script", own = true }, { "stoneeffect2Script", own = true }, { "stoneeffect3Script", own = true },
+ { "stoneeffect4Script", own = true }, { "stoneeffect5Script", own = true }, { "stoneeffect6Script", own = true },
+ -- Bloodmoon: the ice wall cracking in the Halls of Penumbra during the Ritual of the Sun
+ { "icewallcrackScript", own = true }
}
-- Whether the instanced spawn should be used instead of the noninstanced one
diff --git a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
index 976090a..d1be307 100644
--- a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
+++ b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
@@ -12,22 +12,32 @@
-- the host's respawn speed. Ones from the game's files are reset on each client ("isowind respawn", a console
-- command packet the game handles itself); leveled-list ones are spawned again where they first appeared. Someone a
-- quest script brought into the world (Tarhiel falling from the sky) is a one-off and stays dead.
--- * The game's one-off events (the scripts in config.isowindEventScriptIds: Tarhiel falling from the sky near Seyda
--- Neen) happen once for each player. What an event's script does to the world (enabling, disabling or deleting) and
--- how far it has got (its short and long local variables, isowindEventLocals) are each player's own. Players near the
--- one whose event it is (EVENT_BUBBLE_UNITS outdoors, the same cell indoors) who haven't had it see it with them, and
--- it counts as had for them too; the others get their own when they come by. The people an event script brings in or
--- takes away are run by each player's game itself ("isowind local"), not by whoever's game runs the cell, so each
--- player's game has its own of them: their deaths (isowindEventDeaths, which the player's game reports) are each
--- player's own, as their loot already is. The party doesn't share events: they're for whoever is there.
+-- * The game's one-off events (the scripts in config.isowindEventScriptIds) happen once for each player. What an event's
+-- script does to the world (enabling, disabling or deleting) and how far it has got (its short and long local
+-- variables, isowindEventLocals) are each player's own, kept per object and replayed when their game loads the cell.
+-- There are two kinds:
+-- - Shared events (a plain script id: Tarhiel falling from the sky near Seyda Neen) change the world. Players near the
+-- one whose event it is (EVENT_BUBBLE_UNITS outdoors, the same cell indoors) who haven't had it see it with them,
+-- and it counts as had for them too; the others get their own when they come by.
+-- - Own events ({ "scriptId", own = true }: Dagoth Ur's taunts) are only sounds, voices or messages, which other
+-- players' games can't be shown: each player has them once, on their own, whoever is near; nothing of them goes to
+-- anyone else.
+-- The people an event script brings in or takes away are run by each player's game itself ("isowind local"), not by
+-- whoever's game runs the cell, so each player's game has its own of them: their deaths (isowindEventDeaths, which the
+-- player's game reports) are each player's own, as their loot already is. The party doesn't share events: they're
+-- for whoever is there.
if not IsowindHost.IsMmo() then
return
end
--- The server keeps how far each player's one-off events have got: their games send their scripts' local variables
-for _, scriptId in ipairs(config.isowindEventScriptIds or {}) do
- tableHelper.insertValueIfMissing(config.synchronizedClientScriptIds, scriptId)
+-- The server keeps how far each player's one-off events have got: their games send their scripts' local variables.
+-- (An entry of config.isowindEventScriptIds is a script id, or { scriptId, own = true } for an own event.)
+for _, entry in ipairs(config.isowindEventScriptIds or {}) do
+ local scriptId = type(entry) == "table" and entry[1] or entry
+ if type(scriptId) == "string" then
+ tableHelper.insertValueIfMissing(config.synchronizedClientScriptIds, scriptId)
+ end
end
config.shareJournal = false
@@ -271,20 +281,24 @@ local cellLoadedAt = {}
-- The event people each player's game was told to run itself, this session: { name = { cellDescription = { uniqueIndex
-- = true } } }
local runsOwnCopy = {}
+-- Under which load of the cell (cellLoadedAt) each player's own events last wrote each object's data, this session:
+-- { name = { cellDescription = { uniqueIndex = load time } } }
+local ownWrittenAt = {}
--- The event a packet from a script is about (its script, in lower case), or nil
+-- The event a packet from a script is about (its script, in lower case) and whether it's an own event, or nil
local function eventScriptOf(packetOrigin)
if packetOrigin ~= enumerations.packetOrigin.CLIENT_SCRIPT_LOCAL and
packetOrigin ~= enumerations.packetOrigin.CLIENT_SCRIPT_GLOBAL then
- return nil
+ return nil, false
end
local script = string.lower(tes3mp.GetObjectListClientScript() or "")
- for _, scriptId in ipairs(config.isowindEventScriptIds or {}) do
- if string.lower(scriptId) == script then
- return script
+ for _, entry in ipairs(config.isowindEventScriptIds or {}) do
+ local scriptId = type(entry) == "table" and entry[1] or entry
+ if type(scriptId) == "string" and string.lower(scriptId) == script then
+ return script, type(entry) == "table" and entry.own == true
end
end
- return nil
+ return nil, false
end
local function getEventsHad()
@@ -336,6 +350,24 @@ local function isRefire(name, cellDescription)
return loadedAt ~= nil and os.time() - loadedAt <= EVENT_REFIRE_SECONDS
end
+local function markOwnWritten(name, cellDescription, uniqueIndex)
+ local loadedAt = cellLoadedAt[name] ~= nil and cellLoadedAt[name][cellDescription] or 0
+ ownWrittenAt[name] = ownWrittenAt[name] or {}
+ ownWrittenAt[name][cellDescription] = ownWrittenAt[name][cellDescription] or {}
+ ownWrittenAt[name][cellDescription][uniqueIndex] = loadedAt
+end
+
+-- An own event's change from a player's game that comes from its script starting over on loading the cell: kept for
+-- the player from before (kept isn't nil), and nothing of it written since that load
+local function isOwnRefire(name, cellDescription, uniqueIndex, kept)
+ if kept == nil or not isRefire(name, cellDescription) then
+ return false
+ end
+ local written = ownWrittenAt[name] ~= nil and ownWrittenAt[name][cellDescription] ~= nil and
+ ownWrittenAt[name][cellDescription][uniqueIndex] or nil
+ return written ~= cellLoadedAt[name][cellDescription]
+end
+
-- An event script's short and long local variables from a ClientScriptLocal packet, as { "type:index" = value } (keys
-- that stay as they are in the cell's file); its floats are timers, changing all the time, and are never kept
local function intLocals(variables)
@@ -595,10 +627,29 @@ local function eventRunOf(pid, event)
end
-- An event script enabling or disabling the game's own people or things: for the player, and the others in their run
--- if it's theirs
-local function onEventStates(pid, cell, mine, event)
+-- if it's theirs (an own event's: the player's alone)
+local function onEventStates(pid, cell, mine, event, own)
local name = playerKey(pid)
registerEventObjects(cell, mine, event)
+
+ if own then
+ local answer = {}
+ for uniqueIndex, object in pairs(mine) do
+ local kept = getOwnState(cell, uniqueIndex, name)
+ if isOwnRefire(name, cell.description, uniqueIndex, kept) then
+ -- Their game's script starting over on loading the cell: it gets back what the player has
+ answer[uniqueIndex] = { refId = object.refId, state = kept }
+ else
+ setOwnState(cell, uniqueIndex, object.refId, name, object.state)
+ markOwnWritten(name, cell.description, uniqueIndex)
+ answer[uniqueIndex] = object
+ end
+ end
+ -- (the player's own game waits for the server to make the change)
+ sendStates(pid, cell.description, answer)
+ return
+ end
+
local run, isStarter = eventRunOf(pid, event)
if run == nil and isRefire(name, cell.description) then
@@ -636,8 +687,11 @@ local function onEventStates(pid, cell, mine, event)
end
end
--- Whose an event script's deletion is: the run's if it's the player's run, else the player's own
-local function eventDeleters(pid, cell, mine, event)
+-- Whose an event script's deletion is: the run's if it's the player's run, else (and for an own event) the player's
+local function eventDeleters(pid, cell, mine, event, own)
+ if own then
+ return { playerKey(pid) }
+ end
local run, isStarter = eventRunOf(pid, event)
if not isStarter then
return { playerKey(pid) }
@@ -680,7 +734,8 @@ end
-- How far an event's script has got for a player (its short and long variables; ClientScriptLocal packets, which the
-- game sends for the scripts in config.synchronizedClientScriptIds): theirs, and their run's others' if the run is
--- theirs. Their own game already has it (it sets the variable before it tells the server), so it isn't sent back.
+-- theirs (an own event's: the player's alone). Their own game already has it (it sets the variable before it tells
+-- the server), so it isn't sent back.
local function onClientScriptLocal(eventStatus, pid, cellDescription, objects)
if eventStatus.validDefaultHandler == false then
return
@@ -689,7 +744,7 @@ local function onClientScriptLocal(eventStatus, pid, cellDescription, objects)
if packetOrigin == enumerations.packetOrigin.CLIENT_GAMEPLAY then
return onEventDeath(pid, cellDescription, objects)
end
- local event = eventScriptOf(packetOrigin)
+ local event, own = eventScriptOf(packetOrigin)
if event == nil then
return
end
@@ -711,14 +766,33 @@ local function onClientScriptLocal(eventStatus, pid, cellDescription, objects)
end
local name = playerKey(pid)
+ if own then
+ local answer = {}
+ for uniqueIndex, change in pairs(changes) do
+ local kept = getOwnLocals(cell, uniqueIndex, name)
+ if isOwnRefire(name, cellDescription, uniqueIndex, kept) then
+ -- Their game's script starting over on loading the cell: it gets back how far the player had got
+ answer[uniqueIndex] = { refId = change.refId, vars = kept }
+ else
+ setOwnLocals(cell, uniqueIndex, change.refId, name, change.vars)
+ markOwnWritten(name, cellDescription, uniqueIndex)
+ end
+ end
+ if next(answer) ~= nil then
+ sendLocals(pid, cellDescription, answer)
+ end
+ cell:QuicksaveToDrive()
+ return customEventHooks.makeEventStatus(false, true)
+ end
+
local run, isStarter = eventRunOf(pid, event)
if run == nil and isRefire(name, cellDescription) then
-- Their game's script starting over on loading the cell: it gets back how far the player had got
local answer = {}
for uniqueIndex, change in pairs(changes) do
- local own = getOwnLocals(cell, uniqueIndex, name)
- if own ~= nil then
- answer[uniqueIndex] = { refId = change.refId, vars = own }
+ local kept = getOwnLocals(cell, uniqueIndex, name)
+ if kept ~= nil then
+ answer[uniqueIndex] = { refId = change.refId, vars = kept }
else
setOwnLocals(cell, uniqueIndex, change.refId, name, change.vars)
end
@@ -785,10 +859,13 @@ local function onObjectDelete(eventStatus, pid, cellDescription, objects)
end
-- A quest's deletion is the whole party's, an event's its run's; a pickup only the player's
- local event = fromScript and eventScriptOf(packetOrigin) or nil
+ local event, ownEvent = nil, false
+ if fromScript then
+ event, ownEvent = eventScriptOf(packetOrigin)
+ end
local names
if event ~= nil then
- names = eventDeleters(pid, cell, mine, event)
+ names = eventDeleters(pid, cell, mine, event, ownEvent)
else
names = fromScript and questSharers(pid) or { playerKey(pid) }
end
@@ -845,9 +922,9 @@ local function onObjectState(eventStatus, pid, cellDescription, objects)
return
end
- local event = eventScriptOf(packetOrigin)
+ local event, ownEvent = eventScriptOf(packetOrigin)
if event ~= nil then
- onEventStates(pid, cell, mine, event)
+ onEventStates(pid, cell, mine, event, ownEvent)
else
local names = questSharers(pid)
cell.data.isowindStates = cell.data.isowindStates or {}
diff --git a/isowind/server/tests/eventtest.lua b/isowind/server/tests/eventtest.lua
index 32b4d5b..43c35ed 100644
--- a/isowind/server/tests/eventtest.lua
+++ b/isowind/server/tests/eventtest.lua
@@ -328,6 +328,98 @@ local function runTests()
for _, key in ipairs({ "isowindEvents", "isowindEventLocals", "isowindEventDeaths", "isowindStates" }) do
cell.data[key] = nil
end
+
+ -- Own events: Dagoth Ur's first taunt in his citadel (a voice only). Alpha steps on the plate with Beta beside them
+ -- in the same cell: it's Alpha's alone; Beta has their own when they step on it
+ local CITADEL = "Dagoth Ur, Outer Facility"
+ local PLATE = "500001-0"
+ local sync = config.synchronizedClientScriptIds
+ check("own events' scripts report their variables too", tableHelper.containsValue(sync, "DagothTaunt_1") and
+ tableHelper.containsValue(sync, "DagothTaunt_7") and tableHelper.containsValue(sync, "stoneeffect1Script") and
+ tableHelper.containsValue(sync, "fallingScript"))
+ logicHandler.LoadCell(CITADEL)
+ local citadel = LoadedCells[CITADEL]
+ citadel.data.isowindEventLocals = nil
+ citadel.data.isowindStates = nil
+ places[0] = { cell = CITADEL, exterior = false, x = 100, y = 100 }
+ places[1] = { cell = CITADEL, exterior = false, x = 150, y = 100 }
+ places[2] = { cell = CITADEL, exterior = false, x = 200, y = 100 }
+ WorldInstance.data.isowindEventsHad.dagothtaunt_1 = nil
+ citadel.visitors = { 0, 1 }
+ local function taunt(pid, value)
+ receive(LOCAL, "DagothTaunt_1")
+ return validate("OnClientScriptLocal", { pid, CITADEL, { [PLATE] = { refId = "in_dagoth_taunt1",
+ uniqueIndex = PLATE, variables = { [SHORT] = { [0] = value } } } }, {} })
+ end
+ sent = {}
+ status = taunt(0, 1)
+ local tauntRecord = citadel.data.isowindEventLocals ~= nil and citadel.data.isowindEventLocals[PLATE] or nil
+ check("own event: done kept for Alpha", status.validDefaultHandler == false and tauntRecord ~= nil and
+ tauntRecord.players.alpha["0:0"] == 1)
+ check("own event: Beta beside them isn't given it", tauntRecord ~= nil and tauntRecord.players.beta == nil)
+ check("own event: nothing sent to anyone", #sent == 0)
+ check("own event: no one marked as having had it", WorldInstance.data.isowindEventsHad.dagothtaunt_1 == nil)
+ sent = {}
+ taunt(1, 1)
+ check("own event: Beta's own taunt is Beta's", tauntRecord.players.beta ~= nil and
+ tauntRecord.players.beta["0:0"] == 1 and #sent == 0)
+
+ -- An own event's enable or disable (none of the listed ones has any) is the player's alone, and comes back to them
+ sent = {}
+ receive(LOCAL, "PlagueWarning")
+ validate("OnObjectState", { 0, CITADEL, { ["500002-0"] = { refId = "x_thing", uniqueIndex = "500002-0",
+ state = false } }, {} })
+ check("own event state: Alpha's alone", citadel.data.isowindStates["500002-0"].players.alpha == false and
+ citadel.data.isowindStates["500002-0"].players.beta == nil)
+ check("own event state: back to Alpha only", #sentTo("SendObjectState", 0) == 1 and
+ #sentTo("SendObjectState", 1) == 0)
+
+ -- Alpha logs in again: the taunt is still done, and a re-fire on loading is answered with it
+ sent = {}
+ citadel.visitors = { 0 }
+ customEventHooks.triggerHandlers("OnCellLoad", customEventHooks.makeEventStatus(true, true), { 0, CITADEL })
+ local tauntReplay = sentTo("SendClientScriptLocal", 0)[1]
+ check("own event: cell load replays done to Alpha", tauntReplay ~= nil and
+ localValue(tauntReplay, "500001", 0) == 1)
+ sent = {}
+ taunt(0, 2)
+ local tauntAnswer = sentTo("SendClientScriptLocal", 0)[1]
+ check("own event: a re-fire is answered with Alpha's", tauntAnswer ~= nil and
+ localValue(tauntAnswer, "500001", 0) == 1 and tauntRecord.players.alpha["0:0"] == 1)
+
+ -- Gamma has it for the first time just after loading the cell: later changes in that load are kept, not re-fires
+ customEventHooks.triggerHandlers("OnCellLoad", customEventHooks.makeEventStatus(true, true), { 2, CITADEL })
+ sent = {}
+ taunt(2, 1)
+ taunt(2, 2)
+ check("own event: Gamma's first time and what follows are kept", tauntRecord.players.gamma ~= nil and
+ tauntRecord.players.gamma["0:0"] == 2 and #sent == 0)
+
+ -- A ritual stone's sound, placed twice: each placement is the player's own once, Beta near them gets nothing
+ places[0] = { cell = "-20, 19", exterior = true, x = -160000, y = 160000 }
+ places[1] = { cell = "-20, 19", exterior = true, x = -160100, y = 160000 }
+ local STONES = { { cell = "-20, 19", uniqueIndex = "600001-0" }, { cell = "-20, 24", uniqueIndex = "600002-0" } }
+ sent = {}
+ for _, stone in ipairs(STONES) do
+ logicHandler.LoadCell(stone.cell)
+ LoadedCells[stone.cell].data.isowindEventLocals = nil
+ receive(LOCAL, "stoneeffect1Script")
+ validate("OnClientScriptLocal", { 0, stone.cell, { [stone.uniqueIndex] = { refId = "active_BM_stonesound1",
+ uniqueIndex = stone.uniqueIndex, variables = { [SHORT] = { [0] = 1 } } } }, {} })
+ end
+ local stone1 = LoadedCells["-20, 19"].data.isowindEventLocals["600001-0"]
+ local stone2 = LoadedCells["-20, 24"].data.isowindEventLocals["600002-0"]
+ check("own event: both placements are Alpha's", stone1.players.alpha["0:0"] == 1 and
+ stone2.players.alpha["0:0"] == 1)
+ check("own event: Beta near Alpha gets neither", stone1.players.beta == nil and stone2.players.beta == nil and
+ #sent == 0)
+ for _, stone in ipairs(STONES) do
+ LoadedCells[stone.cell].data.isowindEventLocals = nil
+ LoadedCells[stone.cell]:QuicksaveToDrive()
+ end
+ citadel.data.isowindEventLocals = nil
+ citadel.data.isowindStates = nil
+ citadel:QuicksaveToDrive()
log("done, " .. failures .. " failed")
end