Files
qb-core-qbcore-fivem/server/events.lua
T
Kakarot 8fffc421bb Merge Dev (#794)
* [Update] Stuff and Things - Fix Exploit

- Update doors on teleport so they don't get stuck (requires my doorlock PR that creates a updateDoors() export
- Support for heading with TeleportToCoords event
- Support for teleporting to location name with /tp and a default file with locations to use
- Remove 'QBCore:Server:AddItem' event (requires PR to other resources that use it)
- Support for an array of items that do the same thing with QBCore.Functions.CreateUsableItem
- Player exists check before removing or adding permission
- Trigger OnPlayerUnload as a server side event too
- Player.Functions.GetMetaData function
- Added reason to money remove logs
- Set dirt level to 0 on /car vehicles

* Export to Event

* Deprecate instead of remove?

* Player+License verification fix

* Update events.lua

* Export change for qb-management

* [Hotfix] Errors after Merge

* [Change] src to source

* Prevent people using /me to troll

This prevents people using that /me troll with the huge font size and different colors.

* Remove DoorUpdate event

* Update client/events.lua

Co-authored-by: BerkieBb <82737367+BerkieBb@users.noreply.github.com>

* Update server/functions.lua

Co-authored-by: BerkieBb <82737367+BerkieBb@users.noreply.github.com>

* Adjustments for BB

* Linting

* fix(server/functions): use indexed variables

Co-authored-by: David Malchin <malchin459@gmail.com>

* chore(server/events): remove unnecessary _

Co-authored-by: David Malchin <malchin459@gmail.com>

* chore(server/events): remove unnecessary _'s

Co-authored-by: David Malchin <malchin459@gmail.com>

* chore(server/events): language

Co-authored-by: David Malchin <malchin459@gmail.com>

* chore(server/events): language

Co-authored-by: David Malchin <malchin459@gmail.com>

* chore(server/events): language

Co-authored-by: David Malchin <malchin459@gmail.com>

* chore(server/events): language

Co-authored-by: David Malchin <malchin459@gmail.com>

* chore(server/player): indentation

Co-authored-by: David Malchin <malchin459@gmail.com>

* [Chore] Remove Money

Removed repetitive code that made zero sense

* Update en.lua

* Update player.lua

* Update player.lua

* Update functions.lua

Co-authored-by: ItsANoBrainer <itsanobrainergg@protonmail.com>
Co-authored-by: Scullyy <51968381+Scullyy@users.noreply.github.com>
Co-authored-by: Idris Dev <IdrisDose@users.noreply.github.com>
Co-authored-by: Idris <idrisdev@gmail.com>
Co-authored-by: BerkieBb <82737367+BerkieBb@users.noreply.github.com>
Co-authored-by: David Malchin <malchin459@gmail.com>
Co-authored-by: Chris Usiak <christopher.usiak@oakland.k12.mi.us>
2022-08-19 11:48:39 -05:00

240 lines
9.2 KiB
Lua

-- Event Handler
AddEventHandler('chatMessage', function(_, _, message)
if string.sub(message, 1, 1) == '/' then
CancelEvent()
return
end
end)
AddEventHandler('playerDropped', function(reason)
local src = source
if not QBCore.Players[src] then return end
local Player = QBCore.Players[src]
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..' ..'\n **Reason:** ' .. reason)
Player.Functions.Save()
QBCore.Player_Buckets[Player.PlayerData.license] = nil
QBCore.Players[src] = nil
end)
-- Player Connecting
local function onPlayerConnecting(name, _, deferrals)
local src = source
local license
local identifiers = GetPlayerIdentifiers(src)
deferrals.defer()
-- Mandatory wait
Wait(0)
if QBCore.Config.Server.Closed then
if not IsPlayerAceAllowed(src, 'qbadmin.join') then
deferrals.done(QBCore.Config.Server.ClosedReason)
end
end
deferrals.update(string.format(Lang:t('info.checking_ban'), name))
for _, v in pairs(identifiers) do
if string.find(v, 'license') then
license = v
break
end
end
-- Mandatory wait
Wait(2500)
deferrals.update(string.format(Lang:t('info.checking_whitelisted'), name))
local isBanned, Reason = QBCore.Functions.IsPlayerBanned(src)
local isLicenseAlreadyInUse = QBCore.Functions.IsLicenseInUse(license)
local isWhitelist, whitelisted = QBCore.Config.Server.Whitelist, QBCore.Functions.IsWhitelisted(src)
Wait(2500)
deferrals.update(string.format(Lang:t('info.join_server'), name))
if not license then
deferrals.done(Lang:t('error.no_valid_license'))
elseif isBanned then
deferrals.done(Reason)
elseif isLicenseAlreadyInUse and QBCore.Config.Server.CheckDuplicateLicense then
deferrals.done(Lang:t('error.duplicate_license'))
elseif isWhitelist and not whitelisted then
deferrals.done(Lang:t('error.not_whitelisted'))
end
deferrals.done()
-- Add any additional defferals you may need!
end
AddEventHandler('playerConnecting', onPlayerConnecting)
-- Open & Close Server (prevents players from joining)
RegisterNetEvent('QBCore:Server:CloseServer', function(reason)
local src = source
if QBCore.Functions.HasPermission(src, 'admin') then
reason = reason or 'No reason specified'
QBCore.Config.Server.Closed = true
QBCore.Config.Server.ClosedReason = reason
for k in pairs(QBCore.Players) do
if not QBCore.Functions.HasPermission(k, QBCore.Config.Server.WhitelistPermission) then
QBCore.Functions.Kick(k, reason, nil, nil)
end
end
else
QBCore.Functions.Kick(src, 'You don\'t have permissions for this..', nil, nil)
end
end)
RegisterNetEvent('QBCore:Server:OpenServer', function()
local src = source
if QBCore.Functions.HasPermission(src, 'admin') then
QBCore.Config.Server.Closed = false
else
QBCore.Functions.Kick(src, 'You don\'t have permissions for this..', nil, nil)
end
end)
-- Callback Events --
-- Client Callback
RegisterNetEvent('QBCore:Server:TriggerClientCallback', function(name, ...)
if QBCore.ClientCallbacks[name] then
QBCore.ClientCallbacks[name](...)
QBCore.ClientCallbacks[name] = nil
end
end)
-- Server Callback
RegisterNetEvent('QBCore:Server:TriggerCallback', function(name, ...)
local src = source
QBCore.Functions.TriggerCallback(name, src, function(...)
TriggerClientEvent('QBCore:Client:TriggerCallback', src, name, ...)
end, ...)
end)
-- Player
RegisterNetEvent('QBCore:UpdatePlayer', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local newHunger = Player.PlayerData.metadata['hunger'] - QBCore.Config.Player.HungerRate
local newThirst = Player.PlayerData.metadata['thirst'] - QBCore.Config.Player.ThirstRate
if newHunger <= 0 then
newHunger = 0
end
if newThirst <= 0 then
newThirst = 0
end
Player.Functions.SetMetaData('thirst', newThirst)
Player.Functions.SetMetaData('hunger', newHunger)
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, newThirst)
Player.Functions.Save()
end)
RegisterNetEvent('QBCore:Server:SetMetaData', function(meta, data)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
if meta == 'hunger' or meta == 'thirst' then
if data > 100 then
data = 100
end
end
Player.Functions.SetMetaData(meta, data)
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata['hunger'], Player.PlayerData.metadata['thirst'])
end)
RegisterNetEvent('QBCore:ToggleDuty', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
if Player.PlayerData.job.onduty then
Player.Functions.SetJobDuty(false)
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.off_duty'))
else
Player.Functions.SetJobDuty(true)
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.on_duty'))
end
TriggerClientEvent('QBCore:Client:SetDuty', src, Player.PlayerData.job.onduty)
end)
-- Items
-- This event is exploitable and should not be used. It has been deprecated, and will be removed soon.
RegisterNetEvent('QBCore:Server:UseItem', function(item)
print(string.format("%s triggered QBCore:Server:UseItem by ID %s with the following data. This event is deprecated due to exploitation, and will be removed soon. Check qb-inventory for the right use on this event.", GetInvokingResource(), source))
QBCore.Debug(item)
end)
-- This event is exploitable and should not be used. It has been deprecated, and will be removed soon. function(itemName, amount, slot)
RegisterNetEvent('QBCore:Server:RemoveItem', function(itemName, amount)
local src = source
print(string.format("%s triggered QBCore:Server:RemoveItem by ID %s for %s %s. This event is deprecated due to exploitation, and will be removed soon. Adjust your events accordingly to do this server side with player functions.", GetInvokingResource(), src, amount, itemName))
end)
-- This event is exploitable and should not be used. It has been deprecated, and will be removed soon. function(itemName, amount, slot, info)
RegisterNetEvent('QBCore:Server:AddItem', function(itemName, amount)
local src = source
print(string.format("%s triggered QBCore:Server:AddItem by ID %s for %s %s. This event is deprecated due to exploitation, and will be removed soon. Adjust your events accordingly to do this server side with player functions.", GetInvokingResource(), src, amount, itemName))
end)
-- Non-Chat Command Calling (ex: qb-adminmenu)
RegisterNetEvent('QBCore:CallCommand', function(command, args)
local src = source
if not QBCore.Commands.List[command] then return end
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local hasPerm = QBCore.Functions.HasPermission(src, "command."..QBCore.Commands.List[command].name)
if hasPerm then
if QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and not args[#QBCore.Commands.List[command].arguments] then
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args2'), 'error')
else
QBCore.Commands.List[command].callback(src, args)
end
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.no_access'), 'error')
end
end)
-- Use this for player vehicle spawning
-- Vehicle server-side spawning callback (netId)
-- use the netid on the client with the NetworkGetEntityFromNetworkId native
-- convert it to a vehicle via the NetToVeh native
QBCore.Functions.CreateCallback('QBCore:Server:SpawnVehicle', function(source, cb, model, coords, warp)
local ped = GetPlayerPed(source)
model = type(model) == 'string' and joaat(model) or model
if not coords then coords = GetEntityCoords(ped) end
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, true)
while not DoesEntityExist(veh) do Wait(0) end
if warp then
while GetVehiclePedIsIn(ped) ~= veh do
Wait(0)
TaskWarpPedIntoVehicle(ped, veh, -1)
end
end
while NetworkGetEntityOwner(veh) ~= source do Wait(0) end
cb(NetworkGetNetworkIdFromEntity(veh))
end)
-- Use this for long distance vehicle spawning
-- vehicle server-side spawning callback (netId)
-- use the netid on the client with the NetworkGetEntityFromNetworkId native
-- convert it to a vehicle via the NetToVeh native
QBCore.Functions.CreateCallback('QBCore:Server:CreateVehicle', function(source, cb, model, coords, warp)
model = type(model) == 'string' and GetHashKey(model) or model
if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end
local CreateAutomobile = GetHashKey("CREATE_AUTOMOBILE")
local veh = Citizen.InvokeNative(CreateAutomobile, model, coords, coords.w, true, true)
while not DoesEntityExist(veh) do Wait(0) end
if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end
cb(NetworkGetNetworkIdFromEntity(veh))
end)