Skip to content

Commit

Permalink
fix: make calling createSessionId for the same entity return the same…
Browse files Browse the repository at this point in the history
… id (#587)

* fix: make calling createSessionId for the same entity return the same id rather than overwrite

* fix comment
  • Loading branch information
Manason authored Sep 28, 2024
1 parent 1964436 commit f889ceb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ local vehicleClassesPromise
local currentSessionId = 0

---Sets a unique sessionId statebag on the entity.
---If the entity already has a sessionId, this will return it rather than overwrite.
---@param entity number
---@return integer sessionId
local function createSessionId(entity)
local existingSessionId = Entity(entity).state.sessionId
if existingSessionId then
return existingSessionId
end
currentSessionId += 1
local sessionId = currentSessionId
Entity(entity).state:set('sessionId', sessionId, true)
Expand Down

0 comments on commit f889ceb

Please sign in to comment.