Skip to content

Commit

Permalink
Update v2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Nov 23, 2024
1 parent 15106ac commit 698998e
Show file tree
Hide file tree
Showing 18 changed files with 713 additions and 408 deletions.
126 changes: 126 additions & 0 deletions bridge/esx/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
if MSK.Bridge.Framework.Type ~= 'ESX' then return end

AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() ~= resource then return end

if ESX.IsPlayerLoaded() then
MSK.Bridge.isPlayerLoaded = true
ESX.PlayerLoaded = true

local playerData = ESX.GetPlayerData()
ESX.PlayerData = playerData
MSK.Bridge.PlayerData = playerData

SetPlayerData()
end
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.setPlayerData, function(key, value)
local invoke = GetInvokingResource()
if not invoke or invoke ~= 'msk_core' then return end

MSK.Bridge.PlayerData[key] = value

SetPlayerData()
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLoaded, function(xPlayer, isNew, skin)
ESX.PlayerData = xPlayer
ESX.PlayerLoaded = true

MSK.Bridge.isPlayerLoaded = true
MSK.Bridge.PlayerData = xPlayer

SetPlayerData()
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLogout, function()
ESX.PlayerLoaded = false
ESX.PlayerData = {}

MSK.Bridge.isPlayerLoaded = false
MSK.Bridge.PlayerData = {}
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.setJob, function(newJob, lastJob)
MSK.Bridge.PlayerData.job = newJob
SetPlayerData()
end)

MSK.Bridge.SetPlayerData = function(key, value)
MSK.Bridge.PlayerData[key] = value
ESX.SetPlayerData(key, value)
SetPlayerData()
end

SetPlayerData = function()
local self = MSK.Bridge.PlayerData

self.dob = self.dateofbirth

local job = self.job

if job then
self.job = {
name = job.name,
label = job.name,
grade = job.grade,
grade_name = job.grade_name,
grade_label = job.grade_label,
grade_salary = job.grade_salary,
isBoss = job.grade_name == 'boss'
}
end

if MSK.Bridge.Inventory == 'ox_inventory' then
self.inventory = exports.ox_inventory:GetPlayerItems()
self.loadout = self.inventory
elseif MSK.Bridge.Inventory == 'qs-inventory' then
self.inventory = exports['qs-inventory']:getUserInventory()
self.loadout = self.inventory
end

self.Notification = function(title, message, typ, duration)
MSK.Notification(title, message, typ, duration)
end
self.Notify = self.Notification

self.GetAccount = function(account)
for i = 1, #self.accounts do
if self.accounts[i].name == account then
return self.accounts[i]
end
end
return nil
end

self.Set = function(key, val)
MSK.Bridge.SetPlayerData(key, val)
end

self.Get = function(val)
return self[val]
end

self.HasItem = function(itemName, metadata)
return MSK.HasItem(itemName, metadata)
end

self.IsDead = function()
local isDead = IsPlayerDead(MSK.Player.clientId) or IsEntityDead(MSK.Player.ped)

if GetResourceState("visn_are") ~= "missing" then
local healthBuffer = exports.visn_are:GetHealthBuffer()
isDead = healthBuffer.unconscious
end

if GetResourceState("osp_ambulance") ~= "missing" then
local data = exports.osp_ambulance:GetAmbulanceData(MSK.Player.serverId)
isDead = data.isDead or data.inLastStand
end

return isDead
end

MSK.Bridge.PlayerData = self
end
141 changes: 141 additions & 0 deletions bridge/esx/server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
if MSK.Bridge.Framework.Type ~= 'ESX' then return end

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLoaded, function(playerId, xPlayer, isNew)
MSK.LoadedPlayers[playerId] = xPlayer
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLogout, function(playerId)
MSK.LoadedPlayers[playerId] = nil
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.setJob, function(playerId, newJob, lastJob)
MSK.LoadedPlayers[playerId].job = newJob
end)

GetPlayerData = function(playerData)
local self = playerData

self.GetInventory = playerData.getInventory
self.AddItem = playerData.addInventoryItem
self.RemoveItem = playerData.removeInventoryItem
self.HasItem = playerData.hasItem
self.GetItem = playerData.getInventoryItem
self.CanSwapItem = playerData.canSwapItem
self.CanCarryItem = playerData.canCarryItem
self.AddMoney = playerData.addAccountMoney
self.RemoveMoney = playerData.removeAccountMoney
self.AddWeapon = playerData.addWeapon
self.RemoveWeapon = playerData.removeWeapon
self.HasWeapon = playerData.hasWeapon
self.Set = playerData.setMeta
self.Get = playerData.getMeta
self.SetJob = playerData.setJob

self.dob = playerData.dateofbirth

local job = self.job
self.job = {
name = job.name,
label = job.name,
grade = job.grade,
grade_name = job.grade_name,
grade_label = job.grade_label,
grade_salary = job.grade_salary,
isBoss = job.grade_name == 'boss'
}

self.Notification = function(title, message, typ, duration)
MSK.Notification(self.source, title, message, typ, duration)
end
self.Notify = self.Notification

self.GetAccount = function(account)
for i = 1, #self.accounts do
if self.accounts[i].name == account:lower() then
return self.accounts[i]
end
end
return nil
end

