diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 9c1ce9981c7..59139e060ef 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -2484,16 +2484,25 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed) return pPed->ExitVehicle(); } -bool CLuaPedDefs::killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept +bool CLuaPedDefs::killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional gracefully) { switch (taskType) { case taskType::PRIMARY_TASK: { + if (taskNumber == TASK_PRIORITY_DEFAULT) + throw LuaFunctionError("Killing TASK_PRIORITY_DEFAULT is not allowed"); + + if (taskNumber >= TASK_PRIORITY_MAX) + throw LuaFunctionError("Invalid task slot number"); + return ped->KillTask(taskNumber, gracefully.value_or(true)); } case taskType::SECONDARY_TASK: { + if (taskNumber >= TASK_SECONDARY_MAX) + throw LuaFunctionError("Invalid task slot number"); + return ped->KillTaskSecondary(taskNumber, gracefully.value_or(true)); } default: diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 1b4881b0838..f384c4103ad 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -116,8 +116,8 @@ 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, taskType taskType, std::uint8_t taskNumber, std::optional gracefully) noexcept; + + static bool killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional gracefully); static void PlayPedVoiceLine(CClientPed* ped, int speechId, std::optional probabilty); };