ed
This commit is contained in:
parent
875c8448e1
commit
c81ae4bb6d
219 changed files with 8036 additions and 7 deletions
14
resources/[tools]/bl_idcard/client/events.lua
Normal file
14
resources/[tools]/bl_idcard/client/events.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
local Events = {}
|
||||
|
||||
Events.Receive = {
|
||||
loaded = 'idcard:loaded',
|
||||
resolveBaseUrl = 'idcard:resolveBaseUrl',
|
||||
}
|
||||
|
||||
Events.Send = {
|
||||
requestBaseUrl = 'idcard:requestBaseUrl',
|
||||
cardData = 'idcard:data',
|
||||
config = 'idcard:config',
|
||||
}
|
||||
|
||||
return Events
|
94
resources/[tools]/bl_idcard/client/init.lua
Normal file
94
resources/[tools]/bl_idcard/client/init.lua
Normal file
|
@ -0,0 +1,94 @@
|
|||
local utils = require "client.utils"
|
||||
local events = require "client.events"
|
||||
local config = require "shared.config"
|
||||
local callback = lib.callback
|
||||
local Send, Receive = events.Send, events.Receive
|
||||
local isCardOpen = false
|
||||
local cardObject = 0
|
||||
|
||||
---@param data IDInfo
|
||||
local function openCardPopup(data)
|
||||
isCardOpen = true
|
||||
utils.SendNUIEvent(Send.cardData, data)
|
||||
end
|
||||
|
||||
local function clearPed()
|
||||
local anim = config.animation
|
||||
local ped = cache.ped
|
||||
if DoesEntityExist(cardObject) then
|
||||
SetEntityAsMissionEntity(cardObject, true, true)
|
||||
DeleteEntity(cardObject)
|
||||
cardObject = 0
|
||||
end
|
||||
if IsEntityPlayingAnim(ped, anim.dict, anim.clip, 3) then
|
||||
StopAnimTask(ped, anim.dict, anim.clip, 1.0)
|
||||
end
|
||||
end
|
||||
|
||||
local function closeCardPopup()
|
||||
isCardOpen = false
|
||||
clearPed()
|
||||
utils.SendNUIEvent(Send.cardData, nil)
|
||||
end
|
||||
|
||||
---@param data IDInfo
|
||||
RegisterNetEvent('bl_idcard:open', function(data)
|
||||
openCardPopup(data)
|
||||
|
||||
local popupConfig = config.popup
|
||||
if popupConfig.autoclose ~= 0 then
|
||||
SetTimeout(popupConfig.autoclose, function()
|
||||
closeCardPopup()
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNUICallback(Receive.loaded, function(_, cb)
|
||||
cb(1)
|
||||
utils.SendNUIEvent(Send.config, config.idTypes)
|
||||
end)
|
||||
|
||||
callback.register('bl_idcard:use', function(itemName)
|
||||
if isCardOpen then return end
|
||||
local configType = config.items[itemName]
|
||||
local ped = cache.ped
|
||||
local prop = configType.prop
|
||||
if prop then
|
||||
local playerCoords = GetEntityCoords(ped)
|
||||
cardObject = CreateObject(prop, playerCoords.x, playerCoords.y, playerCoords.z + 0.2, true, true, true)
|
||||
local bone = GetPedBoneIndex(ped, 57005)
|
||||
AttachEntityToEntity(cardObject, ped, bone, 0.1000, 0.0200, -0.0300, -90.000, 170.000, 78.999, true, true, false, true, 1, true)
|
||||
SetModelAsNoLongerNeeded(cardObject)
|
||||
end
|
||||
|
||||
if not cache.vehicle then
|
||||
local anim = config.animation
|
||||
if anim then
|
||||
lib.requestAnimDict(anim.dict)
|
||||
TaskPlayAnim(ped, anim.dict, anim.clip, 1.0, 1.0, 10000, 63, 0.0, false, false, false)
|
||||
end
|
||||
end
|
||||
|
||||
SetTimeout(3000, function()
|
||||
clearPed()
|
||||
end)
|
||||
|
||||
local target = utils.GetPlayerLookingAt()
|
||||
|
||||
if not target then
|
||||
Framework.notify({
|
||||
title = "Nobody around",
|
||||
description = "Look at who you want to show it to."
|
||||
})
|
||||
return cache.serverId
|
||||
end
|
||||
|
||||
return target
|
||||
end)
|
||||
|
||||
callback.register('bl_idcard:cb:getMugShot', utils.GetMugShot)
|
||||
|
||||
RegisterCommand('closeidcard', closeCardPopup, false)
|
||||
|
||||
RegisterKeyMapping('closeidcard', 'Close ID Card Popup', 'keyboard', config.popup.key)
|
||||
|
58
resources/[tools]/bl_idcard/client/utils.lua
Normal file
58
resources/[tools]/bl_idcard/client/utils.lua
Normal file
|
@ -0,0 +1,58 @@
|
|||
local Utils = {}
|
||||
local events = require "client.events"
|
||||
local promiseId = nil
|
||||
|
||||
--- Used to send NUI events to the UI
|
||||
--- @param action string
|
||||
--- @param data any
|
||||
function Utils.SendNUIEvent(action, data)
|
||||
SendNUIMessage({
|
||||
action = action,
|
||||
data = data
|
||||
})
|
||||
end
|
||||
|
||||
RegisterNUICallback(events.Receive.resolveBaseUrl, function(url, cb)
|
||||
if not promiseId then return end
|
||||
promiseId:resolve(url)
|
||||
promiseId = nil
|
||||
cb(1)
|
||||
end)
|
||||
|
||||
function Utils.GetMugShot()
|
||||
if promiseId then return end
|
||||
|
||||
local ped = cache.ped
|
||||
local oldMask = GetPedDrawableVariation(ped, 1)
|
||||
local hasMask = oldMask ~= 0
|
||||
|
||||
if hasMask then
|
||||
SetPedComponentVariation(ped, 1, 0, 0, 2)
|
||||
end
|
||||
|
||||
local headShotHandle = RegisterPedheadshotTransparent(ped) or RegisterPedheadshot_3(ped)
|
||||
if not lib.waitFor(function()
|
||||
if IsPedheadshotReady(headShotHandle) and IsPedheadshotValid(headShotHandle) then return true end
|
||||
end, 'couldn\'t load mugshot', 10000) then return end
|
||||
|
||||
local headShotTxd = GetPedheadshotTxdString(headShotHandle)
|
||||
Utils.SendNUIEvent(events.Send.requestBaseUrl, headShotTxd)
|
||||
UnregisterPedheadshot(headShotHandle)
|
||||
|
||||
if hasMask then
|
||||
SetPedComponentVariation(ped, 1, oldMask, GetPedTextureVariation(ped, 1), 2)
|
||||
end
|
||||
|
||||
promiseId = promise.new()
|
||||
return Citizen.Await(promiseId)
|
||||
end
|
||||
|
||||
function Utils.GetPlayerLookingAt()
|
||||
local config = require "shared.config"
|
||||
local playerId, entity = lib.getClosestPlayer(GetEntityCoords(cache.ped), config.range)
|
||||
|
||||
if not playerId or not entity or not IsPedAPlayer(entity) then return end
|
||||
return GetPlayerServerId(playerId)
|
||||
end
|
||||
|
||||
return Utils
|
Loading…
Add table
Add a link
Reference in a new issue