Skip to content

Commit

Permalink
added give ped scripted task event (#150)
Browse files Browse the repository at this point in the history
* added give ped scripted task event

* updated cpp-sdk
  • Loading branch information
KiwisKiwi authored Sep 19, 2023
1 parent aa7db53 commit 2f23b95
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/include/CSharpResourceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ typedef void (* ClientDeleteObjectDelegate_t)(const alt::CEvent* event, alt::IPl

typedef void (* PlayerHealDelegate_t)(alt::IPlayer* target, uint16_t oldHealth, uint16_t newHealth, uint16_t oldArmour, uint16_t newArmour);

typedef void (* GivePedScriptedTaskDelegate_t)(alt::IPlayer* source, alt::IPed* target, int32_t taskType);

class CSharpResourceImpl : public alt::IResource::Impl {
void OnEvent(const alt::CEvent* ev) override;

Expand Down Expand Up @@ -328,6 +330,8 @@ class CSharpResourceImpl : public alt::IResource::Impl {

PlayerHealDelegate_t OnPlayerHealDelegate = nullptr;

GivePedScriptedTaskDelegate_t OnGivePedScriptedTaskDelegate = nullptr;

std::vector<CustomInvoker*> invokers;
std::mutex invokersLock = {};
CoreClr* coreClr;
Expand Down Expand Up @@ -536,4 +540,6 @@ EXPORT void CSharpResourceImpl_SetClientRequestObjectDelegate(CSharpResourceImpl

EXPORT void CSharpResourceImpl_SetClientDeleteObjectDelegate(CSharpResourceImpl* resource, ClientDeleteObjectDelegate_t delegate);

EXPORT void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, PlayerHealDelegate_t delegate);
EXPORT void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, PlayerHealDelegate_t delegate);

EXPORT void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate);
21 changes: 21 additions & 0 deletions server/src/CSharpResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ void CSharpResourceImpl::ResetDelegates()
OnClientDeleteObjectDelegate = [](auto var, auto var2) {};

OnPlayerHealDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5) {};

OnGivePedScriptedTaskDelegate = [](auto var, auto var2, auto var3) {};
}

bool CSharpResourceImpl::Start()
Expand Down Expand Up @@ -743,6 +745,20 @@ case alt::CEvent::Type::SYNCED_META_CHANGE:
playerHealEvent->GetNewArmour());
break;
}
case alt::CEvent::Type::GIVE_PED_SCRIPTED_TASK:
{
auto givePedScriptedTaskEvent = dynamic_cast<const alt::CGivePedScriptedTaskEvent*>(ev);

auto target = givePedScriptedTaskEvent->GetTarget();
auto source = givePedScriptedTaskEvent->GetSource();

if (target == nullptr) return;
if (source == nullptr) return;

OnGivePedScriptedTaskDelegate(source, target, givePedScriptedTaskEvent->GetTaskType());

break;
}
default:
{
std::cout << "Unhandled server event #" << static_cast<int>(ev->GetType()) << " got called" << std::endl;
Expand Down Expand Up @@ -1253,6 +1269,11 @@ void CSharpResourceImpl_SetPlayerHealDelegate(CSharpResourceImpl* resource, Play
resource->OnPlayerHealDelegate = delegate;
}

void CSharpResourceImpl_SetGivePedScriptedTaskDelegate(CSharpResourceImpl* resource, GivePedScriptedTaskDelegate_t delegate)
{
resource->OnGivePedScriptedTaskDelegate = delegate;
}

bool CSharpResourceImpl::MakeClient(alt::IResource::CreationInfo* info, std::vector<std::string> files)
{
const std::string clientMain = resource->GetClientMain();
Expand Down

0 comments on commit 2f23b95

Please sign in to comment.