if MSK.Bridge.Inventory ~= 'default' then
self = FunctionOverride(self)
end

return self
end

MSK.GetPlayer = function(player, data)
local Player

if player.player then
Player = player.player
elseif player.source then
Player = ESX.GetPlayerFromId(player.source)
elseif player.identifier then
Player = ESX.GetPlayerFromIdentifier(player.identifier)
elseif player.citizenid then
Player = ESX.GetPlayerFromIdentifier(player.citizenid)
elseif player.phone then
Player = nil
end

if data == nil then data = true end

return data and GetPlayerData(Player) or Player
end
exports('GetPlayer', MSK.GetPlayer)

MSK.GetPlayerServerId = function(Player)
return Player.source
end
MSK.GetServerId = MSK.GetPlayerServerId
exports('GetPlayerServerId', MSK.GetPlayerServerId)

MSK.GetPlayerIdentifier = function(Player)
if tonumber(Player) then
playerId = tostring(Player)
local identifier = GetPlayerIdentifierByType(playerId, "license")
return identifier and identifier:gsub("license:", "")
end

return Player.identifier
end
MSK.GetIdentifier = MSK.GetPlayerIdentifier
exports('GetPlayerIdentifier', MSK.GetPlayerIdentifier)

MSK.GetPlayerJob = function(player)
local Player = MSK.GetPlayer(player, false)
return Player.job.name
end
exports('GetPlayerJob', MSK.GetPlayerJob)

MSK.HasPlayerItem = function(playerId, itemName)
if not playerId then
MSK.Logging('error', 'Player on Function MSK.HasItem does not exist!')
return false
end

local xPlayer = ESX.GetPlayerFromId(playerId)

if type(itemName) ~= 'table' then
local hasItem = xPlayer.getInventoryItem(itemName)

if hasItem and hasItem.count > 0 then
return hasItem
end

return false
end

for i = 1, #itemName do
local item = itemName[i]
local hasItem = xPlayer.getInventoryItem(itemName)

if hasItem and hasItem.count > 0 then
return hasItem
end
end

return false
end
40 changes: 40 additions & 0 deletions bridge/oxcore/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
if MSK.Bridge.Framework.Type ~= 'OXCore' then return end

AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() ~= resource then return end
local playerData = Ox.GetPlayer()

if playerData then
MSK.Bridge.isPlayerLoaded = true
MSK.Bridge.PlayerData = playerData
end
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.setPlayerData, function(PlayerData)
local invoke = GetInvokingResource()
if not invoke or invoke ~= 'msk_core' then return end

MSK.Bridge.PlayerData = Ox.GetPlayer()
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLoaded, function(playerId, isNew)
MSK.Bridge.isPlayerLoaded = true
MSK.Bridge.PlayerData = Ox.GetPlayer()
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLogout, function(playerId)
MSK.Bridge.isPlayerLoaded = false
MSK.Bridge.PlayerData = {}
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.setJob, function(groupName, grade)
if not MSK.Bridge.PlayerData.job then
MSK.Bridge.PlayerData.job = {}
end

MSK.Bridge.PlayerData.job[groupName] = grade
end)

MSK.Bridge.SetPlayerData = function(key, value)
MSK.Bridge.PlayerData[key] = value
end
66 changes: 66 additions & 0 deletions bridge/oxcore/server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
if MSK.Bridge.Framework.Type ~= 'OXCore' then return end

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLoaded, function(playerId, userId, charId)
MSK.LoadedPlayers[playerId] = Ox.GetPlayer(playerId)
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.playerLogout, function(playerId, userId, charId)
MSK.LoadedPlayers[playerId] = nil
end)

RegisterNetEvent(MSK.Bridge.Framework.Events.setJob, function(playerId, groupName, grade)
if not MSK.LoadedPlayers[playerId].job then
MSK.LoadedPlayers[playerId].job = {}
end

MSK.LoadedPlayers[playerId].job[groupName] = grade
end)

GetPlayerData = function(playerData)
end

MSK.GetPlayerServerId = function(Player)
return Player.source
end
MSK.GetServerId = MSK.GetPlayerServerId
exports('GetPlayerServerId', MSK.GetPlayerServerId)

MSK.GetPlayerIdentifier = function(Player)
if tonumber(Player) then
playerId = tostring(Player)
local identifier = GetPlayerIdentifierByType(playerId, "license")
return identifier and identifier:gsub("license:", "")
end

return Player.identifier
end
MSK.GetIdentifier = MSK.GetPlayerIdentifier
exports('GetPlayerIdentifier', MSK.GetPlayerIdentifier)

MSK.HasPlayerItem = function(playerId, itemName, metadata)
if not playerId then
MSK.Logging('error', 'Player on Function MSK.HasItem does not exist!')
return false
end

if type(itemName) ~= 'table' then
local hasItem = exports.ox_inventory:GetItem(playerId, itemName, metadata)

if hasItem and hasItem.count > 0 then
return hasItem
end

return false
end

for i = 1, #itemName do
local item = itemName[i]
local hasItem = exports.ox_inventory:GetItem(playerId, itemName, metadata)

if hasItem and hasItem.count > 0 then
return hasItem
end
end

return false
end
Loading

0 comments on commit 698998e

Please sign in to comment.