[OneSync] playerEnteredScope and playerLeftScope events

Yesterday, FiveM introduced two new events for OneSync Infinity in the (2437+) server build. As you may have noticed players are only loading closest players and entities. These events allow you to know from the server who entered, who left a player’s scope.

playerEnteredScope

Triggered when a player enters another player’s scope.

playerLeftScope

Triggered when a player leaves another player’s scope.

Examples

AddEventHandler("playerEnteredScope", function(data)
    local playerEntering, player = data["player"], data["for"]
    print(("%s is entering %s's scope"):format(playerEntering, player))
end)

AddEventHandler("playerLeftScope", function(data)
    local playerLeaving, player = data["player"], data["for"]
    print(("%s is leaving %s's scope"):format(playerLeaving, player))
end)

This can be very useful to target players in a specific area or to avoid sending an event to all players.

5 Likes

Example of some util function for your gamemode like TriggerScopeEvent or GetPlayerScope

1 Like

Hello thanks for sharing, saw the commit yesterday and wanted to test.

In terms of performances, is this better to use :

  1. a setup function as your exemple : TriggerScopeEvent ?

Or

  1. Get all server id of players nearby using GetActivePlayers() client side and then send them to the server so it only send to all clients nearby ?

Thanks :upside_down_face:

Awesome! I recent found it and its so useful

1 and first safe