Skip to content

Commit

Permalink
Merge pull request #34 from mafewtm/main
Browse files Browse the repository at this point in the history
refactor: readability and formatting consistancy
  • Loading branch information
darktrovx authored Aug 24, 2024
2 parents 30441b2 + 640fc62 commit c9793b7
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 95 deletions.
5 changes: 2 additions & 3 deletions bridge/esx/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ end)

RegisterNetEvent('esx:onPlayerLogout', function()
Player = table.wipe(Player)
TriggerEvent('interact:groupsChanged', {})
end)

return Bridge
TriggerEvent('interact:groupsChanged', {})
end)
1 change: 1 addition & 0 deletions bridge/ox/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ end)

AddEventHandler('ox:playerLogout', function()
table.wipe(Player)

TriggerEvent('interact:groupsChanged', {})
end)

Expand Down
5 changes: 3 additions & 2 deletions bridge/qb/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ end)

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
local PlayerData = QBCore.Functions.GetPlayerData()

Player = {
Group = {
[PlayerData.job.name] = PlayerData.job.grade.level,
Expand All @@ -38,6 +39,6 @@ end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
Player = table.wipe(Player)
TriggerEvent('interact:groupsChanged', {})
end)

TriggerEvent('interact:groupsChanged', {})
end)
7 changes: 2 additions & 5 deletions client/defaults.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
if GetConvar('interact_disabledefault', 'false') == 'true' then
return
end
if GetConvar('interact_disabledefault', 'false') == 'true' then return end

local api = require 'client.interactions'

Expand All @@ -23,12 +21,11 @@ api.addGlobalVehicleInteraction({
end

local plate = GetVehicleNumberPlateText(entity)
local invId = 'trunk'..plate
local coords = GetEntityCoords(entity)

TaskTurnPedToFaceCoord(cache.ped, coords.x, coords.y, coords.z, 0)

if not exports.ox_inventory:openInventory('trunk', { id = invId, netid = NetworkGetNetworkIdFromEntity(entity), entityid = entity, door = 5 }) then return end
if not exports.ox_inventory:openInventory('trunk', { id = ('trunk%s'):format(plate), netid = NetworkGetNetworkIdFromEntity(entity), entityid = entity, door = 5 }) then return end
end,
}
})
65 changes: 37 additions & 28 deletions client/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local subCache = {}

function entities.isNetIdNearby(netID)
local entity = netIds[netID]

return entity and entity.entity
end

Expand All @@ -31,24 +32,25 @@ function entities.getEntitiesByType(type)

for k, v in pairs(localEnties) do
if v.type == type then
amount = amount + 1
amount += 1
entityTable[amount] = k
end
end

for _, v in pairs(netIds) do
if v.type == type then
amount = amount + 1
amount += 1
entityTable[amount] = v.entity
end
end

if type == "players" then
for k, v in pairs(playersTable) do
amount = amount + 1
if type == 'players' then
for _, v in pairs(playersTable) do
amount += 1
entityTable[amount] = v.entity
serverIds[amount] = v.serverId
end

return amount, entityTable, serverIds
end

Expand Down Expand Up @@ -112,6 +114,7 @@ end
CreateThread(function()
while true do
local playerCoords = GetEntityCoords(cache.ped)

clearTables()

buildEntities('CVehicle', playerCoords)
Expand All @@ -131,36 +134,42 @@ RegisterNetEvent('onPlayerJoining', function(serverId)

local ent = lib.waitFor(function()
local ped = GetPlayerPed(playerId)
if ped > 0 then return ped end

if ped > 0 then
return ped
end
end, '', 10000)

playersTable[serverId] = {
entity = ent,
serverId = serverId,
type = "players",
type = 'players',
}
end)

AddEventHandler('onResourceStart', function(name)
if name == GetCurrentResourceName() then
local players = GetActivePlayers()

for i = 1, #players do
local playerId = players[i]
local serverId = GetPlayerServerId(playerId)
if serverId ~= cache.serverId then

local ent = lib.waitFor(function()
local ped = GetPlayerPed(playerId)
if ped > 0 then return ped end
end, '', 10000)

playersTable[serverId] = {
entity = ent,
serverId = serverId,
type = "players",
}
end
AddEventHandler('onResourceStart', function(resource)
if resource ~= cache.resource then return end

local players = GetActivePlayers()

for i = 1, #players do
local playerId = players[i]
local serverId = GetPlayerServerId(playerId)

if serverId ~= cache.serverId then
local ent = lib.waitFor(function()
local ped = GetPlayerPed(playerId)

if ped > 0 then
return ped
end
end, '', 10000)

playersTable[serverId] = {
entity = ent,
serverId = serverId,
type = 'players',
}
end
end
end)
Expand Down
Loading

0 comments on commit c9793b7

Please sign in to comment.