From b8763510318eb6d1cbd5093bea4c8508dcb08857 Mon Sep 17 00:00:00 2001 From: shierru Date: Wed, 23 Oct 2024 11:36:53 +0300 Subject: [PATCH] Add IsValidWeapon native (#1009) --- Server/Components/Pawn/Scripting/Core/Natives.cpp | 5 +++++ Server/Source/core_impl.hpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/Server/Components/Pawn/Scripting/Core/Natives.cpp b/Server/Components/Pawn/Scripting/Core/Natives.cpp index 163057c9b..37a92546e 100644 --- a/Server/Components/Pawn/Scripting/Core/Natives.cpp +++ b/Server/Components/Pawn/Scripting/Core/Natives.cpp @@ -600,6 +600,11 @@ SCRIPT_API(GetWeaponName, bool(int weaponid, OutputOnlyString& weapon)) return true; } +SCRIPT_API(IsValidWeapon, bool(int weaponid)) +{ + return PawnManager::Get()->core->isWeaponValid(PlayerWeapon(weaponid)); +} + SCRIPT_API(LimitGlobalChatRadius, bool(float chatRadius)) { *PawnManager::Get()->config->getBool("game.use_chat_radius") = true; diff --git a/Server/Source/core_impl.hpp b/Server/Source/core_impl.hpp index 110b6c9fd..65cbf48fa 100644 --- a/Server/Source/core_impl.hpp +++ b/Server/Source/core_impl.hpp @@ -1995,6 +1995,16 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol return PlayerWeaponNames[index]; } + bool isWeaponValid(PlayerWeapon weapon) override + { + int index = int(weapon); + + if (weapon < 0 || weapon > PlayerWeapon_End) + return false; + + return true; + } + void onPlayerConnect(IPlayer& player) override { playerInit(player);