mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-19 06:46:04 +01:00
Create compatibility tables for playerFunctions.lua
This commit is contained in:
@@ -580,6 +580,67 @@ function GetRandomTiming(tbl)
|
|||||||
return type(tbl) == "table" and math.random(tbl[1], tbl[2]) or tbl
|
return type(tbl) == "table" and math.random(tbl[1], tbl[2]) or tbl
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-------------------------------------------------------------
|
||||||
|
-- Player Movement
|
||||||
|
-------------------------------------------------------------
|
||||||
|
|
||||||
|
--- Instantly turns an entity to face a target (entity or coordinates) without animation.
|
||||||
|
---
|
||||||
|
--- @param ent number|nil The Ped to turn (defaults to player's Ped if nil).
|
||||||
|
--- @param ent2 number|vector3|nil The target entity or coordinates to face.
|
||||||
|
---
|
||||||
|
--- @usage
|
||||||
|
--- ```lua
|
||||||
|
--- instantLookEnt(nil, vector3(200.0, 300.0, 40.0))
|
||||||
|
--- instantLookEnt(ped1, ped2)
|
||||||
|
--- ```
|
||||||
|
function instantLookEnt(ent, ent2)
|
||||||
|
local ped = ent or PlayerPedId()
|
||||||
|
local p1 = GetEntityCoords(ped, true)
|
||||||
|
local p2 = type(ent2) == "vector3" and ent2 or GetEntityCoords(ent2, true)
|
||||||
|
|
||||||
|
local dx = p2.x - p1.x
|
||||||
|
local dy = p2.y - p1.y
|
||||||
|
local heading = GetHeadingFromVector_2d(dx, dy)
|
||||||
|
|
||||||
|
debugPrint("^6Bridge^7: ^1Forced ^2Turning Player to^7: '^6"..formatCoord(p2).."^7'")
|
||||||
|
SetEntityHeading(ped, heading)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Makes the player look towards a specific target with an animated turn.
|
||||||
|
---
|
||||||
|
--- If the player is not already facing the target (entity or coordinates), a turning animation is triggered.
|
||||||
|
---
|
||||||
|
--- @param entity number|vector3|vector4|nil The target to look at.
|
||||||
|
---
|
||||||
|
--- @usage
|
||||||
|
--- ```lua
|
||||||
|
--- lookEnt(vector3(200.0, 300.0, 40.0))
|
||||||
|
--- lookEnt(pedEntity)
|
||||||
|
--- ```
|
||||||
|
function lookEnt(entity)
|
||||||
|
local ped = PlayerPedId()
|
||||||
|
if entity then
|
||||||
|
if type(entity) == "vector3" or type(entity) == "vector4" then
|
||||||
|
if not IsPedHeadingTowardsPosition(ped, entity.xyz, 30.0) then
|
||||||
|
TaskTurnPedToFaceCoord(ped, entity.xyz, 1500)
|
||||||
|
debugPrint("^6Bridge^7: ^2Turning Player to^7: '^6"..formatCoord(entity).."^7'")
|
||||||
|
Wait(1500)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if DoesEntityExist(entity) then
|
||||||
|
local entCoords = GetEntityCoords(entity)
|
||||||
|
if not IsPedHeadingTowardsPosition(ped, entCoords, 30.0) then
|
||||||
|
TaskTurnPedToFaceCoord(ped, entCoords, 1500)
|
||||||
|
debugPrint("^6Bridge^7: ^2Turning Player to^7: '^6"..entity.."^7' - '"..formatCoord(entCoords).."^7'")
|
||||||
|
Wait(1500)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Material and Prop Functions
|
-- Material and Prop Functions
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
|||||||
@@ -11,70 +11,108 @@
|
|||||||
• Getting active players near a coordinate.
|
• Getting active players near a coordinate.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-------------------------------------------------------------
|
|
||||||
-- Player Movement
|
|
||||||
-------------------------------------------------------------
|
|
||||||
|
|
||||||
--- Instantly turns an entity to face a target (entity or coordinates) without animation.
|
|
||||||
---
|
|
||||||
--- @param ent number|nil The Ped to turn (defaults to player's Ped if nil).
|
|
||||||
--- @param ent2 number|vector3|nil The target entity or coordinates to face.
|
|
||||||
---
|
|
||||||
--- @usage
|
|
||||||
--- ```lua
|
|
||||||
--- instantLookEnt(nil, vector3(200.0, 300.0, 40.0))
|
|
||||||
--- instantLookEnt(ped1, ped2)
|
|
||||||
--- ```
|
|
||||||
function instantLookEnt(ent, ent2)
|
|
||||||
local ped = ent or PlayerPedId()
|
|
||||||
local p1 = GetEntityCoords(ped, true)
|
|
||||||
local p2 = type(ent2) == "vector3" and ent2 or GetEntityCoords(ent2, true)
|
|
||||||
|
|
||||||
local dx = p2.x - p1.x
|
|
||||||
local dy = p2.y - p1.y
|
|
||||||
local heading = GetHeadingFromVector_2d(dx, dy)
|
|
||||||
|
|
||||||
debugPrint("^6Bridge^7: ^1Forced ^2Turning Player to^7: '^6"..formatCoord(p2).."^7'")
|
|
||||||
SetEntityHeading(ped, heading)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Makes the player look towards a specific target with an animated turn.
|
|
||||||
---
|
|
||||||
--- If the player is not already facing the target (entity or coordinates), a turning animation is triggered.
|
|
||||||
---
|
|
||||||
--- @param entity number|vector3|vector4|nil The target to look at.
|
|
||||||
---
|
|
||||||
--- @usage
|
|
||||||
--- ```lua
|
|
||||||
--- lookEnt(vector3(200.0, 300.0, 40.0))
|
|
||||||
--- lookEnt(pedEntity)
|
|
||||||
--- ```
|
|
||||||
function lookEnt(entity)
|
|
||||||
local ped = PlayerPedId()
|
|
||||||
if entity then
|
|
||||||
if type(entity) == "vector3" or type(entity) == "vector4" then
|
|
||||||
if not IsPedHeadingTowardsPosition(ped, entity.xyz, 30.0) then
|
|
||||||
TaskTurnPedToFaceCoord(ped, entity.xyz, 1500)
|
|
||||||
debugPrint("^6Bridge^7: ^2Turning Player to^7: '^6"..formatCoord(entity).."^7'")
|
|
||||||
Wait(1500)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if DoesEntityExist(entity) then
|
|
||||||
local entCoords = GetEntityCoords(entity)
|
|
||||||
if not IsPedHeadingTowardsPosition(ped, entCoords, 30.0) then
|
|
||||||
TaskTurnPedToFaceCoord(ped, entCoords, 1500)
|
|
||||||
debugPrint("^6Bridge^7: ^2Turning Player to^7: '^6"..entity.."^7' - '"..formatCoord(entCoords).."^7'")
|
|
||||||
Wait(1500)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Server Event Handlers for Needs
|
-- Server Event Handlers for Needs
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
|
||||||
|
local hungerThirstFunc = {
|
||||||
|
{ framework = QBXExport,
|
||||||
|
setThirst =
|
||||||
|
function(src, thirst)
|
||||||
|
local Player = Core.Functions.GetPlayer(src)
|
||||||
|
Player.Functions.SetMetaData('thirst', thirst)
|
||||||
|
TriggerClientEvent("hud:client:UpdateNeeds", src, Player.PlayerData.metadata.hunger, thirst)
|
||||||
|
end,
|
||||||
|
setHunger =
|
||||||
|
function(src, hunger)
|
||||||
|
local Player = Core.Functions.GetPlayer(src)
|
||||||
|
Player.Functions.SetMetaData('hunger', hunger)
|
||||||
|
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.thirst)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = QBExport,
|
||||||
|
setThirst =
|
||||||
|
function(src, thirst)
|
||||||
|
local Player = Core.Functions.GetPlayer(src)
|
||||||
|
Player.Functions.SetMetaData('thirst', thirst)
|
||||||
|
TriggerClientEvent("hud:client:UpdateNeeds", src, Player.PlayerData.metadata.hunger, thirst)
|
||||||
|
end,
|
||||||
|
setHunger =
|
||||||
|
function(src, hunger)
|
||||||
|
local Player = Core.Functions.GetPlayer(src)
|
||||||
|
Player.Functions.SetMetaData('hunger', hunger)
|
||||||
|
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.thirst)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = RSGExport,
|
||||||
|
setThirst =
|
||||||
|
function(src, thirst)
|
||||||
|
local Player = Core.Functions.GetPlayer(src)
|
||||||
|
Player.Functions.SetMetaData('thirst', thirst)
|
||||||
|
TriggerClientEvent("hud:client:UpdateNeeds", src, Player.PlayerData.metadata.hunger, thirst)
|
||||||
|
end,
|
||||||
|
setHunger =
|
||||||
|
function(src, hunger)
|
||||||
|
local Player = Core.Functions.GetPlayer(src)
|
||||||
|
Player.Functions.SetMetaData('hunger', hunger)
|
||||||
|
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.thirst)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = ESXExport,
|
||||||
|
setThirst =
|
||||||
|
function(src, thirst)
|
||||||
|
TriggerClientEvent('esx_status:add', src, 'thirst', thirst)
|
||||||
|
end,
|
||||||
|
setHunger =
|
||||||
|
function(src, hunger)
|
||||||
|
TriggerClientEvent('esx_status:add', src, 'hunger', hunger)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Sets the player's thirst level.
|
||||||
|
---
|
||||||
|
--- @param src number The player's server ID.
|
||||||
|
--- @param thirst number The new thirst level.
|
||||||
|
---
|
||||||
|
--- @usage
|
||||||
|
--- ```lua
|
||||||
|
--- setThirst(playerId, 80)
|
||||||
|
--- ```
|
||||||
|
function setThirst(src, thirst)
|
||||||
|
for i = 1, #hungerThirstFunc do
|
||||||
|
local framework = hungerThirstFunc[i]
|
||||||
|
if isStarted(framework.framework) then
|
||||||
|
debugPrint("^4Debug^7: ^2Adding ^3"..framework.framework.." ^2thirst^7: ^3"..thirst.." ^2to player^7: ^3"..src.."^7")
|
||||||
|
framework.setThirst(src, thirst)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Sets the player's hunger level.
|
||||||
|
---
|
||||||
|
--- @param src number The player's server ID.
|
||||||
|
--- @param hunger number The new hunger level.
|
||||||
|
---
|
||||||
|
--- @usage
|
||||||
|
--- ```lua
|
||||||
|
--- setHunger(playerId, 60)
|
||||||
|
--- ```
|
||||||
|
function setHunger(src, hunger)
|
||||||
|
for i = 1, #hungerThirstFunc do
|
||||||
|
local framework = hungerThirstFunc[i]
|
||||||
|
if isStarted(framework.framework) then
|
||||||
|
debugPrint("^4Debug^7: ^2Adding ^3"..framework.framework.." ^2hunger^7: ^3"..hunger.." ^2to player^7: ^3"..src.."^7")
|
||||||
|
framework.setHunger(src, hunger)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Server event handler for urinal usage.
|
--- Server event handler for urinal usage.
|
||||||
--- Decreases player's thirst by a random amount.
|
--- Decreases player's thirst by a random amount.
|
||||||
RegisterNetEvent(getScript()..":server:Urinal", function()
|
RegisterNetEvent(getScript()..":server:Urinal", function()
|
||||||
@@ -99,72 +137,94 @@ RegisterNetEvent(getScript()..":server:setNeed", function(needType, amount)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Sets the player's thirst level.
|
|
||||||
---
|
|
||||||
--- @param src number The player's server ID.
|
|
||||||
--- @param thirst number The new thirst level.
|
|
||||||
---
|
|
||||||
--- @usage
|
|
||||||
--- ```lua
|
|
||||||
--- setThirst(playerId, 80)
|
|
||||||
--- ```
|
|
||||||
function setThirst(src, thirst)
|
|
||||||
|
|
||||||
debugPrint("^4Debug^7: ^2Adding thirst^7: ^3"..thirst.." ^2to player^7: ^3"..src.."^7")
|
|
||||||
if isStarted(ESXExport) then
|
|
||||||
TriggerClientEvent('esx_status:add', src, 'thirst', thirst)
|
|
||||||
|
|
||||||
elseif isStarted(QBExport) or isStarted(QBXExport) or isStarted(RSGExport) then
|
|
||||||
local Player = Core.Functions.GetPlayer(src)
|
|
||||||
Player.Functions.SetMetaData('thirst', thirst)
|
|
||||||
TriggerClientEvent("hud:client:UpdateNeeds", src, Player.PlayerData.metadata.hunger, thirst)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Sets the player's hunger level.
|
|
||||||
---
|
|
||||||
--- @param src number The player's server ID.
|
|
||||||
--- @param hunger number The new hunger level.
|
|
||||||
---
|
|
||||||
--- @usage
|
|
||||||
--- ```lua
|
|
||||||
--- setHunger(playerId, 60)
|
|
||||||
--- ```
|
|
||||||
function setHunger(src, hunger)
|
|
||||||
|
|
||||||
debugPrint("^4Debug^7: ^2Adding hunger^7: ^3"..hunger.." ^2to player^7: ^3"..src.."^7")
|
|
||||||
if isStarted(ESXExport) then
|
|
||||||
TriggerClientEvent('esx_status:add', src, 'hunger', hunger)
|
|
||||||
|
|
||||||
elseif isStarted(QBExport) or isStarted(QBXExport) or isStarted(RSGExport) then
|
|
||||||
local Player = Core.Functions.GetPlayer(src)
|
|
||||||
Player.Functions.SetMetaData('hunger', hunger)
|
|
||||||
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.thirst)
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Economy Event Handlers
|
-- Economy Event Handlers
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
|
||||||
--- BillPlayer
|
local billPlayerFunc = {
|
||||||
function billPlayer(data)
|
jim =
|
||||||
if not Config.System.Billing or Config.System.Billing == "jim" then
|
function(data)
|
||||||
TriggerEvent("jim-payments:client:Charge", {
|
TriggerEvent("jim-payments:client:Charge", {
|
||||||
job = data.job,
|
job = data.job,
|
||||||
gang = data.gang,
|
gang = data.gang,
|
||||||
coords = data.coords.xyz,
|
coords = data.coords.xyz,
|
||||||
img = data.img
|
img = data.img
|
||||||
})
|
})
|
||||||
elseif Config.System.Billing == "okok" then
|
end,
|
||||||
-- TriggerServerEvent("okokBilling:CreateCustomInvoice", target, price, reason, invoiceSource, society, societyName)
|
okok =
|
||||||
|
function(data)
|
||||||
TriggerEvent("okokBilling:ToggleCreateInvoice")
|
TriggerEvent("okokBilling:ToggleCreateInvoice")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
--- BillPlayer
|
||||||
|
function billPlayer(data)
|
||||||
|
if Config.System.Billing and billPlayerFunc[Config.System.Billing] then
|
||||||
|
billPlayerFunc[Config.System.Billing](data)
|
||||||
|
else
|
||||||
|
debugPrint("^1Error^7: ^1No billing script detected")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Money Handlers
|
||||||
|
|
||||||
|
local moneyFunc = {
|
||||||
|
{ framework = OXInv,
|
||||||
|
chargePlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return exports[OXInv]:RemoveItem(src, "money", amount)
|
||||||
|
end,
|
||||||
|
fundPlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return exports[OXInv]:AddItem(src, "money", amount)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = QBXExport,
|
||||||
|
chargePlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return Core.Functions.GetPlayer(src).Functions.RemoveMoney(moneyType or "cash", amount)
|
||||||
|
end,
|
||||||
|
fundPlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return Core.Functions.GetPlayer(src).Functions.AddMoney(moneyType or "cash", amount)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = QBExport,
|
||||||
|
chargePlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return Core.Functions.GetPlayer(src).Functions.RemoveMoney(moneyType or "cash", amount)
|
||||||
|
end,
|
||||||
|
fundPlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return Core.Functions.GetPlayer(src).Functions.AddMoney(moneyType or "cash", amount)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = RSGExport,
|
||||||
|
chargePlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return Core.Functions.GetPlayer(src).Functions.RemoveMoney(moneyType or "cash", amount)
|
||||||
|
end,
|
||||||
|
fundPlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return Core.Functions.GetPlayer(src).Functions.AddMoney(moneyType or "cash", amount)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = ESXExport,
|
||||||
|
chargePlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return ESX.GetPlayerFromId(src).removeMoney(amount, "")
|
||||||
|
end,
|
||||||
|
fundPlayer =
|
||||||
|
function(src, amount, moneyType)
|
||||||
|
return ESX.GetPlayerFromId(src).addMoney(amount, "")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
--- Charges a player by removing money from their account.
|
--- Charges a player by removing money from their account.
|
||||||
---
|
---
|
||||||
--- @param cost number The amount to charge.
|
--- @param cost number The amount to charge.
|
||||||
@@ -175,59 +235,33 @@ end
|
|||||||
--- ```lua
|
--- ```lua
|
||||||
--- chargePlayer(100, "cash", playerId)
|
--- chargePlayer(100, "cash", playerId)
|
||||||
--- ```
|
--- ```
|
||||||
|
---
|
||||||
function chargePlayer(cost, moneyType, newsrc)
|
function chargePlayer(cost, moneyType, newsrc)
|
||||||
local is_success = false
|
local is_success = false
|
||||||
local src = newsrc or source
|
local src = newsrc or source
|
||||||
local fundResource = ""
|
|
||||||
if cost < 0 then
|
if cost <= 0 then
|
||||||
debugPrint("^1Error^7: ^7SRC: ^3"..src.." ^2Tried to charge a minus value^7", cost)
|
debugPrint("^1Error^7: ^7SRC: ^3"..src.." ^2Tried to charge a zero or minus value^7", cost)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if moneyType == "cash" then
|
|
||||||
if isStarted(OXInv) then fundResource = OXInv
|
|
||||||
is_success = exports[OXInv]:RemoveItem(src, "money", cost)
|
|
||||||
|
|
||||||
elseif isStarted(QBExport) or isStarted(QBXExport) then
|
|
||||||
fundResource = QBExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost)
|
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
|
||||||
fundResource = RSGExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost)
|
|
||||||
|
|
||||||
elseif isStarted(ESXExport) then
|
|
||||||
fundResource = ESXExport
|
|
||||||
ESX.GetPlayerFromId(src).removeMoney(cost, "")
|
|
||||||
is_success = true
|
|
||||||
|
|
||||||
|
for i = 1, #moneyFunc do
|
||||||
|
local framework = moneyFunc[i]
|
||||||
|
if framework.framework == OXInv and moneyType == "bank" then goto skip end
|
||||||
|
if isStarted(framework.framework) then
|
||||||
|
debugPrint("^6Bridge^7: ^2Charging ^3"..framework.framework.." ^2Player^7: '^6"..cost.."^7'", moneyType)
|
||||||
|
is_success = framework.chargePlayer(src, cost, moneyType)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
elseif moneyType == "bank" then
|
::skip::
|
||||||
if isStarted(QBExport) or isStarted(QBXExport) then
|
|
||||||
fundResource = QBExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost)
|
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
|
||||||
fundResource = RSGExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost)
|
|
||||||
|
|
||||||
elseif isStarted(ESXExport) then
|
|
||||||
fundResource = ESXExport
|
|
||||||
ESX.GetPlayerFromId(src).removeMoney(cost, "")
|
|
||||||
is_success = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fundResource == "" then
|
|
||||||
print("Cannot charge player - check starter.lua")
|
|
||||||
else
|
|
||||||
debugPrint("^6Bridge^7: ^2Charging ^2Player^7: '^6"..cost.."^7'", moneyType, fundResource)
|
|
||||||
end
|
end
|
||||||
return is_success
|
return is_success
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent(getScript()..":server:ChargePlayer", function(cost, moneyType, newsrc)
|
RegisterNetEvent(getScript()..":server:ChargePlayer", function(cost, moneyType, newsrc)
|
||||||
debugPrint(GetInvokingResource())
|
|
||||||
if GetInvokingResource() and GetInvokingResource() ~= getScript() and GetInvokingResource() ~= "qb-core" then
|
if GetInvokingResource() and GetInvokingResource() ~= getScript() and GetInvokingResource() ~= "qb-core" then
|
||||||
debugPrint("^1Error^7: ^1Possible exploit^7, ^1vital function was called from an external resource^7")
|
print(GetInvokingResource())
|
||||||
|
print("^1Error^7: ^1Possible exploit^7, ^1vital function was called from an external resource^7")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
chargePlayer(cost, moneyType, newsrc)
|
chargePlayer(cost, moneyType, newsrc)
|
||||||
@@ -246,48 +280,23 @@ end)
|
|||||||
function fundPlayer(fund, moneyType, newsrc)
|
function fundPlayer(fund, moneyType, newsrc)
|
||||||
local is_success = false
|
local is_success = false
|
||||||
local src = newsrc or source
|
local src = newsrc or source
|
||||||
local fundResource = ""
|
|
||||||
|
|
||||||
if moneyType == "cash" then
|
if fund <= 0 then
|
||||||
if isStarted(OXInv) then
|
debugPrint("^1Error^7: ^7SRC: ^3"..src.." ^2Tried to fund a zero or minus value^7", fund)
|
||||||
fundResource = OXInv
|
return
|
||||||
is_success = exports[OXInv]:AddItem(src, "money", fund)
|
|
||||||
|
|
||||||
elseif isStarted(QBExport) or isStarted(QBXExport) then
|
|
||||||
fundResource = QBExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund)
|
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
|
||||||
fundResource = RSGExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund)
|
|
||||||
|
|
||||||
elseif isStarted(ESXExport) then
|
|
||||||
fundResource = ESXExport
|
|
||||||
ESX.GetPlayerFromId(src).addMoney(fund, "")
|
|
||||||
is_success = true
|
|
||||||
|
|
||||||
end
|
|
||||||
elseif moneyType == "bank" then
|
|
||||||
if isStarted(QBExport) or isStarted(QBXExport) then
|
|
||||||
fundResource = QBExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund)
|
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
|
||||||
fundResource = RSGExport
|
|
||||||
is_success = Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund)
|
|
||||||
|
|
||||||
elseif isStarted(ESXExport) then
|
|
||||||
fundResource = ESXExport
|
|
||||||
ESX.GetPlayerFromId(src).addMoney(fund, "")
|
|
||||||
is_success = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if fundResource == "" then
|
for i = 1, #moneyFunc do
|
||||||
print("Cannot fund player - check starter.lua")
|
local framework = moneyFunc[i]
|
||||||
else
|
if framework.framework == OXInv and moneyType == "bank" then goto skip end
|
||||||
debugPrint("^6Bridge^7: ^2Funding Player: '^2"..fund.."^7'", moneyType, fundResource)
|
if isStarted(framework.framework) then
|
||||||
|
debugPrint("^6Bridge^7: ^2Funding ^3"..framework.framework.." ^2Player^7: '^6"..cost.."^7'", moneyType)
|
||||||
|
is_success = framework.chargePlayer(src, fund, moneyType)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
::skip::
|
||||||
|
end
|
||||||
|
|
||||||
return is_success
|
return is_success
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -534,30 +543,13 @@ function hasJob(job, source, grade)
|
|||||||
return hasJobFlag, duty
|
return hasJobFlag, duty
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Retrieves basic player information (name, cash, bank, job, etc.) based on the active core/inventory system.
|
----------------------------------
|
||||||
---
|
---
|
||||||
--- Can be called server-side (passing a player source) or client-side (for current player).
|
local getPlayerFunc = {
|
||||||
---
|
{ framework = ESXExport,
|
||||||
--- @param source number|nil Optional player server ID.
|
serverSide =
|
||||||
--- @return table A table containing player details.
|
function(src)
|
||||||
---
|
|
||||||
--- @usage
|
|
||||||
--- ```lua
|
|
||||||
--- -- Get information for a specific player
|
|
||||||
--- local playerInfo = getPlayer(playerId)
|
|
||||||
--- print(playerInfo.name, playerInfo.cash, playerInfo.bank)
|
|
||||||
---
|
|
||||||
--- -- Get information for the current player (client-side)
|
|
||||||
--- local myInfo = getPlayer()
|
|
||||||
--- print(myInfo.name, myInfo.cash, myInfo.bank)
|
|
||||||
--- ```
|
|
||||||
function getPlayer(source)
|
|
||||||
local Player = {}
|
local Player = {}
|
||||||
--debugPrint("^6Bridge^7: ^2Getting ^3Player^2 info^7")
|
|
||||||
|
|
||||||
if source then
|
|
||||||
local src = tonumber(source)
|
|
||||||
if isStarted(ESXExport) then
|
|
||||||
local info = ESX.GetPlayerFromId(src)
|
local info = ESX.GetPlayerFromId(src)
|
||||||
if not info then return {} end
|
if not info then return {} end
|
||||||
Player = {
|
Player = {
|
||||||
@@ -577,8 +569,45 @@ function getPlayer(source)
|
|||||||
--account = info.charinfo.account,
|
--account = info.charinfo.account,
|
||||||
citizenId = info.identifier,
|
citizenId = info.identifier,
|
||||||
}
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
|
||||||
elseif isStarted(OXCoreExport) then
|
clientSide =
|
||||||
|
function()
|
||||||
|
local Player = {}
|
||||||
|
local info = ESX.GetPlayerData()
|
||||||
|
if not info.firstName then return {} end
|
||||||
|
|
||||||
|
local cash, bank = 0, 0
|
||||||
|
for _, v in pairs(info.accounts) do
|
||||||
|
if v.name == "money" then cash = v.money end
|
||||||
|
if v.name == "bank" then bank = v.money end
|
||||||
|
end
|
||||||
|
Player = {
|
||||||
|
firstname = info.firstName,
|
||||||
|
lastname = info.lastName,
|
||||||
|
name = info.firstName.." "..info.lastName,
|
||||||
|
cash = cash,
|
||||||
|
bank = bank,
|
||||||
|
source = GetPlayerServerId(PlayerId()),
|
||||||
|
job = info.job.name,
|
||||||
|
--jobBoss = info.job.isboss,
|
||||||
|
--gang = info.gang.name,
|
||||||
|
--gangBoss = info.gang.isboss,
|
||||||
|
onDuty = info.job.onDuty,
|
||||||
|
--account = info.charinfo.account,
|
||||||
|
citizenId = info.identifier,
|
||||||
|
isDead = IsEntityDead(PlayerPedId()),
|
||||||
|
isDown = IsPedDeadOrDying(PlayerPedId(), true)
|
||||||
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = OXCoreExport,
|
||||||
|
serverSide =
|
||||||
|
function(src)
|
||||||
|
local Player = {}
|
||||||
local file = ('imports/%s.lua'):format('server')
|
local file = ('imports/%s.lua'):format('server')
|
||||||
local import = LoadResourceFile('ox_core', file)
|
local import = LoadResourceFile('ox_core', file)
|
||||||
local chunk = assert(load(import, ('@@ox_core/%s'):format(file)))
|
local chunk = assert(load(import, ('@@ox_core/%s'):format(file)))
|
||||||
@@ -600,8 +629,38 @@ function getPlayer(source)
|
|||||||
--account = info.charinfo.account,
|
--account = info.charinfo.account,
|
||||||
citizenId = player.stateId,
|
citizenId = player.stateId,
|
||||||
}
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
|
||||||
elseif isStarted(QBXExport) then
|
clientSide =
|
||||||
|
function()
|
||||||
|
local Player = {}
|
||||||
|
if not OxPlayer.userId then return {} end
|
||||||
|
Player = {
|
||||||
|
firstname = OxPlayer.get("firstName"),
|
||||||
|
lastname = OxPlayer.get("lastName"),
|
||||||
|
name = OxPlayer.get("firstName").." "..OxPlayer.get("lastName"),
|
||||||
|
cash = exports[OXInv]:Search('count', "money"),
|
||||||
|
bank = 0,
|
||||||
|
source = GetPlayerServerId(PlayerId()),
|
||||||
|
job = OxPlayer.getGroups(),
|
||||||
|
--jobBoss = info.job.isboss,
|
||||||
|
gang = OxPlayer.getGroups(),
|
||||||
|
--gangBoss = info.gang.isboss,
|
||||||
|
--onDuty = info.job.onduty,
|
||||||
|
--account = info.charinfo.account,
|
||||||
|
citizenId = OxPlayer.userId,
|
||||||
|
isDead = IsEntityDead(PlayerPedId()),
|
||||||
|
isDown = IsPedDeadOrDying(PlayerPedId(), true)
|
||||||
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = QBXExport,
|
||||||
|
serverSide =
|
||||||
|
function(src)
|
||||||
|
local Player = {}
|
||||||
local info = exports[QBXExport]:GetPlayer(src)
|
local info = exports[QBXExport]:GetPlayer(src)
|
||||||
if not info then return {} end
|
if not info then return {} end
|
||||||
Player = {
|
Player = {
|
||||||
@@ -624,112 +683,12 @@ function getPlayer(source)
|
|||||||
isDown = info.PlayerData.metadata["inlaststand"],
|
isDown = info.PlayerData.metadata["inlaststand"],
|
||||||
charInfo = info.charinfo,
|
charInfo = info.charinfo,
|
||||||
}
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
|
||||||
elseif isStarted(QBExport) and not isStarted(QBXExport) then
|
clientSide =
|
||||||
if Core.Functions.GetPlayer(src) then
|
function()
|
||||||
local info = Core.Functions.GetPlayer(src).PlayerData
|
local Player = {}
|
||||||
if not info then return {} end
|
|
||||||
Player = {
|
|
||||||
firstname = info.charinfo.firstname,
|
|
||||||
lastname = info.charinfo.lastname,
|
|
||||||
name = info.charinfo.firstname.." "..info.charinfo.lastname,
|
|
||||||
cash = info.money["cash"],
|
|
||||||
bank = info.money["bank"],
|
|
||||||
source = info.source,
|
|
||||||
job = info.job.name,
|
|
||||||
jobBoss = info.job.isboss,
|
|
||||||
jobInfo = info.job,
|
|
||||||
gang = info.gang.name,
|
|
||||||
gangBoss = info.gang.isboss,
|
|
||||||
gangInfo = info.gang,
|
|
||||||
onDuty = info.job.onduty,
|
|
||||||
account = info.charinfo.account,
|
|
||||||
citizenId = info.citizenid,
|
|
||||||
isDead = info.metadata["isdead"],
|
|
||||||
isDown = info.metadata["inlaststand"],
|
|
||||||
charInfo = info.charinfo,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
|
||||||
if Core.Functions.GetPlayer(src) then
|
|
||||||
local info = Core.Functions.GetPlayer(src).PlayerData
|
|
||||||
if not info then return {} end
|
|
||||||
Player = {
|
|
||||||
firstname = info.charinfo.firstname,
|
|
||||||
lastname = info.charinfo.lastname,
|
|
||||||
name = info.charinfo.firstname.." "..info.charinfo.lastname,
|
|
||||||
cash = info.money["cash"],
|
|
||||||
bank = info.money["bank"],
|
|
||||||
source = info.source,
|
|
||||||
job = info.job.name,
|
|
||||||
jobBoss = info.job.isboss,
|
|
||||||
jobInfo = info.job,
|
|
||||||
gang = info.gang.name,
|
|
||||||
gangBoss = info.gang.isboss,
|
|
||||||
gangInfo = info.gang,
|
|
||||||
onDuty = info.job.onduty,
|
|
||||||
account = info.charinfo.account,
|
|
||||||
citizenId = info.citizenid,
|
|
||||||
isDead = info.metadata["isdead"],
|
|
||||||
isDown = info.metadata["inlaststand"],
|
|
||||||
charInfo = info.charinfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("^4ERROR^7: ^2No Core detected for getPlayer() - Check starter.lua")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- Client-side: Get current player info.
|
|
||||||
if isStarted(ESXExport) and ESX ~= nil then
|
|
||||||
local info = ESX.GetPlayerData()
|
|
||||||
if not info.firstName then return {} end
|
|
||||||
|
|
||||||
local cash, bank = 0, 0
|
|
||||||
for k, v in pairs(info.accounts) do
|
|
||||||
if v.name == "money" then cash = v.money end
|
|
||||||
if v.name == "bank" then bank = v.money end
|
|
||||||
end
|
|
||||||
Player = {
|
|
||||||
firstname = info.firstName,
|
|
||||||
lastname = info.lastName,
|
|
||||||
name = info.firstName.." "..info.lastName,
|
|
||||||
cash = cash,
|
|
||||||
bank = bank,
|
|
||||||
source = GetPlayerServerId(PlayerId()),
|
|
||||||
job = info.job.name,
|
|
||||||
--jobBoss = info.job.isboss,
|
|
||||||
--gang = info.gang.name,
|
|
||||||
--gangBoss = info.gang.isboss,
|
|
||||||
onDuty = info.job.onDuty,
|
|
||||||
--account = info.charinfo.account,
|
|
||||||
citizenId = info.identifier,
|
|
||||||
isDead = IsEntityDead(PlayerPedId()),
|
|
||||||
isDown = IsPedDeadOrDying(PlayerPedId(), true)
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif isStarted(OXCoreExport) then
|
|
||||||
if not OxPlayer.userId then return {} end
|
|
||||||
Player = {
|
|
||||||
firstname = OxPlayer.get("firstName"),
|
|
||||||
lastname = OxPlayer.get("lastName"),
|
|
||||||
name = OxPlayer.get("firstName").." "..OxPlayer.get("lastName"),
|
|
||||||
cash = exports[OXInv]:Search('count', "money"),
|
|
||||||
bank = 0,
|
|
||||||
source = GetPlayerServerId(PlayerId()),
|
|
||||||
job = OxPlayer.getGroups(),
|
|
||||||
--jobBoss = info.job.isboss,
|
|
||||||
gang = OxPlayer.getGroups(),
|
|
||||||
--gangBoss = info.gang.isboss,
|
|
||||||
--onDuty = info.job.onduty,
|
|
||||||
--account = info.charinfo.account,
|
|
||||||
citizenId = OxPlayer.userId,
|
|
||||||
isDead = IsEntityDead(PlayerPedId()),
|
|
||||||
isDown = IsPedDeadOrDying(PlayerPedId(), true)
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif isStarted(QBXExport) then
|
|
||||||
local info = exports[QBXExport]:GetPlayerData()
|
local info = exports[QBXExport]:GetPlayerData()
|
||||||
if not info.charinfo then return {} end
|
if not info.charinfo then return {} end
|
||||||
Player = {
|
Player = {
|
||||||
@@ -752,8 +711,44 @@ function getPlayer(source)
|
|||||||
isDown = info.metadata["inlaststand"],
|
isDown = info.metadata["inlaststand"],
|
||||||
charInfo = info.charinfo,
|
charInfo = info.charinfo,
|
||||||
}
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
elseif isStarted(QBExport) and not isStarted(QBXExport) then
|
{ framework = QBExport,
|
||||||
|
serverSide =
|
||||||
|
function(src)
|
||||||
|
local Player = {}
|
||||||
|
if Core.Functions.GetPlayer(src) then
|
||||||
|
local info = Core.Functions.GetPlayer(src).PlayerData
|
||||||
|
if not info then return {} end
|
||||||
|
Player = {
|
||||||
|
firstname = info.charinfo.firstname,
|
||||||
|
lastname = info.charinfo.lastname,
|
||||||
|
name = info.charinfo.firstname.." "..info.charinfo.lastname,
|
||||||
|
cash = info.money["cash"],
|
||||||
|
bank = info.money["bank"],
|
||||||
|
source = info.source,
|
||||||
|
job = info.job.name,
|
||||||
|
jobBoss = info.job.isboss,
|
||||||
|
jobInfo = info.job,
|
||||||
|
gang = info.gang.name,
|
||||||
|
gangBoss = info.gang.isboss,
|
||||||
|
gangInfo = info.gang,
|
||||||
|
onDuty = info.job.onduty,
|
||||||
|
account = info.charinfo.account,
|
||||||
|
citizenId = info.citizenid,
|
||||||
|
isDead = info.metadata["isdead"],
|
||||||
|
isDown = info.metadata["inlaststand"],
|
||||||
|
charInfo = info.charinfo,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
|
||||||
|
clientSide =
|
||||||
|
function()
|
||||||
|
local Player = {}
|
||||||
local info = nil
|
local info = nil
|
||||||
Core.Functions.GetPlayerData(function(PlayerData) info = PlayerData end)
|
Core.Functions.GetPlayerData(function(PlayerData) info = PlayerData end)
|
||||||
if not info.charinfo then return {} end
|
if not info.charinfo then return {} end
|
||||||
@@ -778,8 +773,44 @@ function getPlayer(source)
|
|||||||
isDown = info.metadata["inlaststand"],
|
isDown = info.metadata["inlaststand"],
|
||||||
charInfo = info.charinfo,
|
charInfo = info.charinfo,
|
||||||
}
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
{ framework = RSGExport,
|
||||||
|
serverSide =
|
||||||
|
function(src)
|
||||||
|
local Player = {}
|
||||||
|
if Core.Functions.GetPlayer(src) then
|
||||||
|
local info = Core.Functions.GetPlayer(src).PlayerData
|
||||||
|
if not info then return {} end
|
||||||
|
Player = {
|
||||||
|
firstname = info.charinfo.firstname,
|
||||||
|
lastname = info.charinfo.lastname,
|
||||||
|
name = info.charinfo.firstname.." "..info.charinfo.lastname,
|
||||||
|
cash = info.money["cash"],
|
||||||
|
bank = info.money["bank"],
|
||||||
|
source = info.source,
|
||||||
|
job = info.job.name,
|
||||||
|
jobBoss = info.job.isboss,
|
||||||
|
jobInfo = info.job,
|
||||||
|
gang = info.gang.name,
|
||||||
|
gangBoss = info.gang.isboss,
|
||||||
|
gangInfo = info.gang,
|
||||||
|
onDuty = info.job.onduty,
|
||||||
|
account = info.charinfo.account,
|
||||||
|
citizenId = info.citizenid,
|
||||||
|
isDead = info.metadata["isdead"],
|
||||||
|
isDown = info.metadata["inlaststand"],
|
||||||
|
charInfo = info.charinfo,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
|
||||||
|
clientSide =
|
||||||
|
function()
|
||||||
|
local Player = {}
|
||||||
local info = nil
|
local info = nil
|
||||||
Core.Functions.GetPlayerData(function(PlayerData) info = PlayerData end)
|
Core.Functions.GetPlayerData(function(PlayerData) info = PlayerData end)
|
||||||
if not info.charinfo then return {} end
|
if not info.charinfo then return {} end
|
||||||
@@ -804,11 +835,53 @@ function getPlayer(source)
|
|||||||
isDown = info.metadata["inlaststand"],
|
isDown = info.metadata["inlaststand"],
|
||||||
charInfo = info.charinfo,
|
charInfo = info.charinfo,
|
||||||
}
|
}
|
||||||
|
return Player
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Retrieves basic player information (name, cash, bank, job, etc.) based on the active core/inventory system.
|
||||||
|
---
|
||||||
|
--- Can be called server-side (passing a player source) or client-side (for current player).
|
||||||
|
---
|
||||||
|
--- @param source number|nil Optional player server ID.
|
||||||
|
--- @return table A table containing player details.
|
||||||
|
---
|
||||||
|
--- @usage
|
||||||
|
--- ```lua
|
||||||
|
--- -- Get information for a specific player
|
||||||
|
--- local playerInfo = getPlayer(playerId)
|
||||||
|
--- print(playerInfo.name, playerInfo.cash, playerInfo.bank)
|
||||||
|
---
|
||||||
|
--- -- Get information for the current player (client-side)
|
||||||
|
--- local myInfo = getPlayer()
|
||||||
|
--- print(myInfo.name, myInfo.cash, myInfo.bank)
|
||||||
|
--- ```
|
||||||
|
function getPlayer(source)
|
||||||
|
local Player = {}
|
||||||
|
--debugPrint("^6Bridge^7: ^2Getting ^3Player^2 info^7")
|
||||||
|
|
||||||
|
if source then
|
||||||
|
|
||||||
|
for i = 1, #getPlayerFunc do
|
||||||
|
local framework = getPlayerFunc[i]
|
||||||
|
if isStarted(framework.framework) then
|
||||||
|
Player = framework.serverSide(source)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
print("^4ERROR^7: ^2No Core detected for hasJob ^7- ^2Check ^3starter^1.^2lua^7")
|
|
||||||
|
for i = 1, #getPlayerFunc do
|
||||||
|
local framework = getPlayerFunc[i]
|
||||||
|
if isStarted(framework.framework) then
|
||||||
|
Player = framework.clientSide()
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
return Player
|
return Player
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user