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.
This commit is contained in:
Ted John 2020-05-02 11:45:05 +01:00 committed by GitHub
parent 32eb7071a1
commit e3016cdc03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -242,7 +242,7 @@ declare global {
}
interface GameActionResult {
error?: string;
error?: number;
errorTitle?: string;
errorMessage?: string;
position?: Coord3;

View file

@ -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<int32_t>(dukEventArgs["error"]);
if (error != 0)
auto dukResult = dukEventArgs["result"];
if (dukResult.type() == DukValue::Type::OBJECT)
{
result->Error = static_cast<GA_ERROR>(error);
result->ErrorTitle = AsOrDefault<std::string>(dukEventArgs["errorTitle"]);
result->ErrorMessage = AsOrDefault<std::string>(dukEventArgs["errorMessage"]);
auto error = AsOrDefault<int32_t>(dukResult["error"]);
if (error != 0)
{
result->Error = static_cast<GA_ERROR>(error);
result->ErrorTitle = AsOrDefault<std::string>(dukResult["errorTitle"]);
result->ErrorMessage = AsOrDefault<std::string>(dukResult["errorMessage"]);
}
}
}
}