Skip to content

Commit

Permalink
Merge branch 'main' into tutorial-natives
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm authored Oct 31, 2024
2 parents e2e5810 + 52232c4 commit d0a28d8
Show file tree
Hide file tree
Showing 52 changed files with 1,935 additions and 1,409 deletions.
21 changes: 12 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
root = true

[*]
end_of_line = lf
insert_final_newline = false
indent_style = space
charset = utf-8
trim_trailing_whitespace = true
indent_size = 4
root = true

[*]
end_of_line = lf
insert_final_newline = false
indent_style = space
charset = utf-8
trim_trailing_whitespace = true
indent_size = 4

[*.{sql,html,css,json,js,ts,jsx,tsx}]
indent_size = 2
7 changes: 4 additions & 3 deletions .github/actions/bump-manifest-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ const newVersion = version.replace('v', '')

const manifestFile = fs.readFileSync('fxmanifest.lua', {encoding: 'utf8'})

let newFileContent = manifestFile.replace(/\bversion\s+(.*)$/gm, `version '${newVersion}'`)
const versionStr = `version '${newVersion}'`
let newFileContent = manifestFile.replace(/\bversion\s+(.*)$/gm, versionStr)

if (newFileContent == manifestFile) {
newFileContent = manifestFile.replace(/\bgame\s+(.*)$/gm, `game 'gta5'\nversion '${newVersion}'`);
if (!newFileContent.includes(versionStr)) {
newFileContent = manifestFile.replace(/\bgame\s+(.*)$/gm, `game 'gta5'\n${versionStr}`);
}

fs.writeFileSync('fxmanifest.lua', newFileContent)
2 changes: 1 addition & 1 deletion .github/workflows/discord-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Github Releases To Discord
uses: SethCohen/github-releases-to-discord@v1.15.0
uses: SethCohen/github-releases-to-discord@v1.16.2
with:
webhook_url: ${{ secrets.WEBHOOK_URL }}
color: "15852866"
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: Lint
on: [push, pull_request_target]
on:
push:
paths:
- '**.lua'
- '.github/workflows/lint.yml'
pull_request_target:
paths:
- '**.lua'
- '.github/workflows/lint.yml'
jobs:
lint:
name: Lint Resource
Expand Down
25 changes: 20 additions & 5 deletions .github/workflows/release-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,25 @@ jobs:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1
continue-on-error: true
with:
token: ${{ steps.generate_token.outputs.token }}
tag: ${{ github.ref_name }}
includeInvalidCommits: true
useGitmojis: false
writeToFile: false

- name: Create Release
uses: marvinpinto/action-automatic-releases@latest
uses: ncipollo/[email protected]
with:
title: ${{ github.ref_name }}
repo_token: '${{ steps.generate_token.outputs.token }}'
prerelease: false
files: ${{ github.event.repository.name }}.zip
allowUpdates: true
draft: false
makeLatest: true
name: ${{ github.ref_name }}
tag: ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changes }}
artifacts: ${{ github.event.repository.name }}.zip
token: ${{ steps.generate_token.outputs.token }}
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,4 @@ jobs:
add: fxmanifest.lua
push: true
message: 'chore: bump manifest version to ${{ inputs.version }}'

