From 4a40a89e70ee3125d3484876d0977f6a3e230657 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sat, 16 Oct 2021 13:36:29 +0100 Subject: [PATCH 1/3] [Script] Add ufo and noclip function --- src/Components/Modules/Script.cpp | 22 ++++++++++++++++++++++ src/Game/Functions.hpp | 1 + 2 files changed, 23 insertions(+) diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index 72995ce6..c0213610 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -531,6 +531,28 @@ namespace Components { Script::ScriptStorage.clear(); }); + + Script::AddFunction("NoClip", [](Game::scr_entref_t entref) + { + if (entref >= Game::MAX_GENTITIES || Game::g_entities[entref].client == nullptr) + { + Game::Scr_Error(Utils::String::VA("^1NoClip: entity %u is not a client\n", entref)); + return; + } + + Game::g_entities[entref].client->flags ^= Game::PLAYER_FLAG_NOCLIP; + }); + + Script::AddFunction("Ufo", [](Game::scr_entref_t entref) + { + if (entref >= Game::MAX_GENTITIES || Game::g_entities[entref].client == nullptr) + { + Game::Scr_Error(Utils::String::VA("^1Ufo: entity %u is not a client\n", entref)); + return; + } + + Game::g_entities[entref].client->flags ^= Game::PLAYER_FLAG_UFO; + }); } Script::Script() diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 2569dbcf..984bf7c5 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -931,6 +931,7 @@ namespace Game extern int* demoRecording; extern int* serverMessageSequence; + constexpr auto MAX_GENTITIES = 2048; extern gentity_t* g_entities; extern netadr_t* connectedHost; From eda10589a1bb2a5c805e3fc97d992bff82237e14 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sat, 16 Oct 2021 13:51:57 +0100 Subject: [PATCH 2/3] [Script] Make MAX_GENTITIES unsigned --- src/Game/Functions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 984bf7c5..00318046 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -931,7 +931,7 @@ namespace Game extern int* demoRecording; extern int* serverMessageSequence; - constexpr auto MAX_GENTITIES = 2048; + constexpr auto MAX_GENTITIES = 2048u; extern gentity_t* g_entities; extern netadr_t* connectedHost; From 4d2356f824f057c8bb491e7967c0451deb251844 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sat, 16 Oct 2021 17:44:22 +0100 Subject: [PATCH 3/3] [Script] Add optional toggle parameter to ufo/noclip --- src/Components/Modules/Script.cpp | 34 ++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index c0213610..730be18e 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -532,7 +532,7 @@ namespace Components Script::ScriptStorage.clear(); }); - Script::AddFunction("NoClip", [](Game::scr_entref_t entref) + Script::AddFunction("Noclip", [](Game::scr_entref_t entref) { if (entref >= Game::MAX_GENTITIES || Game::g_entities[entref].client == nullptr) { @@ -540,7 +540,21 @@ namespace Components return; } - Game::g_entities[entref].client->flags ^= Game::PLAYER_FLAG_NOCLIP; + if (Game::Scr_GetNumParam() == 1 && Game::Scr_GetType(0) == Game::VAR_INTEGER) + { + if (Game::Scr_GetInt(0)) + { + Game::g_entities[entref].client->flags |= Game::PLAYER_FLAG_NOCLIP; + } + else + { + Game::g_entities[entref].client->flags &= ~Game::PLAYER_FLAG_NOCLIP; + } + } + else + { + Game::g_entities[entref].client->flags ^= Game::PLAYER_FLAG_NOCLIP; + } }); Script::AddFunction("Ufo", [](Game::scr_entref_t entref) @@ -551,7 +565,21 @@ namespace Components return; } - Game::g_entities[entref].client->flags ^= Game::PLAYER_FLAG_UFO; + if (Game::Scr_GetNumParam() == 1 && Game::Scr_GetType(0) == Game::VAR_INTEGER) + { + if (Game::Scr_GetInt(0)) + { + Game::g_entities[entref].client->flags |= Game::PLAYER_FLAG_UFO; + } + else + { + Game::g_entities[entref].client->flags &= ~Game::PLAYER_FLAG_UFO; + } + } + else + { + Game::g_entities[entref].client->flags ^= Game::PLAYER_FLAG_UFO; + } }); }