From e4d3ca96bc97cc51983ee11fd641b93eccf5e2f2 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Wed, 16 Oct 2024 21:57:21 +0300 Subject: [PATCH 1/7] killTask --- .../mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 15 +++++++++++++++ .../mods/deathmatch/logic/luadefs/CLuaPedDefs.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index f38096dceea..0378f2fddc9 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -115,6 +115,7 @@ void CLuaPedDefs::LoadFunctions() {"isPedDucked", IsPedDucked}, {"isPedDead", IsPedDead}, {"isPedReloadingWeapon", IsPedReloadingWeapon}, + {"killPedTask", ArgumentParser}, }; // Add functions @@ -2493,3 +2494,17 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) { return pPed->ExitVehicle(); } + +bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, uint8_t taskNumber, bool gracefully) +{ + + if (taskType == "primary") // PRIMARY + { + return ped->KillTask(taskNumber, gracefully); + } + else if (taskType == "secondary") // SECONDARY + { + return ped->KillTaskSecondary(taskNumber, gracefully); + } + +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index d97a484d8e1..b071970161d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -115,4 +115,6 @@ class CLuaPedDefs : public CLuaDefs static bool SetPedExitVehicle(CClientPed* pPed); static bool IsPedBleeding(CClientPed* ped); static bool SetPedBleeding(CClientPed* ped, bool bleeding); + + static bool killPedTask(CClientPed* ped, std::string taskType, uint8_t taskNumber, bool gracefully); }; From a3521c615fc7c09a4007cbfe8bc9d932854a5339 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:02:42 +0300 Subject: [PATCH 2/7] space --- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 0378f2fddc9..4d94c489a63 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2497,14 +2497,12 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, uint8_t taskNumber, bool gracefully) { - if (taskType == "primary") // PRIMARY { return ped->KillTask(taskNumber, gracefully); } - else if (taskType == "secondary") // SECONDARY + else if (taskType == "secondary") // SECONDARY { return ped->KillTaskSecondary(taskNumber, gracefully); } - } From df9b421c46844276212b486280481b4a1169d941 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:16:00 +0300 Subject: [PATCH 3/7] review --- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 4 +++- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 4d94c489a63..40d3f4b4e15 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2495,7 +2495,7 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) return pPed->ExitVehicle(); } -bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, uint8_t taskNumber, bool gracefully) +bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, bool gracefully) noexcept { if (taskType == "primary") // PRIMARY { @@ -2505,4 +2505,6 @@ bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, uint8_t tas { return ped->KillTaskSecondary(taskNumber, gracefully); } + + return false; } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index b071970161d..687596b196b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -116,5 +116,5 @@ class CLuaPedDefs : public CLuaDefs static bool IsPedBleeding(CClientPed* ped); static bool SetPedBleeding(CClientPed* ped, bool bleeding); - static bool killPedTask(CClientPed* ped, std::string taskType, uint8_t taskNumber, bool gracefully); + static bool killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, bool gracefully) noexcept; }; From b6153582c09a57e629180151cec234161bf1ef1e Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:33:25 +0300 Subject: [PATCH 4/7] add optional to last arg --- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 6 +++--- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 40d3f4b4e15..c5d69bbc89b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2495,15 +2495,15 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) return pPed->ExitVehicle(); } -bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, bool gracefully) noexcept +bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept { if (taskType == "primary") // PRIMARY { - return ped->KillTask(taskNumber, gracefully); + return ped->KillTask(taskNumber, gracefully.value_or(true)); } else if (taskType == "secondary") // SECONDARY { - return ped->KillTaskSecondary(taskNumber, gracefully); + return ped->KillTaskSecondary(taskNumber, gracefully.value_or(true)); } return false; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 687596b196b..107888cee9e 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -116,5 +116,5 @@ class CLuaPedDefs : public CLuaDefs static bool IsPedBleeding(CClientPed* ped); static bool SetPedBleeding(CClientPed* ped, bool bleeding); - static bool killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, bool gracefully) noexcept; + static bool killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept; }; From 4e53350ccfeb4a620b62f56aa00fbd3b497d20b2 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:35:21 +0300 Subject: [PATCH 5/7] remove braces --- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index c5d69bbc89b..52e9673fff0 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2498,13 +2498,10 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept { if (taskType == "primary") // PRIMARY - { return ped->KillTask(taskNumber, gracefully.value_or(true)); - } + else if (taskType == "secondary") // SECONDARY - { return ped->KillTaskSecondary(taskNumber, gracefully.value_or(true)); - } return false; } From 88ff29e30106bb5e816ab5ba1404159fb0f0ff24 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Sat, 19 Oct 2024 01:36:11 +0300 Subject: [PATCH 6/7] better type --- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp | 2 +- Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 52e9673fff0..b8d87b0913c 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2495,7 +2495,7 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) return pPed->ExitVehicle(); } -bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept +bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string_view taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept { if (taskType == "primary") // PRIMARY return ped->KillTask(taskNumber, gracefully.value_or(true)); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 107888cee9e..2ff0fbbb19d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -116,5 +116,5 @@ class CLuaPedDefs : public CLuaDefs static bool IsPedBleeding(CClientPed* ped); static bool SetPedBleeding(CClientPed* ped, bool bleeding); - static bool killPedTask(CClientPed* ped, std::string taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept; + static bool killPedTask(CClientPed* ped, std::string_view taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept; }; From 65bb7bfab722d34e497fafc5b280f3cde1c81e34 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Sat, 26 Oct 2024 19:52:34 +0300 Subject: [PATCH 7/7] use enum --- .../logic/lua/CLuaFunctionParseHelpers.cpp | 5 +++++ .../logic/lua/CLuaFunctionParseHelpers.h | 1 + .../deathmatch/logic/luadefs/CLuaPedDefs.cpp | 22 ++++++++++++------- .../deathmatch/logic/luadefs/CLuaPedDefs.h | 2 +- Client/sdk/game/CTaskManager.h | 7 ++++++ 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp index 64708dea0ca..230a85733e9 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp @@ -910,6 +910,11 @@ ADD_ENUM(PreloadAreaOption::COLLISIONS, "collisions") ADD_ENUM(PreloadAreaOption::ALL, "all") IMPLEMENT_ENUM_CLASS_END("preload-area-option") +IMPLEMENT_ENUM_CLASS_BEGIN(taskType) +ADD_ENUM(taskType::PRIMARY_TASK, "primary") +ADD_ENUM(taskType::SECONDARY_TASK, "secondary") +IMPLEMENT_ENUM_CLASS_END("tasks-types") + // // CResource from userdata // diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h index e134a73bea9..210a3e7eead 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h @@ -88,6 +88,7 @@ DECLARE_ENUM(ePools); DECLARE_ENUM(eWorldProperty); DECLARE_ENUM_CLASS(eModelLoadState); DECLARE_ENUM_CLASS(PreloadAreaOption); +DECLARE_ENUM_CLASS(taskType); class CRemoteCall; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index b8d87b0913c..6caf2456180 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2495,13 +2495,19 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) return pPed->ExitVehicle(); } -bool CLuaPedDefs::killPedTask(CClientPed* ped, std::string_view taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept +bool CLuaPedDefs::killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept { - if (taskType == "primary") // PRIMARY - return ped->KillTask(taskNumber, gracefully.value_or(true)); - - else if (taskType == "secondary") // SECONDARY - return ped->KillTaskSecondary(taskNumber, gracefully.value_or(true)); - - return false; + switch (taskType) + { + case taskType::PRIMARY_TASK: + { + return ped->KillTask(taskNumber, gracefully.value_or(true)); + } + case taskType::SECONDARY_TASK: + { + return ped->KillTaskSecondary(taskNumber, gracefully.value_or(true)); + } + default: + return false; + } } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 2ff0fbbb19d..76b97713325 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -116,5 +116,5 @@ class CLuaPedDefs : public CLuaDefs static bool IsPedBleeding(CClientPed* ped); static bool SetPedBleeding(CClientPed* ped, bool bleeding); - static bool killPedTask(CClientPed* ped, std::string_view taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept; + static bool killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept; }; diff --git a/Client/sdk/game/CTaskManager.h b/Client/sdk/game/CTaskManager.h index 3467f349281..f89d145dd4c 100644 --- a/Client/sdk/game/CTaskManager.h +++ b/Client/sdk/game/CTaskManager.h @@ -41,6 +41,13 @@ enum ABORT_PRIORITY_IMMEDIATE }; +enum taskType +{ + PRIMARY_TASK = 0, + SECONDARY_TASK +}; + + class CTaskManager { public: