From e3016cdc037013b183066a65082d88cb5bd87e81 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 2 May 2020 11:45:05 +0100 Subject: [PATCH] Fix plugin game action hook player and result (#11587) - Player was not being attached to the game action event args. - OpenRCT2 was looking for error on the event args object rather than the result sub object. --- distribution/openrct2.d.ts | 2 +- src/openrct2/scripting/ScriptEngine.cpp | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 798635f3a2..64f6859f61 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -242,7 +242,7 @@ declare global { } interface GameActionResult { - error?: string; + error?: number; errorTitle?: string; errorMessage?: string; position?: Coord3; diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index ba5f629a8f..a52689d934 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -942,6 +942,7 @@ void ScriptEngine::RunGameActionHooks(const GameAction& action, std::unique_ptr< if (_hookEngine.HasSubscriptions(hookType)) { DukObject obj(_context); + obj.Set("player", action.GetPlayer()); obj.Set("type", action.GetType()); auto flags = action.GetActionFlags(); @@ -957,12 +958,16 @@ void ScriptEngine::RunGameActionHooks(const GameAction& action, std::unique_ptr< if (!isExecute) { - auto error = AsOrDefault(dukEventArgs["error"]); - if (error != 0) + auto dukResult = dukEventArgs["result"]; + if (dukResult.type() == DukValue::Type::OBJECT) { - result->Error = static_cast(error); - result->ErrorTitle = AsOrDefault(dukEventArgs["errorTitle"]); - result->ErrorMessage = AsOrDefault(dukEventArgs["errorMessage"]); + auto error = AsOrDefault(dukResult["error"]); + if (error != 0) + { + result->Error = static_cast(error); + result->ErrorTitle = AsOrDefault(dukResult["errorTitle"]); + result->ErrorMessage = AsOrDefault(dukResult["errorMessage"]); + } } } }