Files
qb-core-qbcore-fivem/client/events.lua
T
Kakarot 923f3d3a31 ⚠️ Major Update ⚠️
- Major cleanup of all files including reformatting & notations
- Added an optional export to add to scripts as an alternative to import.lua
- Added player state to OnPlayerLoaded so no more need for isLoggedIn inside scripts
- Updated all events to the new RegisterNetEvent and got rid of unneeded handlers
- Added the ability for ACE permissions with commands
- Added two new config options for player update interval and status update
- Changed players table to use citizenid column as primary key <-- very important
- Overall sloppy code cleanup, removal of unused code, got rid of nil checks
2021-09-24 22:46:20 -06:00

100 lines
3.2 KiB
Lua

-- Player load and unload handling
-- New method for checking if logged in across all scripts (optional)
-- if LocalPlayer.state['isLoggedIn'] then
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
ShutdownLoadingScreenNui()
LocalPlayer.state:set('isLoggedIn', true, false)
SetCanAttackFriendly(PlayerPedId(), true, false)
NetworkSetFriendlyFireOption(true)
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
LocalPlayer.state:set('isLoggedIn', false, false)
end)
-- Teleport Commands
RegisterNetEvent('QBCore:Command:TeleportToPlayer', function(coords)
local ped = PlayerPedId()
SetPedCoordsKeepVehicle(ped, coords.x, coords.y, coords.z)
end)
RegisterNetEvent('QBCore:Command:TeleportToCoords', function(x, y, z)
local ped = PlayerPedId()
SetPedCoordsKeepVehicle(ped, x, y, z)
end)
RegisterNetEvent('QBCore:Command:GoToMarker', function()
local ped = PlayerPedId()
local blip = GetFirstBlipInfoId(8)
if DoesBlipExist(blip) then
local blipCoords = GetBlipCoords(blip)
for height = 1, 1000 do
SetPedCoordsKeepVehicle(ped, blipCoords.x, blipCoords.y, height + 0.0)
local foundGround, zPos = GetGroundZFor_3dCoord(blipCoords.x, blipCoords.y, height + 0.0)
if foundGround then
SetPedCoordsKeepVehicle(ped, blipCoords.x, blipCoords.y, height + 0.0)
break
end
Wait(0)
end
end
end)
-- Vehicle Commands
RegisterNetEvent('QBCore:Command:SpawnVehicle', function(vehName)
local ped = PlayerPedId()
local hash = GetHashKey(vehName)
if not IsModelInCdimage(hash) then return end
RequestModel(hash)
while not HasModelLoaded(hash) do Wait(10) end
local vehicle = CreateVehicle(hash, GetEntityCoords(ped), GetEntityHeading(ped), true, false)
TaskWarpPedIntoVehicle(ped, vehicle, -1)
SetModelAsNoLongerNeeded(vehicle)
TriggerEvent("vehiclekeys:client:SetOwner", GetVehicleNumberPlateText(vehicle))
end)
RegisterNetEvent('QBCore:Command:DeleteVehicle', function()
local ped = PlayerPedId()
local veh = GetVehiclePedIsUsing(ped)
if veh ~= 0 then
SetEntityAsMissionEntity(veh, true, true)
DeleteVehicle(veh)
else
local pcoords = GetEntityCoords(ped)
local vehicles = GetGamePool('CVehicle')
for k, v in pairs(vehicles) do
if #(pcoords - GetEntityCoords(v)) <= 5.0 then
SetEntityAsMissionEntity(v, true, true)
DeleteVehicle(v)
end
end
end
end)
-- Other stuff
RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
QBCore.PlayerData = val
end)
RegisterNetEvent('QBCore:Player:UpdatePlayerData', function()
TriggerServerEvent('QBCore:UpdatePlayer')
end)
RegisterNetEvent('QBCore:Notify', function(text, type, length)
QBCore.Functions.Notify(text, type, length)
end)
RegisterNetEvent('QBCore:Client:TriggerCallback', function(name, ...)
if QBCore.ServerCallbacks[name] then
QBCore.ServerCallbacks[name](...)
QBCore.ServerCallbacks[name] = nil
end
end)
RegisterNetEvent('QBCore:Client:UseItem', function(item)
TriggerServerEvent('QBCore:Server:UseItem', item)
end)