- name: Push Git Tag
run: |
git tag ${{ inputs.version }}
git push origin ${{ inputs.version }}
tag: ${{ inputs.version }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.idea
.vscode/*
!.vscode/extensions.json
!.vscode/settings.json
!.vscode/settings.json
.DS_Store
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"Lua.diagnostics.globals": [
"lib",
"cache",
"QBX",
"locale",
"MySQL",
"QBX",
"qbx"
]
}
2 changes: 1 addition & 1 deletion bridge/qb/client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end)
RegisterNetEvent('QBCore:Client:VehicleInfo', function(info)
local vehicle = NetworkGetEntityFromNetworkId(info.netId)
local plate = qbx.getVehiclePlate(vehicle)
local hasKeys = config.hasKeys()
local hasKeys = config.hasKeys(plate, vehicle)

local data = {
vehicle = vehicle,
Expand Down
2 changes: 1 addition & 1 deletion bridge/qb/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function functions.SetVehicleProperties(vehicle, props)
props.modRoofLivery = props.modRoofLivery or props.liveryRoof

--- lib.setVehicleProperties copied and pasted from Overextended below so that we can remove the error so that setting properties is best effort
assert(DoesEntityExist(vehicle), string.format('Unable to set vehicle properties for "%s" (entity does not exist)', vehicle))
assert(DoesEntityExist(vehicle), ('Unable to set vehicle properties for "%s" (entity does not exist)'):format(vehicle))

if NetworkGetEntityIsNetworked(vehicle) and NetworkGetEntityOwner(vehicle) ~= cache.playerId then
lib.print.warn('setting vehicle properties on non entity owner client. This may cause certain properties to fail to set. entity:', vehicle)
Expand Down
2 changes: 2 additions & 0 deletions bridge/qb/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ qbCoreCompat.Shared.Jobs = GetJobs()
qbCoreCompat.Shared.Gangs = GetGangs()
qbCoreCompat.Functions = require 'bridge.qb.client.functions'

---@diagnostic disable: deprecated

---@deprecated use https://overextended.github.io/docs/ox_lib/Callback/Lua/Client/ instead
qbCoreCompat.ClientCallbacks = {}

Expand Down
34 changes: 28 additions & 6 deletions bridge/qb/server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ require 'server.functions'
require 'bridge.qb.server.player'
local functions = {}

local allowMethodOverrides = GetConvar('qbx:allowmethodoverrides', 'true') == 'true'
local disableMethodOverrideWarning = GetConvar('qbx:disableoverridewarning', 'false') == 'true'

local createQbExport = require 'bridge.qb.shared.export-function'

---@deprecated use the GetEntityCoords and GetEntityHeading natives directly
Expand Down Expand Up @@ -34,7 +37,7 @@ function functions.SpawnVehicle(source, model, coords, warp)
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, true)
while not DoesEntityExist(veh) do Wait(0) end
if warp then
while GetVehiclePedIsIn(ped) ~= veh do
while GetVehiclePedIsIn(ped, false) ~= veh do
Wait(0)
TaskWarpPedIntoVehicle(ped, veh, -1)
end
Expand Down Expand Up @@ -391,6 +394,18 @@ functions.RemoveGang = function(gangName)
end
createQbExport('RemoveGang', RemoveGang)

local function checkExistingMethod(method, methodName)
local methodType = type(method)
if methodType == 'function' then
local warnMessage = allowMethodOverrides and 'A resource is overriding method %s in player class. This can cause unexpected behavior. Disable this warning by setting convar qbx:disableoverridewarning to true' or 'A resource attempted to override method %s in player object and was blocked. Disable this warning by setting convar qbx:disableoverridewarning to true'
if not disableMethodOverrideWarning then
lib.print.warn(warnMessage:format(methodName))
end
return allowMethodOverrides
end
return true
end

---Add a new function to the Functions table of the player class
---Use-case:
-- [[
Expand All @@ -409,15 +424,19 @@ function functions.AddPlayerMethod(ids, methodName, handler)
if idType == 'number' then
if ids == -1 then
for _, v in pairs(QBX.Players) do
v.Functions[methodName] = handler
if checkExistingMethod(v.Functions[methodName], methodName) then
v.Functions[methodName] = handler
end
end
else
if not QBX.Players[ids] then return end

QBX.Players[ids].Functions[methodName] = handler
if checkExistingMethod(QBX.Players[ids].Functions[methodName], methodName) then
QBX.Players[ids].Functions[methodName] = handler
end
end
elseif idType == 'table' and table.type(ids) == 'array' then
for i = 1, #ids do
---@diagnostic disable-next-line: deprecated
functions.AddPlayerMethod(ids[i], methodName, handler)
end
end
Expand All @@ -439,15 +458,18 @@ function functions.AddPlayerField(ids, fieldName, data)
if idType == 'number' then
if ids == -1 then
for _, v in pairs(QBX.Players) do
---@diagnostic disable-next-line: undefined-field
v.Functions.AddField(fieldName, data)
end
else
if not QBX.Players[ids] then return end

---@diagnostic disable-next-line: undefined-field
QBX.Players[ids].Functions.AddField(fieldName, data)
end
elseif idType == 'table' and table.type(ids) == 'array' then
for i = 1, #ids do
---@diagnostic disable-next-line: deprecated
functions.AddPlayerField(ids[i], fieldName, data)
end
end
Expand Down Expand Up @@ -502,7 +524,7 @@ function functions.GetSource(identifier)
end

---@param source Source|string source or identifier of the player
---@return Player
---@return Player?
function functions.GetPlayer(source)
return AddDeprecatedFunctions(exports.qbx_core:GetPlayer(source))
end
Expand Down Expand Up @@ -669,4 +691,4 @@ function functions.GetCoreVersion(InvokingResource)
return exports.qbx_core:GetCoreVersion(InvokingResource)
end

return functions
return functions
3 changes: 3 additions & 0 deletions bridge/qb/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require 'bridge.qb.server.events'
local convertItems = require 'bridge.qb.shared.compat'.convertItems
convertItems(require '@ox_inventory.data.items', require 'shared.items')

---@diagnostic disable-next-line: lowercase-global
qbCoreCompat = {}

qbCoreCompat.Config = lib.table.merge(require 'config.server', require 'config.shared')
Expand All @@ -20,6 +21,8 @@ qbCoreCompat.UsableItems = QBX.UsableItems
qbCoreCompat.Functions = require 'bridge.qb.server.functions'
qbCoreCompat.Commands = require 'bridge.qb.server.commands'

---@diagnostic disable: deprecated

---@deprecated Call lib.print.debug() instead
qbCoreCompat.Debug = lib.print.debug

Expand Down
4 changes: 2 additions & 2 deletions bridge/qb/server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ end
---Will cause major issues!
---@param playerData PlayerData
---@param Offline boolean
---@return Player player
---@return Player?
function playerObj.CreatePlayer(playerData, Offline)
AddDeprecatedFunctions(exports.qbx_core:CreatePlayer(playerData, Offline))
return AddDeprecatedFunctions(exports.qbx_core:CreatePlayer(playerData, Offline))
end

---Save player info to database (make sure citizenid is the primary key in your database)
Expand Down
6 changes: 6 additions & 0 deletions bridge/qb/shared/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ qbShared.StarterItems = {}
if type(starterItems) == 'table' then
for i = 1, #starterItems do
local item = starterItems[i]

---@diagnostic disable-next-line: deprecated
qbShared.StarterItems[item.name] = {
amount = item.amount,
item = item.name,
Expand All @@ -85,12 +87,16 @@ qbShared.CommaValue = lib.math.groupdigits
qbShared.RandomStr = function(length)
if length <= 0 then return '' end
local pattern = math.random(2) == 1 and 'a' or 'A'

---@diagnostic disable-next-line: deprecated
return qbShared.RandomStr(length - 1) .. lib.string.random(pattern)
end

---@deprecated use lib.string.random from ox_lib
qbShared.RandomInt = function(length)
if length <= 0 then return '' end

---@diagnostic disable-next-line: deprecated
return qbShared.RandomInt(length - 1) .. lib.string.random('1')
end

Expand Down
6 changes: 4 additions & 2 deletions client/character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ local randomPeds = {
local nationalities = {}

if config.characters.limitNationalities then
local nationalityList = lib.load('data.nationalities')

CreateThread(function()
for i = 1, #config.characters.nationalities do
nationalities[#nationalities + 1] = {value = config.characters.nationalities[i]}
for i = 1, #nationalityList do
nationalities[#nationalities + 1] = { value = nationalityList[i] }
end
end)
end
Expand Down
10 changes: 9 additions & 1 deletion client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
SetCanAttackFriendly(cache.ped, true, false)
NetworkSetFriendlyFireOption(true)
end

if NetworkIsInTutorialSession() then NetworkEndTutorialSession() end

local motd = GetConvar('qbx:motd', '')
if motd ~= '' then
exports.chat:addMessage({ template = motd })
end
end)

---@param val PlayerData
RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
local invokingResource = GetInvokingResource()
if invokingResource and invokingResource ~= GetCurrentResourceName() then return end
if invokingResource and invokingResource ~= cache.resource then return end
QBX.PlayerData = val
end)

Expand All @@ -22,6 +28,7 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
end)

---@param value boolean
---@diagnostic disable-next-line: param-type-mismatch
AddStateBagChangeHandler('PVPEnabled', nil, function(bagName, _, value)
if bagName == 'global' then
SetCanAttackFriendly(cache.ped, value, false)
Expand Down Expand Up @@ -151,6 +158,7 @@ end)

---@param bagName string
---@param value string
---@diagnostic disable-next-line: param-type-mismatch
AddStateBagChangeHandler('me', nil, function(bagName, _, value)
if not value then return end

Expand Down
16 changes: 15 additions & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
QBX = {}

---@diagnostic disable-next-line: missing-fields
QBX.PlayerData = {}
QBX.Shared = require 'shared.main'
QBX.IsLoggedIn = false
Expand Down Expand Up @@ -37,6 +39,7 @@ function GetLocations()
return QBX.Shared.Locations
end

---@diagnostic disable-next-line: deprecated
exports('GetLocations', GetLocations)

AddStateBagChangeHandler('isLoggedIn', ('player:%s'):format(cache.serverId), function(_, _, value)
Expand All @@ -61,5 +64,16 @@ CreateThread(function()
lib.print.warn('Could not find gameName value in vehicles.meta for vehicle model %s', v.model)
end
end
end
end
end)

lib.callback.register('qbx_core:client:getVehicleClasses', function()
local models = GetAllVehicleModels()
local classes = {}
for i = 1, #models do
local model = models[i]
local class = GetVehicleClassFromName(model)
classes[joaat(model)] = class
end
return classes
end)
Loading

0 comments on commit d0a28d8

Please sign in to comment.