fix(vehicle): set metadata state for vehicle if non-existent

- Added debug print for when metadata is storage is skipped
This commit is contained in:
NotSomething0
2024-05-11 14:54:57 -05:00
parent 5d3c051149
commit e0c4a8419b

View File

@@ -156,13 +156,22 @@ function NDCore.getVehicle(entity)
function self.setMetadata(key, value) function self.setMetadata(key, value)
self.metadata[key] = value self.metadata[key] = value
if DoesEntityExist(entity) then if DoesEntityExist(entity) then
local state = Entity(self.entity).state local state = Entity(self.entity).state
local metadata = state.metadata
metadata[key] = value if not state.metadata then
state.metadata = metadata state.metadata = self.metadata
else
state.metadata[key] = value
end
end end
if not self.id or not self.owner then return end
if not self.id or not self.owner then
lib.print.debug(('Skipped storing metadata for vehicle %s as it does not have an id/owner associated with it.'):format(self.entity))
return
end
MySQL.query("UPDATE nd_vehicles SET metadata = ? WHERE id = ?", {json.encode(self.metadata), self.id}) MySQL.query("UPDATE nd_vehicles SET metadata = ? WHERE id = ?", {json.encode(self.metadata), self.id})
end end