From 7ae9ea746547b22b2506ba747686ed287acfe8c6 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 27 Sep 2016 15:51:10 +0300 Subject: [PATCH] Add server stat functions for getting attribute and skill counts --- apps/openmw-mp/Script/Functions/Stats.cpp | 16 ++++++++++++++++ apps/openmw-mp/Script/Functions/Stats.hpp | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index dc46acffe..5d570f227 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -246,6 +246,16 @@ void StatsFunctions::SetCurrentFatigue(unsigned short pid, float value) noexcept player->CreatureStats()->mDynamic[2].mCurrent = 0; } +int StatsFunctions::GetAttributeCount() noexcept +{ + return Attribute::Length; +} + +int StatsFunctions::GetSkillCount() noexcept +{ + return Skill::Length; +} + int StatsFunctions::GetAttributeId(const char *name) noexcept { for (int x = 0; x < Attribute::Length; x++) @@ -274,11 +284,17 @@ int StatsFunctions::GetSkillId(const char *name) noexcept const char *StatsFunctions::GetAttributeName(unsigned short attribute) noexcept { + if (attribute >= Attribute::Length) + return "invalid"; + return Attribute::sAttributeNames[attribute].c_str(); } const char *StatsFunctions::GetSkillName(unsigned short skill) noexcept { + if (skill >= Skill::Length) + return "invalid"; + return Skill::sSkillNames[skill].c_str(); } diff --git a/apps/openmw-mp/Script/Functions/Stats.hpp b/apps/openmw-mp/Script/Functions/Stats.hpp index 0c7e8a5c5..e757dfaad 100644 --- a/apps/openmw-mp/Script/Functions/Stats.hpp +++ b/apps/openmw-mp/Script/Functions/Stats.hpp @@ -27,6 +27,8 @@ {"GetBirthsign", StatsFunctions::GetBirthsign},\ {"SetBirthsign", StatsFunctions::SetBirthsign},\ \ + {"GetAttributeCount", StatsFunctions::GetAttributeCount},\ + {"GetSkillCount", StatsFunctions::GetSkillCount},\ {"GetAttributeId", StatsFunctions::GetAttributeId},\ {"GetSkillId", StatsFunctions::GetSkillId},\ {"GetAttributeName", StatsFunctions::GetAttributeName},\ @@ -108,6 +110,8 @@ public: static float GetCurrentFatigue(unsigned short pid) noexcept; static void SetCurrentFatigue(unsigned short pid, float value) noexcept; + static int GetAttributeCount() noexcept; + static int GetSkillCount() noexcept; static int GetAttributeId(const char *name) noexcept; static int GetSkillId(const char *name) noexcept; static const char *GetAttributeName(unsigned short attribute) noexcept;