forked from Simnation/Main
ed
This commit is contained in:
parent
dd9fcf9ecf
commit
364b3e9835
5 changed files with 164 additions and 155 deletions
|
@ -1246,7 +1246,12 @@ CodeStudio.Products = {
|
|||
itemPrice = 50,
|
||||
itemInfo = "",
|
||||
},
|
||||
|
||||
['vehicletrackertablet'] = {
|
||||
itemName = "Fahrzeugtracker Tablet",
|
||||
itemStock = 150,
|
||||
itemPrice = 50,
|
||||
itemInfo = "",
|
||||
},
|
||||
}
|
||||
},
|
||||
['police_weapons'] = {
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
Config = {}
|
||||
Config.lockerProps = {'h4_prop_h4_ld_keypad_01b'} -- Props you can access storage
|
||||
Config.Locations = {
|
||||
[1] = {
|
||||
name = 'SD',
|
||||
location = vector3(1827.6656, 3680.0276, 34.4050),
|
||||
radius = 8.0,
|
||||
maxweight = 30000,
|
||||
slots = 32.0,
|
||||
},
|
||||
[2] = {
|
||||
name = 'Lagerhaus Sandy',
|
||||
location = vector3(182.5523, 2792.6450, 45.6404),
|
||||
radius = 8.0,
|
||||
maxweight = 400000,
|
||||
slots = 32.0,
|
||||
},
|
||||
}
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
|
||||
exports['qb-target']:AddTargetModel(Config.lockerProps, {
|
||||
options = {
|
||||
{
|
||||
id = 1,
|
||||
icon = "fa-solid fa-lock",
|
||||
label = "Open personal locker",
|
||||
action = function(entity)
|
||||
TriggerEvent('rj-lockers:openLocker', entity)
|
||||
end,
|
||||
},
|
||||
},
|
||||
distance = 1.5
|
||||
})
|
||||
|
||||
end)
|
||||
|
||||
RegisterNetEvent('rj-lockers:openLocker', function(entity)
|
||||
|
||||
local PlayerData = QBCore.Functions.GetPlayerData()
|
||||
local lockerLoc = GetEntityCoords(entity)
|
||||
local accessGranted = false
|
||||
|
||||
for x, v in pairs(Config.Locations) do
|
||||
if GetDistanceBetweenCoords(lockerLoc, v.location) < v.radius then
|
||||
TriggerServerEvent("inventory:server:OpenInventory", "stash", v.name .. "_" .. PlayerData.citizenid, {maxweight = v.maxweight, slots = v.slots})
|
||||
TriggerEvent("inventory:client:SetCurrentStash", v.name .. "_" .. PlayerData.citizenid)
|
||||
accessGranted = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not accessGranted then
|
||||
QBCore.Functions.Notify('You cannot access this locker', 'error', 5000)
|
||||
end
|
||||
|
||||
end)
|
|
@ -1,10 +0,0 @@
|
|||
fx_version 'cerulean'
|
||||
game 'gta5'
|
||||
|
||||
author 'RJ-Scripts'
|
||||
description 'rj-lockers for QBCore'
|
||||
version '1.0.0'
|
||||
|
||||
client_script {
|
||||
'client.lua',
|
||||
}
|
|
@ -2,6 +2,45 @@ local QBCore = exports[Config.CoreName]:GetCoreObject()
|
|||
local nvMode = 0
|
||||
local thermalMode = 0
|
||||
|
||||
-- Cache system for item checks
|
||||
local itemCheckCache = {}
|
||||
local lastCheckTime = {}
|
||||
local checkCooldown = 1000 -- 1 second cooldown between checks for the same item
|
||||
|
||||
-- Function to check if player has an item
|
||||
local function HasItem(itemName, callback)
|
||||
-- Check cache first (to avoid spamming the server)
|
||||
local currentTime = GetGameTimer()
|
||||
if itemCheckCache[itemName] ~= nil and lastCheckTime[itemName] and
|
||||
(currentTime - lastCheckTime[itemName]) < checkCooldown then
|
||||
callback(itemCheckCache[itemName])
|
||||
return
|
||||
end
|
||||
|
||||
-- Set up the callback
|
||||
local callbackRegistered = false
|
||||
local eventHandler = RegisterNetEvent('nightvision:itemCheckResult', function(checkedItem, hasItem)
|
||||
if checkedItem == itemName then
|
||||
itemCheckCache[itemName] = hasItem
|
||||
lastCheckTime[itemName] = GetGameTimer()
|
||||
callback(hasItem)
|
||||
callbackRegistered = true
|
||||
RemoveEventHandler(eventHandler)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Request the check from server
|
||||
TriggerServerEvent('nightvision:checkItem', itemName)
|
||||
|
||||
-- Set a timeout to prevent hanging if something goes wrong
|
||||
SetTimeout(1000, function()
|
||||
if not callbackRegistered then
|
||||
RemoveEventHandler(eventHandler)
|
||||
callback(false)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Funktion zum Prüfen des Charaktergeschlechts
|
||||
local function IsPedMale(ped)
|
||||
return GetEntityModel(ped) == `mp_m_freemode_01`
|
||||
|
@ -32,7 +71,8 @@ end
|
|||
RegisterCommand('toggleNV', function()
|
||||
local ped = PlayerPedId()
|
||||
|
||||
if QBCore.Functions.HasItem(Config.NVItem) then
|
||||
HasItem(Config.NVItem, function(hasItem)
|
||||
if hasItem then
|
||||
local gender = IsPedMale(ped) and "male" or "female"
|
||||
local glasses = Config.Glasses[gender]
|
||||
|
||||
|
@ -79,13 +119,15 @@ RegisterCommand('toggleNV', function()
|
|||
else
|
||||
QBCore.Functions.Notify('Du hast kein Nachtsichtgerät!', 'error')
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Wärmebild-Befehl
|
||||
RegisterCommand('toggleThermal', function()
|
||||
local ped = PlayerPedId()
|
||||
|
||||
if QBCore.Functions.HasItem(Config.ThermalItem) then
|
||||
HasItem(Config.ThermalItem, function(hasItem)
|
||||
if hasItem then
|
||||
local gender = IsPedMale(ped) and "male" or "female"
|
||||
local glasses = Config.Glasses[gender]
|
||||
|
||||
|
@ -132,6 +174,7 @@ RegisterCommand('toggleThermal', function()
|
|||
else
|
||||
QBCore.Functions.Notify('Du hast kein Wärmebildgerät!', 'error')
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Tastenbelegungen registrieren
|
||||
|
@ -204,3 +247,6 @@ end)
|
|||
RegisterNetEvent('nightvision:toggleHelmet', function()
|
||||
TriggerEvent('nightvision:toggleGlasses', 'nightvision')
|
||||
end)
|
||||
|
||||
-- Register event handler for item check results
|
||||
RegisterNetEvent('nightvision:itemCheckResult')
|
||||
|
|
|
@ -1,8 +1,35 @@
|
|||
local QBCore = exports[Config.CoreName]:GetCoreObject()
|
||||
|
||||
-- Function to check if player has an item
|
||||
local function HasItem(source, itemName)
|
||||
local items = exports["tgiann-inventory"]:GetPlayerItems(source)
|
||||
if not items then return false end
|
||||
|
||||
for _, item in pairs(items) do
|
||||
if item.name == itemName then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- Event for client to check if player has an item
|
||||
RegisterNetEvent('nightvision:checkItem', function(itemName)
|
||||
local src = source
|
||||
local hasItem = HasItem(src, itemName)
|
||||
TriggerClientEvent('nightvision:itemCheckResult', src, itemName, hasItem)
|
||||
end)
|
||||
|
||||
-- Register usable items
|
||||
QBCore.Functions.CreateUseableItem(Config.NVItem, function(source, item)
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player.Functions.GetItemByName(item.name) then
|
||||
if HasItem(source, item.name) then
|
||||
TriggerClientEvent('nightvision:toggleHelmet', source)
|
||||
end
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateUseableItem(Config.ThermalItem, function(source, item)
|
||||
if HasItem(source, item.name) then
|
||||
TriggerClientEvent('nightvision:toggleGlasses', source, 'thermal')
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue