Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vehicle's callbacks (OnVehicleTrailerAttach & OnVehicleTrailerDetach) #1014

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SDK
20 changes: 20 additions & 0 deletions Server/Components/Pawn/Scripting/Vehicle/Events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,24 @@ struct VehicleEvents : public VehicleEventHandler, public Singleton<VehicleEvent
}
return !!ret;
}

bool onVehicleTrailerAttach(IPlayer& player, IVehicle& vehicle, IVehicle& trailer) override
{
cell ret = PawnManager::Get()->CallInSides("OnVehicleTrailerAttach", DefaultReturnValue_False, player.getID(), vehicle.getID(), trailer.getID());
if (!ret)
{
ret = PawnManager::Get()->CallInEntry("OnVehicleTrailerAttach", DefaultReturnValue_True, player.getID(), vehicle.getID(), trailer.getID());
}
return !!ret;
}

bool onVehicleTrailerDetach(IPlayer& player, IVehicle& vehicle, IVehicle& trailer) override
{
cell ret = PawnManager::Get()->CallInSides("OnVehicleTrailerDetach", DefaultReturnValue_False, player.getID(), vehicle.getID(), trailer.getID());
if (!ret)
{
ret = PawnManager::Get()->CallInEntry("OnVehicleTrailerDetach", DefaultReturnValue_True, player.getID(), vehicle.getID(), trailer.getID());
}
return !!ret;
}
};
10 changes: 10 additions & 0 deletions Server/Components/TestComponent/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ struct TestComponent : public IComponent, public PlayerDamageEventHandler, publi
player.sendClientMessage(Colour::White(), "onVehicleSirenStateChange(" + std::to_string(player.getID()) + ", " + std::to_string(vehicle.getID()) + ", " + std::to_string((int)sirenState) + ")");
return true;
}
bool onVehicleTrailerAttach(IPlayer& player, IVehicle& vehicle, IVehicle& trailer) override
{
player.sendClientMessage(Colour::White(), "onVehicleTrailerAttach(" + std::to_string(player.getID()) + ", " + std::to_string(vehicle.getID()) + ", " + std::to_string(vehicle.getTrailer()->getID()) + ")");
return true;
}
bool onVehicleTrailerDetach(IPlayer& player, IVehicle& vehicle, IVehicle& trailer) override
{
player.sendClientMessage(Colour::White(), "onVehicleTrailerDetach(" + std::to_string(player.getID()) + ", " + std::to_string(vehicle.getID()) + ", " + std::to_string(vehicle.getTrailer()->getID()) + ")");
return true;
}
} vehicleEventWatcher;

void onPlayerConnect(IPlayer& player) override
Expand Down
10 changes: 10 additions & 0 deletions Server/Components/Vehicles/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ bool Vehicle::updateFromDriverSync(const VehicleDriverSyncPacket& vehicleSync, I
else
{
trailer->cab = this;

static_cast<DefaultEventDispatcher<VehicleEventHandler>&>(pool->getEventDispatcher()).stopAtFalse([&player, this](VehicleEventHandler* handler)
{
return handler->onVehicleTrailerAttach(player, *this, *trailer);
});
}
}
}
Expand All @@ -253,6 +258,11 @@ bool Vehicle::updateFromDriverSync(const VehicleDriverSyncPacket& vehicleSync, I
// Client is reporting no trailer (probably lost it) but server thinks there's still one. Detaching it server side.
if (trailer && Time::now() - trailer->trailerUpdateTime > Seconds(0))
{
static_cast<DefaultEventDispatcher<VehicleEventHandler>&>(pool->getEventDispatcher()).stopAtFalse([&player, this](VehicleEventHandler* handler)
{
return handler->onVehicleTrailerDetach(player, *this, *trailer);
});

trailer->cab = nullptr;
trailer = nullptr;
}
Expand Down