Skip to content

Commit

Permalink
fix(client): Fix getByScriptId crashing the client
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Dec 20, 2023
1 parent 2340530 commit 037bfc5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion client/src/classes/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ static void GetByScriptID(js::FunctionContext& ctx)
uint32_t scriptId;
if(!ctx.GetArg(0, scriptId)) return;

if (auto obj = alt::ICore::Instance().GetWorldObjectByScriptID(scriptId); obj->GetType() == alt::IBaseObject::Type::OBJECT)
auto obj = alt::ICore::Instance().GetWorldObjectByScriptID(scriptId);
if (obj && (obj->GetType() == alt::IBaseObject::Type::OBJECT || obj->GetType() == alt::IBaseObject::Type::LOCAL_OBJECT))
return ctx.Return(obj);

ctx.Return(nullptr);
Expand Down
2 changes: 1 addition & 1 deletion client/src/classes/Ped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static void GetByScriptID(js::FunctionContext& ctx)
if(!ctx.GetArg(0, scriptId)) return;

auto obj = alt::ICore::Instance().GetWorldObjectByScriptID(scriptId);
if (obj->GetType() == alt::IBaseObject::Type::PED || obj->GetType() == alt::IBaseObject::Type::LOCAL_PED)
if (obj && (obj->GetType() == alt::IBaseObject::Type::PED || obj->GetType() == alt::IBaseObject::Type::LOCAL_PED))
return ctx.Return(obj);

ctx.Return(nullptr);
Expand Down
2 changes: 1 addition & 1 deletion client/src/classes/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void GetByScriptID(js::FunctionContext& ctx)
if(!ctx.GetArg(0, scriptId)) return;

auto obj = alt::ICore::Instance().GetWorldObjectByScriptID(scriptId);
if (obj->GetType() == alt::IBaseObject::Type::VEHICLE || obj->GetType() == alt::IBaseObject::Type::LOCAL_VEHICLE)
if (obj && (obj->GetType() == alt::IBaseObject::Type::VEHICLE || obj->GetType() == alt::IBaseObject::Type::LOCAL_VEHICLE))
return ctx.Return(obj);

ctx.Return(nullptr);
Expand Down

0 comments on commit 037bfc5

Please sign in to comment.