Tables + prints + keys + weather + cleanup
This commit is contained in:
1 parent
39022c3a1c
commit
28f20ef27e
41 files changed
+401
-873
No files matched your search
@@ -27,6 +27,10 @@ server_scripts {
|
||||
'modules/phone/**/server.lua',
|
||||
'modules/notify/server.lua',
|
||||
'modules/managment/**/server.lua',
|
||||
'modules/dispatch/**/server.lua',
|
||||
'modules/clothing/**/server.lua',
|
||||
'modules/weather/**/server.lua',
|
||||
'modules/vehicleKey/**/server.lua',
|
||||
'init.lua',
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ Bridge.RegisterModule("Dispatch", Dispatch)
|
||||
Bridge.RegisterModule("VehicleKey", VehicleKey)
|
||||
Bridge.RegisterModule("Weather", Weather)
|
||||
--lib
|
||||
Bridge.RegisterModule("Table", cLib.Table)
|
||||
Bridge.RegisterModule("Tables", cLib.Tables)
|
||||
Bridge.RegisterModule("Math", cLib.Math)
|
||||
Bridge.RegisterModule("Prints", cLib.Prints)
|
||||
Bridge.RegisterModule("Callback", cLib.Callback)
|
||||
|
||||
@@ -39,6 +39,7 @@ cLib = {
|
||||
Ids = Ids or Require("lib/shared/ids.lua"),
|
||||
ReboundEntities = ReboundEntities or Require("lib/shared/rebound_entities.lua"),
|
||||
Tables = Tables or Require("lib/shared/tables.lua"),
|
||||
Prints = Prints or Require("lib/shared/prints.lua"),
|
||||
Math = Math or Require("lib/shared/math.lua"),
|
||||
LA = LA or Require("lib/shared/la.lua"),
|
||||
Perlin = Perlin or Require("lib/shared/perlin.lua"),
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
if GetResourceState('ox_core') ~= 'started' then return end
|
||||
|
||||
local Ox = require '@ox_core.lib.init'
|
||||
|
||||
Framework = {}
|
||||
|
||||
Framework.GetPlayerData = function()
|
||||
-- wip
|
||||
end
|
||||
|
||||
Framework.GetPlayerMetaData = function(metadata)
|
||||
-- wip
|
||||
end
|
||||
|
||||
Framework.GetPlayerIdentifier = function()
|
||||
local player = Ox.GetPlayer()
|
||||
return player.stateId
|
||||
end
|
||||
|
||||
Framework.GetPlayerName = function()
|
||||
local player = Ox.GetPlayer()
|
||||
local first = player.get('firstName')
|
||||
local last = player.get('lastName')
|
||||
return first, last
|
||||
end
|
||||
|
||||
Framework.GetPlayerJob = function()
|
||||
local group, grade, title = Ox.getGroupInfo()
|
||||
return group, title, title, grade
|
||||
end
|
||||
|
||||
Framework.GetPlayerInventory = function()
|
||||
return exports.ox_inventory:GetPlayerItems()
|
||||
end
|
||||
|
||||
Framework.GetIsPlayerDead = function()
|
||||
-- wip
|
||||
end
|
||||
|
||||
RegisterNetEvent('ox:playerLoaded', function()
|
||||
Wait(1500)
|
||||
FillBridgeTables()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
||||
end)
|
||||
|
||||
|
||||
RegisterNetEvent('ox:playerLogout', function()
|
||||
ClearClientSideVariables()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('ox:setGroup', function(name, grade)
|
||||
PlayerJobName = name
|
||||
PlayerJobLabel = name
|
||||
PlayerJobGradeName = grade
|
||||
PlayerJobGradeLevel = grade
|
||||
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate',PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel)
|
||||
end)
|
||||
@@ -0,0 +1,218 @@
|
||||
if GetResourceState('ox_core') ~= 'started' then return end
|
||||
|
||||
local Ox = require '@ox_core.lib.init'
|
||||
|
||||
Framework = {}
|
||||
|
||||
-- Framework.GetPlayerIdentifier(src)
|
||||
-- Returns the citizen ID of the player.
|
||||
Framework.GetPlayerIdentifier = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.getIdentifier()
|
||||
end
|
||||
|
||||
-- Framework.GetPlayerName(src)
|
||||
-- Returns the first and last name of the player.
|
||||
Framework.GetPlayerName = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.variables.firstName, xPlayer.variables.lastName
|
||||
end
|
||||
|
||||
-- Framework.GetItem(src, item, metadata)
|
||||
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
|
||||
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||
Framework.GetItem = function(src, item, _)
|
||||
local playerItems = ESX.GetPlayerFromId(src).getInventory()
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
if v.name == item then
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
--metadata = v.metadata,
|
||||
--slot = v.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
-- Framework.GetItemCount(src, item, _)
|
||||
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
|
||||
Framework.GetItemCount = function(src, item, _)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.getInventoryItem(item).count
|
||||
end
|
||||
|
||||
-- Framework.GetPlayerInventory(src)
|
||||
-- Returns the entire inventory of the player as a table.
|
||||
-- returns {name = v.name, count = v.amount, _, _}
|
||||
Framework.GetPlayerInventory = function(src)
|
||||
local playerItems = ESX.GetPlayerFromId(src).getInventory()
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
if v.count > 0 then
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
--metadata = v.metadata,
|
||||
--slot = v.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
-- Framework.SetMetadata(src, metadata, value)
|
||||
-- Adds the specified metadata key and number value to the player's data.
|
||||
Framework.SetPlayerMetadata = function(src, metadata, value)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
xPlayer.setMeta(metadata, value, nil)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Framework.GetMetadata(src, metadata)
|
||||
-- Gets the specified metadata key and value to the player's data.
|
||||
Framework.GetPlayerMetadata = function(src, metadata)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.getMeta(metadata) or false
|
||||
end
|
||||
|
||||
-- defualt esx Available tables are
|
||||
-- identifier, accounts, group, inventory, job, job_grade, loadout,
|
||||
-- metadata, position, firstname, lastname, dateofbirth, sex, height,
|
||||
-- skin, status, is_dead, id, disabled, last_property, created_at, last_seen,
|
||||
-- phone_number, pincode
|
||||
Framework.GetStatus = function(src, column)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.get(column) or nil
|
||||
end
|
||||
|
||||
-- Framework.AddThirst(src, value)
|
||||
-- Adds the specified value from the player's thirst level.
|
||||
Framework.AddThirst = function(src, value)
|
||||
local clampIT = Math.Clamp(value, 0, 200000)
|
||||
local levelForEsx = clampIT * 2000
|
||||
TriggerClientEvent('esx_status:add', src, 'thirst', levelForEsx)
|
||||
return levelForEsx
|
||||
end
|
||||
|
||||
-- Framework.AddHunger(src, value)
|
||||
-- Adds the specified value from the player's hunger level.
|
||||
Framework.AddHunger = function(src, value)
|
||||
local clampIT = Math.Clamp(value, 0, 200000)
|
||||
local levelForEsx = clampIT * 2000
|
||||
TriggerClientEvent('esx_status:add', src, 'hunger', levelForEsx)
|
||||
return levelForEsx
|
||||
end
|
||||
|
||||
Framework.GetHunger = function(src)
|
||||
local status = Framework.GetStatus(src, "status")
|
||||
if not status then return 0 end
|
||||
return status.hunger
|
||||
end
|
||||
|
||||
Framework.GetThirst = function(src)
|
||||
local status = Framework.GetStatus(src, "status")
|
||||
if not status then return 0 end
|
||||
return status.thirst
|
||||
end
|
||||
|
||||
-- Framework.GetPlayerPhone(src)
|
||||
-- Returns the phone number of the player.
|
||||
Framework.GetPlayerPhone = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.get("phone_number")
|
||||
end
|
||||
|
||||
-- Framework.GetPlayerJob(src)
|
||||
-- Returns the job name, label, grade name, and grade level of the player.
|
||||
Framework.GetPlayerJob = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.getJob().name, xPlayer.getJob().label, xPlayer.getJob().grade_label, xPlayer.getJob().grade
|
||||
end
|
||||
|
||||
-- Framework.GetPlayersByJob(jobname)
|
||||
-- returns a table of player sources that have the specified job name.
|
||||
Framework.GetPlayersByJob = function(job)
|
||||
local players = GetPlayers()
|
||||
local playerList = {}
|
||||
for _, src in pairs(players) do
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if xPlayer.getJob().name == job then
|
||||
table.insert(playerList, src)
|
||||
end
|
||||
end
|
||||
return playerList
|
||||
end
|
||||
|
||||
-- Framework.SetPlayerJob(src, name, grade)
|
||||
-- Sets the player's job to the specified name and grade.
|
||||
Framework.SetPlayerJob = function(src, name, grade)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not ESX.DoesJobExist(name, grade) then lib.print.error("Job Does Not Exsist In Framework :NAME "..name.." Grade:"..grade) return end
|
||||
return xPlayer.setJob(name, grade, true)
|
||||
end
|
||||
|
||||
Framework.ToggleDuty = function(src, status)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
local name = xPlayer.getJob().name
|
||||
local grade = xPlayer.getJob().grade
|
||||
xPlayer.setJob(name, grade, status)
|
||||
end
|
||||
|
||||
-- Framework.AddAccountBalance(src, _type, amount)
|
||||
-- Adds the specified amount to the player's account balance of the specified type.
|
||||
Framework.AddAccountBalance = function(src, _type, amount)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.addAccountMoney(_type, amount)
|
||||
end
|
||||
|
||||
-- Framework.RemoveAccountBalance(src, _type, amount)
|
||||
-- Removes the specified amount from the player's account balance of the specified type.
|
||||
Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.removeAccountMoney(_type, amount)
|
||||
end
|
||||
|
||||
-- Framework.GetAccountBalance(src, _type)
|
||||
-- Returns the player's account balance of the specified type.
|
||||
Framework.GetAccountBalance = function(src, _type)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.getAccount(_type).money
|
||||
end
|
||||
|
||||
-- Framework.AddItem(src, item, amount, _, _)
|
||||
-- Adds the specified item to the player's inventory.
|
||||
Framework.AddItem = function(src, item, amount, slot, metadata)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.addInventoryItem(item, amount)
|
||||
end
|
||||
|
||||
-- Framework.RemoveItem(src, item, amount, _, _)
|
||||
-- Removes the specified item from the player's inventory.
|
||||
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
return xPlayer.removeInventoryItem(item, amount)
|
||||
end
|
||||
|
||||
-- Framework.RegisterUsableItem(item, cb)
|
||||
-- Registers a usable item with a callback function.
|
||||
Framework.RegisterUsableItem = function(itemName, cb)
|
||||
exports(itemName, function(event, item, inventory, slot, data)
|
||||
local slotData = exports.ox_inventory:GetSlot(inventory.id, slot)
|
||||
if event == 'usingItem' then
|
||||
cb(inventory.id, item, slotData)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Framework.Commands = {}
|
||||
Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...)
|
||||
ESX.RegisterCommand(name, permission, function(xPlayer, args, showError)
|
||||
callback(xPlayer, args)
|
||||
end, false, {
|
||||
help = help,
|
||||
arguments = arguments
|
||||
})
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('MrNewbVehicleKeys') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('Renewed-Vehiclekeys') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('cd_garage') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('mk_vehiclekeys') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('okokGarage') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,11 @@
|
||||
if GetResourceState('qb-vehiclekeys') ~= 'started' then return end
|
||||
if GetResourceState('qbx_vehiclekeys') == 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('qbx_vehiclekeys') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('qs-vehiclekeys') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('t1ger_keys') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,10 @@
|
||||
if GetResourceState('wasabi_carlock') ~= 'started' then return end
|
||||
VehicleKey = {}
|
||||
|
||||
VehicleKey.GiveKeys = function(src, vehicle, plate)
|
||||
--wip
|
||||
end
|
||||
|
||||
VehicleKey.RemoveKeys = function(src, vehicle, plate)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,6 @@
|
||||
if GetResourceState('qb-weathersync') ~= 'started' then return end
|
||||
Weather = {}
|
||||
|
||||
Weather.ToggleSync = function(src, toggle)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,6 @@
|
||||
if GetResourceState('Renewed-Weathersync') ~= 'started' then return end
|
||||
Weather = {}
|
||||
|
||||
Weather.ToggleSync = function(src, toggle)
|
||||
-- wip
|
||||
end
|
||||
File renamed without changes.
@@ -0,0 +1,6 @@
|
||||
if GetResourceState('qb-weathersync') ~= 'started' then return end
|
||||
Weather = {}
|
||||
|
||||
Weather.ToggleSync = function(src, toggle)
|
||||
-- wip
|
||||
end
|
||||
@@ -1,108 +0,0 @@
|
||||
Utility = Utility or {}
|
||||
|
||||
local activePlacementProp = nil
|
||||
lib.locale()
|
||||
|
||||
-- Object placer --
|
||||
local placementText = {
|
||||
locale('place_object_place'),
|
||||
locale('place_object_cancel'),
|
||||
locale('place_object_scroll_up'),
|
||||
locale('place_object_scroll_down')
|
||||
}
|
||||
|
||||
local function finishPlacing()
|
||||
Bridge.Notify.HideHelpText()
|
||||
if activePlacementProp == nil then return end
|
||||
DeleteObject(activePlacementProp)
|
||||
activePlacementProp = nil
|
||||
end
|
||||
|
||||
Utility.PlaceObject = function(object, distance, snapToGround, allowedMats, offset)
|
||||
if activePlacementProp then return end
|
||||
|
||||
if not object then Prints.Error('no_prop_defined') end
|
||||
|
||||
local propObject = type(object) == 'string' and joaat(object) or object
|
||||
local heading = 0.0
|
||||
local checkDist = distance or 10.0
|
||||
|
||||
Utility.LoadModel(propObject)
|
||||
|
||||
activePlacementProp = CreateObject(propObject, 1.0, 1.0, 1.0, false, true, true)
|
||||
SetModelAsNoLongerNeeded(propObject)
|
||||
SetEntityAlpha(activePlacementProp, 150, false)
|
||||
SetEntityCollision(activePlacementProp, false, false)
|
||||
SetEntityInvincible(activePlacementProp, true)
|
||||
FreezeEntityPosition(activePlacementProp, true)
|
||||
|
||||
Bridge.Notify.ShowHelpText(type(placementText) == 'table' and table.concat(placementText) or placementText, {
|
||||
position = "left-center",
|
||||
})
|
||||
|
||||
local outLine = false
|
||||
|
||||
while activePlacementProp do
|
||||
--local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4)
|
||||
--local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4, nil)
|
||||
local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4)
|
||||
if hit then
|
||||
if offset then
|
||||
coords += offset
|
||||
end
|
||||
|
||||
SetEntityCoords(activePlacementProp, coords.x, coords.y, coords.z, false, false, false, false)
|
||||
local distCheck = #(GetEntityCoords(cache.ped) - coords)
|
||||
SetEntityHeading(activePlacementProp, heading)
|
||||
|
||||
if snapToGround then
|
||||
PlaceObjectOnGroundProperly(activePlacementProp)
|
||||
end
|
||||
|
||||
if outLine then
|
||||
outLine = false
|
||||
SetEntityDrawOutline(activePlacementProp, false)
|
||||
end
|
||||
|
||||
if (allowedMats and not allowedMats[materialHash]) or distCheck >= checkDist then
|
||||
if not outLine then
|
||||
outLine = true
|
||||
SetEntityDrawOutline(activePlacementProp, true)
|
||||
end
|
||||
end
|
||||
|
||||
if IsControlJustReleased(0, 38) then
|
||||
if not outLine and (not allowedMats or allowedMats[materialHash]) and distCheck < checkDist then
|
||||
finishPlacing()
|
||||
|
||||
return coords, heading
|
||||
end
|
||||
end
|
||||
|
||||
if IsControlJustReleased(0, 73) then
|
||||
finishPlacing()
|
||||
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
if IsControlJustReleased(0, 14) then
|
||||
heading = heading + 5
|
||||
if heading > 360 then heading = 0.0 end
|
||||
end
|
||||
|
||||
if IsControlJustReleased(0, 15) then
|
||||
heading = heading - 5
|
||||
if heading < 0 then
|
||||
heading = 360.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Utility.StopPlacing = function()
|
||||
if not activePlacementProp then return end
|
||||
finishPlacing()
|
||||
end
|
||||
|
||||
-- This is derrived and slightly altered from its creator and licensed under GPL-3.0 license Author:Zoo, the original is located here https://github.com/Renewed-Scripts/Renewed-Lib/tree/main
|
||||
@@ -1,298 +0,0 @@
|
||||
Utility = Utility or {}
|
||||
local blipIDs = {}
|
||||
local spawnedPeds = {}
|
||||
local ActivePoints = {}
|
||||
lib.locale()
|
||||
|
||||
Utility.CreateVehicle = function(model, coords, heading, networked)
|
||||
if networked == nil then networked = true end
|
||||
Utility.LoadModel(model)
|
||||
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
|
||||
local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, networked, false)
|
||||
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
|
||||
SetVehicleNeedsToBeHotwired(vehicle, false)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
SetVehRadioStation(vehicle, "OFF")
|
||||
return vehicle, { networkid = NetworkGetNetworkIdFromEntity(vehicle) or 0, coords = GetEntityCoords(vehicle), heading = GetEntityHeading(vehicle), }
|
||||
end
|
||||
|
||||
Utility.StartBusySpinner = function(text)
|
||||
AddTextEntry(text, text)
|
||||
BeginTextCommandBusyString(text)
|
||||
AddTextComponentSubstringPlayerName(text)
|
||||
EndTextCommandBusyString(0)
|
||||
end
|
||||
|
||||
Utility.StopBusySpinner = function()
|
||||
if BusyspinnerIsOn() then BusyspinnerOff() end
|
||||
end
|
||||
|
||||
Utility.CreateProp = function(model, coords, heading, networked)
|
||||
if networked == nil then networked = true end
|
||||
Utility.LoadModel(model)
|
||||
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
|
||||
local propEntity = CreateObject(model, coords.x, coords.y, coords.z, networked, false, false)
|
||||
SetEntityHeading(propEntity, heading)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
return propEntity
|
||||
end
|
||||
|
||||
Utility.CreateBlip = function(coords, sprite, color, scale, label, shortRange)
|
||||
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
|
||||
SetBlipSprite(blip, sprite or 8)
|
||||
SetBlipColour(blip, color or 3)
|
||||
SetBlipScale(blip, scale or 0.8)
|
||||
SetBlipAsShortRange(blip, shortRange)
|
||||
AddTextEntry(label, label)
|
||||
BeginTextCommandSetBlipName(label)
|
||||
EndTextCommandSetBlipName(blip)
|
||||
table.insert(blipIDs, blip)
|
||||
return blip
|
||||
end
|
||||
|
||||
Utility.RemoveBlip = function(blip)
|
||||
local success = false
|
||||
for i, storedBlip in ipairs(blipIDs) do
|
||||
if storedBlip == blip then
|
||||
RemoveBlip(blip)
|
||||
table.remove(blipIDs, i)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
||||
Utility.LoadModel = function(model)
|
||||
if type(model) ~= 'number' then model = joaat(model) end
|
||||
if not IsModelValid(model) and not IsModelInCdimage(model) then return false end
|
||||
RequestModel(model)
|
||||
local count = 0
|
||||
while not HasModelLoaded(model) and count < 30000 do
|
||||
Wait(0)
|
||||
count = count + 1
|
||||
end
|
||||
return HasModelLoaded(model)
|
||||
end
|
||||
|
||||
Utility.CreatePed = function(model, coords, heading, networked, clothing)
|
||||
if networked == nil then networked = true end
|
||||
Utility.LoadModel(model)
|
||||
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
|
||||
local spawnedEntity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, networked, false)
|
||||
if clothing then
|
||||
for componentID, v in pairs(clothing) do
|
||||
SetPedComponentVariation(spawnedEntity, componentID, v[1], v[2], 0)
|
||||
end
|
||||
end
|
||||
FreezeEntityPosition(spawnedEntity, true)
|
||||
SetEntityInvincible(spawnedEntity, true)
|
||||
SetBlockingOfNonTemporaryEvents(spawnedEntity, true)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
table.insert(spawnedPeds, spawnedEntity)
|
||||
return spawnedEntity
|
||||
end
|
||||
|
||||
Utility.RemovePed = function(entity)
|
||||
local success = false
|
||||
DeleteEntity(entity)
|
||||
for i, storedEntity in ipairs(spawnedPeds) do
|
||||
if storedEntity == entity then
|
||||
table.remove(spawnedPeds, i)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
||||
Utility.NativeInputMenu = function(text, length)
|
||||
local maxLength = Math.Clamp(length, 1, 50)
|
||||
local menutText = text or 'enter text'
|
||||
AddTextEntry(menutText, menutText)
|
||||
DisplayOnscreenKeyboard(1, menutText, "", "", "", "", "", maxLength)
|
||||
while(UpdateOnscreenKeyboard() == 0) do
|
||||
DisableAllControlActions(0)
|
||||
Wait(0)
|
||||
end
|
||||
if(GetOnscreenKeyboardResult()) then
|
||||
local result = GetOnscreenKeyboardResult()
|
||||
return result
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
Utility.GetEntitySkinData = function(entity)
|
||||
local skinData = {}
|
||||
skinData.clothing = {}
|
||||
for i = 0, 11 do
|
||||
skinData.clothing[i] = {GetPedDrawableVariation(entity, i), GetPedTextureVariation(entity, i)}
|
||||
end
|
||||
return skinData
|
||||
end
|
||||
|
||||
Utility.SetEntitySkinData = function(entity, skinData)
|
||||
for i = 0, 11 do
|
||||
SetPedComponentVariation(entity, i, skinData.clothing[i][1], skinData.clothing[i][2], 0)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Utility.NativeAlert = function(data)
|
||||
local message = data.message or 'No message provided'
|
||||
local coords = data.coords or GetEntityCoords(cache.ped)
|
||||
local job = data.job
|
||||
local scale = data.scale or 0.8
|
||||
local sprite = data.sprite or 1
|
||||
TriggerServerEvent('community_bridge:server:alert', {message = message, coords = coords, job = job, scale = scale, sprite = sprite})
|
||||
end
|
||||
|
||||
Utility.ReloadSkin = function()
|
||||
local skinData = Utility.GetEntitySkinData(cache.ped)
|
||||
Utility.SetEntitySkinData(cache.ped, skinData)
|
||||
for _, props in pairs(GetGamePool("CObject")) do
|
||||
if IsEntityAttachedToEntity(cache.ped, props) then
|
||||
SetEntityAsMissionEntity(props, true, true)
|
||||
DeleteObject(props)
|
||||
DeleteEntity(props)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Utility.RestoreAppearance = function(data)
|
||||
return Utility.SetEntitySkinData(cache.ped, data)
|
||||
end
|
||||
|
||||
Utility.HelpText = function(text, duration)
|
||||
AddTextEntry(text, text)
|
||||
BeginTextCommandDisplayHelp(text)
|
||||
EndTextCommandDisplayHelp(0, false, true, duration or 5000)
|
||||
end
|
||||
|
||||
Utility.NotifyText = function(text)
|
||||
AddTextEntry(text, text)
|
||||
SetNotificationTextEntry(text)
|
||||
DrawNotification(false, true)
|
||||
end
|
||||
|
||||
Utility.RequestAnimDict = function(dict)
|
||||
RequestAnimDict(dict)
|
||||
local count = 0
|
||||
while not HasAnimDictLoaded(dict) and count < 30000 do
|
||||
Wait(0)
|
||||
count = count + 1
|
||||
end
|
||||
return HasAnimDictLoaded(dict)
|
||||
end
|
||||
|
||||
Utility.TeleportPlayer = function(coords, conditionFunction, afterTeleportFunction)
|
||||
if conditionFunction ~= nil then
|
||||
if not conditionFunction() then
|
||||
return
|
||||
end
|
||||
end
|
||||
DoScreenFadeOut(2500)
|
||||
Wait(2500)
|
||||
SetEntityCoords(cache.ped, coords.x, coords.y, coords.z, false, false, false, false)
|
||||
if coords.w then
|
||||
SetEntityHeading(cache.ped, coords.w)
|
||||
end
|
||||
FreezeEntityPosition(cache.ped, true)
|
||||
local count = 0
|
||||
while not HasCollisionLoadedAroundEntity(cache.ped) and count <= 30000 do
|
||||
RequestCollisionAtCoord(coords.x, coords.y, coords.z)
|
||||
Wait(0)
|
||||
count = count + 1
|
||||
end
|
||||
FreezeEntityPosition(cache.ped, false)
|
||||
DoScreenFadeIn(1000)
|
||||
if afterTeleportFunction ~= nil then
|
||||
afterTeleportFunction()
|
||||
end
|
||||
end
|
||||
|
||||
Utility.GetEntityHashFromModel = function(model)
|
||||
if type(model) ~= 'number' then model = joaat(model) end
|
||||
return model
|
||||
end
|
||||
|
||||
Utility.GetClosestPlayer = function(coords, distanceScope, includeMe)
|
||||
local players = GetActivePlayers()
|
||||
local closestPlayer = 0
|
||||
local selfPed = cache.ped
|
||||
local selfCoords = coords or GetEntityCoords(cache.ped)
|
||||
local closestDistance = distanceScope or 5
|
||||
|
||||
for _, player in ipairs(players) do
|
||||
local playerPed = GetPlayerPed(player)
|
||||
if includeMe or playerPed ~= selfPed then
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
local distance = #(selfCoords - playerCoords)
|
||||
if closestDistance == -1 or distance < closestDistance then
|
||||
closestPlayer = player
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer)
|
||||
end
|
||||
|
||||
-- register points
|
||||
Utility.RegisterPoint = function(pointCoords, pointDistance, pointOnEnter, pointOnExit)
|
||||
local enterZone = lib.points.new({
|
||||
coords = pointCoords,
|
||||
distance = pointDistance,
|
||||
onEnter = function(self)
|
||||
pointOnEnter(self)
|
||||
end,
|
||||
onExit = function(self)
|
||||
pointOnExit(self)
|
||||
end,
|
||||
})
|
||||
local pointID = Utility.CreateUniqueId(nil, 5, nil)
|
||||
ActivePoints[pointID] = enterZone
|
||||
return enterZone, pointID
|
||||
end
|
||||
|
||||
-- Function to retrieve the enterZone using pointID
|
||||
Utility.GetPointById = function(pointID)
|
||||
return ActivePoints[pointID]
|
||||
end
|
||||
|
||||
Utility.RemovePoint = function(pointID)
|
||||
local point = ActivePoints[pointID]
|
||||
if point then
|
||||
--print("Removing point with ID " .. pointID)
|
||||
point:remove() -- Call the remove method on the point (ensure this method stops all event listeners)
|
||||
ActivePoints[pointID] = nil -- Remove from ActivePoints table
|
||||
--print("Point removed successfully.")
|
||||
return true
|
||||
else
|
||||
--print("Point with ID " .. pointID .. " not found.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
AddEventHandler('onResourceStop', function(resource)
|
||||
if resource == GetCurrentResourceName() then
|
||||
for _, blip in pairs(blipIDs) do
|
||||
if DoesBlipExist(blip.id) then
|
||||
RemoveBlip(blip.id)
|
||||
end
|
||||
end
|
||||
for _, ped in pairs(spawnedPeds) do
|
||||
if DoesEntityExist(ped) then
|
||||
DeleteEntity(ped)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('community_bridge:client:alert', function(data)
|
||||
local blip = Utility.CreateBlip(data.coords, data.sprite, 3, data.scale, data.message, true)
|
||||
SetTimeout(40000, function()
|
||||
Utility.RemoveBlip(blip)
|
||||
end)
|
||||
end)
|
||||
@@ -1,38 +0,0 @@
|
||||
Utility = Utility or {}
|
||||
|
||||
function Utility.VersionChecker(repoPath)
|
||||
local resource = repoPath:match("([^/]+)$")
|
||||
if not resource then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end
|
||||
|
||||
local version = GetResourceMetadata(resource, "version", 0)
|
||||
if not version then return Prints.Error(('^1Unable to determine current resource version for %s ^0'):format(resource)) end
|
||||
|
||||
version = version:match('%d+%.%d+%.%d+')
|
||||
if not version then return Prints.Error(('^1Invalid version format for %s ^0'):format(resource)) end
|
||||
|
||||
local username, reponame = repoPath:match("([^/]+)/([^/]+)")
|
||||
if not username or not reponame then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end
|
||||
PerformHttpRequest(('https://api.github.com/repos/%s/%s/releases/latest'):format(username, reponame), function(status, response)
|
||||
local failure = ('^1Unable locate github repo for resource %s ^0'):format(resource)
|
||||
|
||||
if status ~= 200 then return Prints.Error(failure) end
|
||||
response = json.decode(response)
|
||||
|
||||
if response.prerelease then return Prints.Error(failure) end
|
||||
|
||||
local latest = response.tag_name:match('%d+%.%d+%.%d+')
|
||||
if not latest then return Prints.Error(failure) end
|
||||
|
||||
if latest == version then return print(('^2 %s is on the latest version.^0'):format(resource)) end
|
||||
local currentVersion, latestVersion = version:gsub('%D', ''), latest:gsub('%D', '')
|
||||
|
||||
if currentVersion < latestVersion then
|
||||
return print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from the GitHub release page.^7\r\n%s'):format(resource, version, response.html_url))
|
||||
end
|
||||
end, 'GET')
|
||||
end
|
||||
|
||||
AddEventHandler('onResourceStart', function(resourceName)
|
||||
if GetCurrentResourceName() ~= resourceName then return end
|
||||
Utility.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge")
|
||||
end)
|
||||
@@ -1,50 +0,0 @@
|
||||
Utility = Utility or {}
|
||||
|
||||
local WebhookURL = BridgeServerConfig.WebhookURL
|
||||
local LogoForEmbed = BridgeServerConfig.WebhookImage
|
||||
|
||||
Utility.SendLog = function(src, message)
|
||||
if not src or not message then return end
|
||||
if BridgeServerConfig.LogSystem == "builtin" then
|
||||
PerformHttpRequest(WebhookURL, function(err, text, headers) end, 'POST', json.encode(
|
||||
{
|
||||
username = "Community_Bridge's Logger",
|
||||
avatar_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024',
|
||||
embeds = {
|
||||
{
|
||||
color = "15769093",
|
||||
title = GetCurrentResourceName(),
|
||||
url = 'https://discord.gg/wsPAK5mEPg',
|
||||
--description = message,
|
||||
thumbnail = { url = LogoForEmbed },
|
||||
fields = {
|
||||
{
|
||||
name = '**Player ID**',
|
||||
value = src,
|
||||
inline = true,
|
||||
},
|
||||
{
|
||||
name = '**Player Identifier**',
|
||||
value = Framework.GetPlayerIdentifier(src),
|
||||
inline = true,
|
||||
},
|
||||
{
|
||||
name = 'Log Message',
|
||||
value = "```"..message.."```",
|
||||
inline = false,
|
||||
},
|
||||
},
|
||||
timestamp = os.date('!%Y-%m-%dT%H:%M:%S'),
|
||||
footer = {
|
||||
text = "Community_Bridge | "..GetCurrentResourceName(),
|
||||
icon_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024',
|
||||
},
|
||||
}
|
||||
}
|
||||
}), { ['Content-Type']= 'application/json' })
|
||||
elseif BridgeServerConfig.LogSystem == "qb" then
|
||||
return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message)
|
||||
elseif BridgeServerConfig.LogSystem == "ox" then
|
||||
return exports.ox_lib:logger(src, GetCurrentResourceName(), message)
|
||||
end
|
||||
end
|
||||
@@ -1,70 +0,0 @@
|
||||
Utility = Utility or {}
|
||||
|
||||
local lootTables = {}
|
||||
|
||||
Utility.RegisterLootTable = function(name, items)
|
||||
local repackedTable = {}
|
||||
for k, v in pairs(items) do
|
||||
table.insert(repackedTable, {
|
||||
name = k,
|
||||
min = v.min,
|
||||
max = v.max,
|
||||
chance = v.chance,
|
||||
tier = v.tier,
|
||||
item = v.item,
|
||||
metadata = v.metadata
|
||||
})
|
||||
end
|
||||
lootTables[name] = repackedTable
|
||||
return lootTables[name]
|
||||
end
|
||||
|
||||
Utility.GetLootTable = function(name)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
return lootTables[name] or {}
|
||||
end
|
||||
|
||||
Utility.GetRandomItem = function(name, tier, randomNumber)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
if tier == nil then tier = 1 end
|
||||
local lootTable = lootTables[name] or {}
|
||||
math.randomseed(GetGameTimer())
|
||||
local chance = randomNumber or math.random(1, 100)
|
||||
for _, v in pairs(lootTable) do
|
||||
if v.chance <= chance and tier == v.tier then
|
||||
return { item = v.item, metadata = v.metadata, count = math.random(v.min, v.max), tier = v.tier, chance = v.chance}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Utility.GetRandomItems = function(name, tier, randomNumber)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
if tier == nil then tier = 1 end
|
||||
local lootTable = Utility.GetLootTable(name)
|
||||
math.randomseed(GetGameTimer())
|
||||
local chance = randomNumber or math.random(1, 100)
|
||||
local items = {}
|
||||
for _, v in pairs(lootTable) do
|
||||
if v.chance <= chance and tier == v.tier then
|
||||
table.insert(items,{item = v.item, metadata = v.metadata, count = math.random(v.min, v.max), tier = v.tier, chance = v.chance})
|
||||
end
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
Utility.GetRandomItemsWithLimit = function(name, tier, randomNumber)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
if tier == nil then tier = 1 end
|
||||
local lootTable = Utility.GetLootTable(name)
|
||||
math.randomseed(GetGameTimer())
|
||||
local chance = randomNumber or math.random(1, 100)
|
||||
local items = {}
|
||||
for k = #lootTable, 1, -1 do
|
||||
local v = lootTable[k]
|
||||
if chance <= v.chance and tier == v.tier then
|
||||
table.insert(items, {v.item, v.metadata, math.random(v.min, v.max), v.tier, v.chance})
|
||||
table.remove(lootTable, k)
|
||||
end
|
||||
end
|
||||
return items
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
RegisterNetEvent("community_bridge:server:alert", function(data)
|
||||
local playersByJob = Framework.GetPlayersByJob(data.job)
|
||||
for _, src in pairs(playersByJob) do
|
||||
TriggerClientEvent("community_bridge:client:alert", src, data)
|
||||
end
|
||||
end)
|
||||
@@ -1,145 +0,0 @@
|
||||
Callbacks = {}
|
||||
cbData = {}
|
||||
Callback = Callback or {}
|
||||
|
||||
local resource = GetCurrentResourceName() or 'unknown'
|
||||
|
||||
local clientToServerName = resource .. ':server:CS:TriggerCallback'
|
||||
local clientToServerBackToClientName = resource .. ':client:CSC:TriggerCallback'
|
||||
|
||||
|
||||
local serverToClientName = resource .. ':client:SC:TriggerCallback'
|
||||
local serverToClientBackToServerName = resource .. ':server:SCS:TriggerCallback'
|
||||
|
||||
|
||||
if not IsDuplicityVersion() then goto client end
|
||||
|
||||
|
||||
|
||||
-- -- -- -- -- -- -- -- -- --
|
||||
-- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄
|
||||
-- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄
|
||||
-- -- -- -- -- -- -- -- -- --
|
||||
|
||||
|
||||
|
||||
-- client to server rebound
|
||||
function Callback.Register(name, callback, all)
|
||||
Callback[name] = {
|
||||
callback = callback,
|
||||
toAll = all
|
||||
}
|
||||
end
|
||||
|
||||
RegisterNetEvent(clientToServerName, function(name, ...)
|
||||
local src = source
|
||||
local data = Callback[name]
|
||||
if not data then return end
|
||||
local func = data.callback
|
||||
if not func then return end
|
||||
local toAll = data.toAll and -1 or src
|
||||
local cb = function(...)
|
||||
TriggerClientEvent(clientToServerBackToClientName, toAll, name, ...)
|
||||
end
|
||||
func(src, cb, ...)
|
||||
end)
|
||||
-----------------------------
|
||||
|
||||
-- server to client rebound
|
||||
|
||||
function Callback.Trigger(name, src, func, ...)
|
||||
if src == nil then src = -1 end
|
||||
local p = promise.new()
|
||||
cbData[name] = {cb = func, p = p}
|
||||
if type(src) == 'table' then
|
||||
for i, d in pairs(src) do
|
||||
TriggerClientEvent(serverToClientName, tonumber(d), name, ...)
|
||||
end
|
||||
return Citizen.Await(p)
|
||||
end
|
||||
TriggerClientEvent(serverToClientName, tonumber(src), name, ...)
|
||||
return Citizen.Await(p)
|
||||
end
|
||||
|
||||
RegisterNetEvent(serverToClientBackToServerName, function(name, ...)
|
||||
print('Rebound')
|
||||
local data = cbData[name]
|
||||
if not data then return end
|
||||
local func = data.cb
|
||||
if not func then return end
|
||||
data.p:resolve(func(...) or true)
|
||||
cbData[name] = nil
|
||||
end)
|
||||
-----------------------------
|
||||
exports('RegisterCallback', Callback.Register)
|
||||
exports('TriggerCallback', Callback.Trigger)
|
||||
|
||||
|
||||
-- -- -- -- -- -- -- -- -- --
|
||||
-- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀
|
||||
-- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █
|
||||
-- -- -- -- -- -- -- -- -- --
|
||||
if IsDuplicityVersion() then return end
|
||||
::client::
|
||||
|
||||
|
||||
cbRebounds = {}
|
||||
function Callback.Register(name, callback, all)
|
||||
Callback[name] = {
|
||||
callback = callback,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
function Callback.RegisterRebound(name, callback)
|
||||
cbRebounds[name] = callback
|
||||
end
|
||||
|
||||
|
||||
-- client to server rebound
|
||||
function Callback.Trigger(name, func, ...)
|
||||
local p = promise.new()
|
||||
TriggerServerEvent(clientToServerName, name, ...)
|
||||
cbData[name] = {cb = func, p = p}
|
||||
CreateThread(function()
|
||||
Wait(5000)
|
||||
if cbData[name] then
|
||||
cbData[name].p:resolve()
|
||||
cbData[name] = nil
|
||||
end
|
||||
end)
|
||||
print('Triggered')
|
||||
return Citizen.Await(p)
|
||||
end
|
||||
|
||||
RegisterNetEvent(clientToServerBackToClientName, function(name, ...)
|
||||
local clientRebound = cbRebounds[name]
|
||||
if clientRebound then
|
||||
clientRebound(...)
|
||||
end
|
||||
local data = cbData[name]
|
||||
if not data then return end
|
||||
local func = data.cb
|
||||
if not func then return end
|
||||
data.p:resolve(func(...) or true)
|
||||
cbData[name] = nil
|
||||
end)
|
||||
-----------------------------
|
||||
|
||||
-- server to client rebound
|
||||
RegisterNetEvent(serverToClientName, function(name, ...)
|
||||
local data = Callback[name]
|
||||
if not data then return end
|
||||
local func = data.callback
|
||||
if not func then return end
|
||||
local cb = function(...)
|
||||
TriggerServerEvent(serverToClientBackToServerName, name, ...)
|
||||
end
|
||||
func(cb, ...)
|
||||
end)
|
||||
-----------------------------
|
||||
|
||||
exports('RegisterCallback', Callback.Register)
|
||||
exports('RegisterRebound', Callback.RegisterRebound)
|
||||
exports('TriggerCallback', Callback.Trigger)
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
Prints = Prints or {}
|
||||
|
||||
local function printMessage(level, color, message)
|
||||
if type(message) == 'table' then
|
||||
message = json.encode(message)
|
||||
end
|
||||
print(color .. '[' .. level .. ']:', message)
|
||||
end
|
||||
|
||||
Prints.Info = function(message)
|
||||
printMessage('INFO', '^5', message)
|
||||
end
|
||||
|
||||
Prints.Warn = function(message)
|
||||
printMessage('WARN', '^3', message)
|
||||
end
|
||||
|
||||
Prints.Error = function(message)
|
||||
printMessage('ERROR', '^1', message)
|
||||
end
|
||||
|
||||
Prints.Debug = function(message)
|
||||
printMessage('DEBUG', '^2', message)
|
||||
end
|
||||
@@ -1,108 +0,0 @@
|
||||
Table = {}
|
||||
|
||||
Table.CheckPopulated = function(tbl)
|
||||
if #tbl == 0 then
|
||||
for _, _ in pairs(tbl) do
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Table.DeepClone = function(tbl, out, omit)
|
||||
if type(tbl) ~= "table" then return tbl end
|
||||
local new = out or {}
|
||||
omit = omit or {}
|
||||
for key, data in pairs(tbl) do
|
||||
if not omit[key] then
|
||||
if type(data) == "table" then
|
||||
new[key] = Table.DeepClone(data)
|
||||
else
|
||||
new[key] = data
|
||||
end
|
||||
end
|
||||
end
|
||||
return new
|
||||
end
|
||||
|
||||
Table.TableContains = function(tbl, search, nested)
|
||||
for _, v in pairs(tbl) do
|
||||
if nested and type(v) == "table" then
|
||||
return Table.TableContains(v, search)
|
||||
elseif v == search then
|
||||
return true, v
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
Table.TableContainsKey = function(tbl, search)
|
||||
for k, _ in pairs(tbl) do
|
||||
if k == search then
|
||||
return true, k
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
Table.GetClosest = function(coords, tbl)
|
||||
local closestPoint = nil
|
||||
local dist = math.huge
|
||||
for k, v in pairs(tbl) do
|
||||
local c = v.coords
|
||||
local d = c and #(coords - c)
|
||||
if d < dist then
|
||||
dist = d
|
||||
closestPoint = v
|
||||
end
|
||||
end
|
||||
return closestPoint
|
||||
end
|
||||
|
||||
Table.FindFirstUnoccupiedSlot = function(tbl)
|
||||
local occupiedSlots = {}
|
||||
for _, v in pairs(tbl) do
|
||||
occupiedSlots[v.slot] = true
|
||||
end
|
||||
for i = 1, BridgeServerConfig.MaxInventorySlots do
|
||||
if not occupiedSlots[i] then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
Table.Append = function(tbl1, tbl2)
|
||||
for _, v in pairs(tbl2) do
|
||||
table.insert(tbl1, v)
|
||||
end
|
||||
return tbl1
|
||||
end
|
||||
|
||||
Table.Split = function(tbl, size)
|
||||
local new1 = {}
|
||||
local new2 = {}
|
||||
size = size or math.floor(#tbl / 2)
|
||||
|
||||
if size > #tbl then
|
||||
assert(false, "Size is greater than the length of the table.")
|
||||
end
|
||||
for i = 1, size do
|
||||
table.insert(new1, tbl[i])
|
||||
end
|
||||
for i = size + 1, #tbl do
|
||||
table.insert(new2, tbl[i])
|
||||
end
|
||||
return new1, new2
|
||||
end
|
||||
|
||||
Table.Shuffle = function(tbl)
|
||||
for i = #tbl, 2, -1 do
|
||||
local j = math.random(i)
|
||||
tbl[i], tbl[j] = tbl[j], tbl[i]
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
return Table
|
||||
@@ -1,25 +0,0 @@
|
||||
Utility = Utility or {}
|
||||
-- for unique ids
|
||||
Utility.CreateUniqueId = function(tbl, len, pattern) -- both optional
|
||||
tbl = tbl or {} -- table to check uniqueness. Ids to check against must be the key to the tables value
|
||||
len = len or 8
|
||||
|
||||
local id = ""
|
||||
for i = 1, len do
|
||||
local char = ""
|
||||
if pattern then
|
||||
char = pattern:sub(math.random(1, #pattern), math.random(1, #pattern))
|
||||
else
|
||||
char = math.random(1, 2) == 1 and string.char(math.random(65, 90)) or math.random(0, 9) -- CAP letter and number
|
||||
end
|
||||
id = id .. char
|
||||
end
|
||||
if tbl[id] then
|
||||
return Utility.CreateUniqueId(tbl, len, pattern)
|
||||
end
|
||||
return id
|
||||
end
|
||||
|
||||
Utility.RandomString = function()
|
||||
return Utility.CreateUniqueId(nil, 14, nil)
|
||||
end
|
||||
Reference in new issue
Block a user