From ca21bc35c2a09a8976fb75caded69ea41b178e3d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 19 Sep 2019 08:46:54 +0300 Subject: [PATCH] [Server] Add script functions that read & send ScriptGlobalShort packets --- apps/openmw-mp/Script/Functions/Objects.cpp | 31 +++++++++++++++++++++ apps/openmw-mp/Script/Functions/Objects.hpp | 15 ++++++++++ 2 files changed, 46 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index 4e8528a6b..9373fad48 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -254,6 +254,16 @@ const char *ObjectFunctions::GetVideoFilename(unsigned int index) noexcept return readObjectList->baseObjects.at(index).videoFilename.c_str(); } +const char *ObjectFunctions::GetScriptVariableName(unsigned int index) noexcept +{ + return readObjectList->baseObjects.at(index).varName.c_str(); +} + +int ObjectFunctions::GetScriptVariableShortValue(unsigned int index) noexcept +{ + return readObjectList->baseObjects.at(index).shortVal; +} + unsigned int ObjectFunctions::GetContainerChangesSize(unsigned int objectIndex) noexcept { return readObjectList->baseObjects.at(objectIndex).containerItemCount; @@ -436,6 +446,16 @@ void ObjectFunctions::SetObjectDoorDestinationRotation(double x, double z) noexc tempObject.destinationPosition.rot[2] = z; } +void ObjectFunctions::SetScriptVariableName(const char* varName) noexcept +{ + tempObject.varName = varName; +} + +void ObjectFunctions::SetScriptVariableShortValue(int shortVal) noexcept +{ + tempObject.shortVal = shortVal; +} + void ObjectFunctions::SetPlayerAsObject(unsigned short pid) noexcept { Player *player; @@ -622,6 +642,17 @@ void ObjectFunctions::SendVideoPlay(bool sendToOtherPlayers, bool skipAttachedPl packet->Send(true); } +void ObjectFunctions::SendScriptGlobalShort(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept +{ + mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_SCRIPT_GLOBAL_SHORT); + packet->setObjectList(&writeObjectList); + + if (!skipAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); +} + void ObjectFunctions::SendConsoleCommand(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_CONSOLE_COMMAND); diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index bed37e903..d55224408 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -54,6 +54,9 @@ \ {"GetVideoFilename", ObjectFunctions::GetVideoFilename},\ \ + {"GetScriptVariableName", ObjectFunctions::GetScriptVariableName},\ + {"GetScriptVariableShortValue", ObjectFunctions::GetScriptVariableShortValue},\ + \ {"GetContainerChangesSize", ObjectFunctions::GetContainerChangesSize},\ {"GetContainerItemRefId", ObjectFunctions::GetContainerItemRefId},\ {"GetContainerItemCount", ObjectFunctions::GetContainerItemCount},\ @@ -93,6 +96,9 @@ {"SetObjectDoorDestinationPosition", ObjectFunctions::SetObjectDoorDestinationPosition},\ {"SetObjectDoorDestinationRotation", ObjectFunctions::SetObjectDoorDestinationRotation},\ \ + {"SetScriptVariableName", ObjectFunctions::SetScriptVariableName},\ + {"SetScriptVariableShortValue", ObjectFunctions::SetScriptVariableShortValue},\ + \ {"SetPlayerAsObject", ObjectFunctions::SetPlayerAsObject},\ \ {"SetContainerItemRefId", ObjectFunctions::SetContainerItemRefId},\ @@ -118,6 +124,7 @@ {"SendDoorDestination", ObjectFunctions::SendDoorDestination},\ {"SendContainer", ObjectFunctions::SendContainer},\ {"SendVideoPlay", ObjectFunctions::SendVideoPlay},\ + {"SendScriptGlobalShort", ObjectFunctions::SendScriptGlobalShort},\ {"SendConsoleCommand", ObjectFunctions::SendConsoleCommand},\ \ {"ReadLastObjectList", ObjectFunctions::ReadLastObjectList},\ @@ -508,6 +515,9 @@ public: */ static const char *GetVideoFilename(unsigned int index) noexcept; + static const char *GetScriptVariableName(unsigned int index) noexcept; + static int GetScriptVariableShortValue(unsigned int index) noexcept; + /** * \brief Get the number of container item indexes of the object at a certain index in the * read object list. @@ -841,6 +851,9 @@ public: */ static void SetObjectDoorDestinationRotation(double x, double z) noexcept; + static void SetScriptVariableName(const char* varName) noexcept; + static void SetScriptVariableShortValue(int shortVal) noexcept; + /** * \brief Set a player as the object in the temporary object stored on the server. * Currently only used for ConsoleCommand packets. @@ -1057,6 +1070,8 @@ public: */ static void SendVideoPlay(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; + static void SendScriptGlobalShort(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; + /** * \brief Send a ConsoleCommand packet. *