Skip to content

Commit c1e6be1

Browse files
authored
Fix killPedTask crash (PR #4045)
1 parent 7067ac1 commit c1e6be1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,16 +2484,25 @@ bool CLuaPedDefs::SetPedExitVehicle(CClientPed* pPed)
24842484
return pPed->ExitVehicle();
24852485
}
24862486

2487-
bool CLuaPedDefs::killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional<bool> gracefully) noexcept
2487+
bool CLuaPedDefs::killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional<bool> gracefully)
24882488
{
24892489
switch (taskType)
24902490
{
24912491
case taskType::PRIMARY_TASK:
24922492
{
2493+
if (taskNumber == TASK_PRIORITY_DEFAULT)
2494+
throw LuaFunctionError("Killing TASK_PRIORITY_DEFAULT is not allowed");
2495+
2496+
if (taskNumber >= TASK_PRIORITY_MAX)
2497+
throw LuaFunctionError("Invalid task slot number");
2498+
24932499
return ped->KillTask(taskNumber, gracefully.value_or(true));
24942500
}
24952501
case taskType::SECONDARY_TASK:
24962502
{
2503+
if (taskNumber >= TASK_SECONDARY_MAX)
2504+
throw LuaFunctionError("Invalid task slot number");
2505+
24972506
return ped->KillTaskSecondary(taskNumber, gracefully.value_or(true));
24982507
}
24992508
default:

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ class CLuaPedDefs : public CLuaDefs
116116
static bool SetPedExitVehicle(CClientPed* pPed);
117117
static bool IsPedBleeding(CClientPed* ped);
118118
static bool SetPedBleeding(CClientPed* ped, bool bleeding);
119-
120-
static bool killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional<bool> gracefully) noexcept;
119+
120+
static bool killPedTask(CClientPed* ped, taskType taskType, std::uint8_t taskNumber, std::optional<bool> gracefully);
121121

122122
static void PlayPedVoiceLine(CClientPed* ped, int speechId, std::optional<float> probabilty);
123123
};

0 commit comments

Comments
 (0)