From 41868cc9ccb4f6690b063a0c2a08ebef120b2c99 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 18 Aug 2016 00:13:45 +0300 Subject: [PATCH] Add script functions for getting attributes and skills by their IDs --- apps/openmw-mp/Script/Functions/Stats.cpp | 29 +++++++++++++++++++++++ apps/openmw-mp/Script/ScriptFunctions.hpp | 6 +++++ 2 files changed, 35 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 071056c3d..5dc4f60ac 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -5,10 +5,13 @@ #include #include #include +#include +#include #include #include using namespace std; +using namespace ESM; void ScriptFunctions::SetName(unsigned short pid, const char *name) noexcept { @@ -230,6 +233,32 @@ void ScriptFunctions::SetCurrentFatigue(unsigned short pid, float value) noexcep player->CreatureStats()->mDynamic[2].mCurrent = 0; } +int ScriptFunctions::GetAttributeIdByName(const char *name) noexcept +{ + for (int x = 0; x < 8; x++) + { + if (Misc::StringUtils::ciEqual(name, Attribute::sAttributeNames[x])) + { + return x; + } + } + + return -1; +} + +int ScriptFunctions::GetSkillIdByName(const char *name) noexcept +{ + for (int x = 0; x < 27; x++) + { + if (Misc::StringUtils::ciEqual(name, Skill::sSkillNames[x])) + { + return x; + } + } + + return -1; +} + int ScriptFunctions::GetAttribute(unsigned short pid, unsigned short attribute) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 8538a9af2..e780ea1b6 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -87,6 +87,9 @@ public: static float GetCurrentFatigue(unsigned short pid) noexcept; static void SetCurrentFatigue(unsigned short pid, float fatigue) noexcept; + static int GetAttributeIdByName(const char *name) noexcept; + static int GetSkillIdByName(const char *name) noexcept; + static int GetAttribute(unsigned short pid, unsigned short attribute) noexcept; static void SetAttribute(unsigned short pid, unsigned short attribute, int value) noexcept; static int GetCurrentAttribute(unsigned short pid, unsigned short attribute) noexcept; @@ -194,6 +197,9 @@ public: {"GetBirthsign", ScriptFunctions::GetBirthsign}, {"SetBirthsign", ScriptFunctions::SetBirthsign}, + {"GetAttributeIdByName", ScriptFunctions::GetAttributeIdByName}, + {"GetSkillIdByName", ScriptFunctions::GetSkillIdByName}, + {"GetAttribute", ScriptFunctions::GetAttribute}, {"SetAttribute", ScriptFunctions::SetAttribute}, {"GetCurrentAttribute", ScriptFunctions::GetCurrentAttribute},