resursa iteme vizibile pe corp cu admin menu + disable idle cam
- rv-itemsonback v2.0: afișare props pe corp din inventar (medikit etc.) - Admin menu /itemsonback cu ox_lib (search items, adjust pos/rot, select bone) - Live preview cu auto-cleanup + /clearpreview emergency - Config persistent JSON (data/items.json) - Disable idle camera + idle animations (InvalidateIdleCam) - resources.cfg: safety net ensure qs-weaponsonback - fix(qs-inventory): Config.Genders[0]=Male pt QBCore compatibility
This commit is contained in:
127
resources/[framework]/[addons]/rv-itemsonback/server.lua
Normal file
127
resources/[framework]/[addons]/rv-itemsonback/server.lua
Normal file
@@ -0,0 +1,127 @@
|
||||
--[[
|
||||
rv-itemsonback — Server
|
||||
Gestionare configurări persistent (JSON), sync către clienți
|
||||
]]
|
||||
print('[rv-itemsonback] ^2Server script loading...^0')
|
||||
|
||||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
local savedItems = {}
|
||||
local dataFile = 'data/items.json'
|
||||
|
||||
-----------------------------------------
|
||||
-- Încarcă config din JSON
|
||||
-----------------------------------------
|
||||
local function LoadConfig()
|
||||
local file = LoadResourceFile(GetCurrentResourceName(), dataFile)
|
||||
if file then
|
||||
savedItems = json.decode(file) or {}
|
||||
print('[rv-itemsonback] Loaded ' .. #savedItems .. ' item configs')
|
||||
else
|
||||
savedItems = {
|
||||
-- Default: medikit
|
||||
{
|
||||
item = 'medikit',
|
||||
model = 'prop_ld_health_pack',
|
||||
bone = 11816,
|
||||
pos = { x = 0.15, y = -0.15, z = -0.05 },
|
||||
rot = { x = 0.0, y = 0.0, z = 0.0 }
|
||||
}
|
||||
}
|
||||
SaveConfig()
|
||||
print('[rv-itemsonback] Created default config with medikit')
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------
|
||||
-- Salvează config în JSON
|
||||
-----------------------------------------
|
||||
function SaveConfig()
|
||||
SaveResourceFile(GetCurrentResourceName(), dataFile, json.encode(savedItems), -1)
|
||||
end
|
||||
|
||||
-----------------------------------------
|
||||
-- Callback: trimite config-ul la client
|
||||
-----------------------------------------
|
||||
lib.callback.register('rv-itemsonback:getConfig', function(source)
|
||||
return savedItems
|
||||
end)
|
||||
|
||||
-----------------------------------------
|
||||
-- Callback: salvează un item nou/editat
|
||||
-----------------------------------------
|
||||
lib.callback.register('rv-itemsonback:saveItem', function(source, data)
|
||||
-- Verifică admin
|
||||
if not QBCore.Functions.HasPermission(source, 'god') and
|
||||
not QBCore.Functions.HasPermission(source, 'admin') and
|
||||
not IsPlayerAceAllowed(source, 'command') then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Caută dacă itemul există deja
|
||||
local found = false
|
||||
for i, item in ipairs(savedItems) do
|
||||
if item.item == data.item then
|
||||
savedItems[i] = data
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
savedItems[#savedItems + 1] = data
|
||||
end
|
||||
|
||||
SaveConfig()
|
||||
|
||||
-- Sync la toți clienții
|
||||
TriggerClientEvent('rv-itemsonback:syncConfig', -1, savedItems)
|
||||
return true
|
||||
end)
|
||||
|
||||
-----------------------------------------
|
||||
-- Callback: șterge un item
|
||||
-----------------------------------------
|
||||
lib.callback.register('rv-itemsonback:deleteItem', function(source, itemName)
|
||||
if not QBCore.Functions.HasPermission(source, 'god') and
|
||||
not QBCore.Functions.HasPermission(source, 'admin') and
|
||||
not IsPlayerAceAllowed(source, 'command') then
|
||||
return false
|
||||
end
|
||||
|
||||
for i, item in ipairs(savedItems) do
|
||||
if item.item == itemName then
|
||||
table.remove(savedItems, i)
|
||||
SaveConfig()
|
||||
TriggerClientEvent('rv-itemsonback:syncConfig', -1, savedItems)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end)
|
||||
|
||||
-----------------------------------------
|
||||
-- Sync la connect
|
||||
-----------------------------------------
|
||||
RegisterNetEvent('QBCore:Server:PlayerLoaded', function()
|
||||
local src = source
|
||||
TriggerClientEvent('rv-itemsonback:syncConfig', src, savedItems)
|
||||
end)
|
||||
|
||||
-----------------------------------------
|
||||
-- Comandă admin
|
||||
-----------------------------------------
|
||||
RegisterCommand('itemsonback', function(source)
|
||||
if source == 0 then return end -- consola
|
||||
if QBCore.Functions.HasPermission(source, 'god') or
|
||||
QBCore.Functions.HasPermission(source, 'admin') or
|
||||
IsPlayerAceAllowed(source, 'command') then
|
||||
TriggerClientEvent('rv-itemsonback:openMenu', source)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Nu ai permisiune', 'error')
|
||||
end
|
||||
end, false)
|
||||
|
||||
-----------------------------------------
|
||||
-- Init
|
||||
-----------------------------------------
|
||||
LoadConfig()
|
||||
Reference in New Issue
Block a user