Skip to content

feat(citizen-server): add event listeners for routing bucket changes #3352

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <ServerInstanceBase.h>
#include <ServerInstanceBaseRef.h>
#include <state/ServerGameState.h>


#include <ResourceEventComponent.h>
#include <ResourceManager.h>
#include <ScriptEngine.h>
#include <ScriptDeprecations.h>
Expand Down Expand Up @@ -1600,7 +1601,8 @@ static void Init()
fx::ScriptEngine::RegisterNativeHandler("SET_PLAYER_ROUTING_BUCKET", MakeClientFunction([](fx::ScriptContext& context, const fx::ClientSharedPtr& client)
{
if (context.GetArgumentCount() > 1)
{
{
const char* player = context.GetArgument<char*>(0);
auto bucket = context.GetArgument<int>(1);

if (bucket >= 0)
Expand All @@ -1614,7 +1616,11 @@ static void Init()
// get the server's game state
auto gameState = instance->GetComponent<fx::ServerGameState>();

auto [lock, clientData] = gameState->ExternalGetClientData(client);
auto [lock, clientData] = gameState->ExternalGetClientData(client);

// store old bucket for event
const auto oldBucket = clientData->routingBucket;

gameState->ClearClientFromWorldGrid(client);
clientData->routingBucket = bucket;

Expand All @@ -1629,6 +1635,21 @@ static void Init()
{
playerEntity->routingBucket = bucket;
}


auto eventManager = resourceManager->GetComponent<fx::ResourceEventManagerComponent>();
/*NETEV onPlayerBucketChange SERVER
/#*
* Triggered when a routing bucket changed for a player on the server.
*
* @param player - The id of the player that changed bucket.
* @param bucket - The new bucket that is placing the player into.
* @param oldBucket - The old bucket where the player was previously in.
*
#/
declare function onPlayerBucketChange(player: string, bucket: int, oldBucket: int): void;
*/
eventManager->TriggerEvent2("onPlayerBucketChange", {}, player, bucket, oldBucket);
}
}

Expand All @@ -1644,12 +1665,29 @@ static void Init()
{
if (context.GetArgumentCount() > 1)
{
char* ent = context.GetArgument<char*>(0);
auto bucket = context.GetArgument<int>(1);
int oldBucket = entity->routingBucket;

if (bucket >= 0)
{
entity->routingBucket = bucket;
}

auto resourceManager = fx::ResourceManager::GetCurrent();
auto eventManager = resourceManager->GetComponent<fx::ResourceEventManagerComponent>();
/*NETEV onEntityBucketChange SERVER
/#*
* Triggered when a routing bucket changed for an entity on the server.
*
* @param entity - The entity id that changed bucket.
* @param bucket - The new bucket that is placing the entity into.
* @param oldBucket - The old bucket where the entity was previously in.
*
#/
declare function onEntityBucketChange(entity: string, bucket: int, oldBucket: int): void;
*/
eventManager->TriggerEvent2("onEntityBucketChange", {}, ent, bucket, oldBucket);
}

return true;
Expand Down
Loading