From f270c3f1686923531058badf2e33633e54929d85 Mon Sep 17 00:00:00 2001 From: Degranon Date: Sat, 19 Oct 2024 21:10:39 +0500 Subject: [PATCH] Player teammembers --- doc/lua/player.md | 6 ++++++ source/game/StarPlayer.cpp | 16 ++++++++++++++++ source/game/StarPlayer.hpp | 2 ++ source/game/scripting/StarPlayerLuaBindings.cpp | 2 ++ 4 files changed, 26 insertions(+) diff --git a/doc/lua/player.md b/doc/lua/player.md index fd8ebd4..f281bad 100644 --- a/doc/lua/player.md +++ b/doc/lua/player.md @@ -527,3 +527,9 @@ Returns uuid, type, and orbits for all system objects in the specified system; #### `List` player.collectables(`String` collectionName) Returns a list of names of the collectables the player has unlocked in the specified collection. + +--- + +#### `List` player.teamMembers() + +Returns an array, each entry being a table with `name`, `uuid`, `entity`, `healthPercentage` and `energyPercentage` diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index 8ee6d7a..15890bb 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -35,6 +35,8 @@ #include "StarInspectionTool.hpp" #include "StarUtilityLuaBindings.hpp" #include "StarCelestialLuaBindings.hpp" +#include "StarUniverseClient.hpp" +#include "StarTeamClient.hpp" namespace Star { @@ -2072,6 +2074,20 @@ Vec2F Player::nametagOrigin() const { void Player::updateIdentity() { m_identityUpdated = true; m_humanoid->setIdentity(m_identity); } +JsonArray Player::teamMembers() { + JsonArray jarray; + for (auto member : m_client->teamClient()->members()) { + jarray.push_back(JsonObject{ + {"name", member.name}, + {"uuid", member.uuid.hex()}, + {"entity", member.entity}, + {"healthPercentage", member.healthPercentage}, + {"energyPercentage", member.energyPercentage} + }); + } + return jarray; +} + void Player::setBodyDirectives(String const& directives) { m_identity.bodyDirectives = directives; updateIdentity(); } diff --git a/source/game/StarPlayer.hpp b/source/game/StarPlayer.hpp index f6e32e0..fe97fce 100644 --- a/source/game/StarPlayer.hpp +++ b/source/game/StarPlayer.hpp @@ -316,6 +316,8 @@ public: void updateIdentity(); + JsonArray teamMembers(); + void setBodyDirectives(String const& directives); void setEmoteDirectives(String const& directives); diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index 7952f30..4343531 100644 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -27,6 +27,8 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { } }); + callbacks.registerCallback("teamMembers", [player]() { return player->teamMembers(); }); + callbacks.registerCallback( "humanoidIdentity", [player]() { return player->humanoid()->identity().toJson(); }); callbacks.registerCallback("setHumanoidIdentity", [player](Json const& id) { player->setIdentity(HumanoidIdentity(id)); });