Skip to content

Commit

Permalink
MODIFIED FILES
Browse files Browse the repository at this point in the history
  • Loading branch information
Clefas committed Jul 7, 2023
1 parent f1a13c2 commit 1f4a22b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 833 deletions.
3 changes: 2 additions & 1 deletion client/functions.lua
Expand Up @@ -37,7 +37,8 @@ ESX.IsPlayerLoaded = function()
end

ESX.GetPlayerData = function()
return ESX.PlayerData
ESX.PlayerData.inventory = exports['qs-inventory']:getUserInventory()
return ESX.PlayerData
end

ESX.SetPlayerData = function(key, val)
Expand Down
256 changes: 7 additions & 249 deletions client/main.lua
Expand Up @@ -75,7 +75,7 @@ AddEventHandler('esx:playerLoaded', function(playerData)
ShutdownLoadingScreen()
ShutdownLoadingScreenNui()
FreezeEntityPosition(PlayerPedId(), false)
DoScreenFadeIn(10000)
DoScreenFadeIn(10000)
StartServerSyncLoops()
end)

Expand All @@ -96,32 +96,6 @@ AddEventHandler('skinchanger:modelLoaded', function()
TriggerEvent('esx:restoreLoadout')
end)

AddEventHandler('esx:restoreLoadout', function()
local playerPed = PlayerPedId()
local ammoTypes = {}
RemoveAllPedWeapons(playerPed, true)

for k,v in ipairs(ESX.PlayerData.loadout) do
local weaponName = v.name
local weaponHash = GetHashKey(weaponName)

GiveWeaponToPed(playerPed, weaponHash, 0, false, false)
SetPedWeaponTintIndex(playerPed, weaponHash, v.tintIndex)

local ammoType = GetPedAmmoTypeFromWeapon(playerPed, weaponHash)

for k2,v2 in ipairs(v.components) do
local componentHash = ESX.GetWeaponComponent(weaponName, v2).hash
GiveWeaponComponentToPed(playerPed, weaponHash, componentHash)
end

if not ammoTypes[ammoType] then
AddAmmoToPed(playerPed, weaponHash, v.ammo)
ammoTypes[ammoType] = true
end
end
end)

RegisterNetEvent('esx:setAccountMoney')
AddEventHandler('esx:setAccountMoney', function(account)
for k,v in ipairs(ESX.PlayerData.accounts) do
Expand All @@ -138,100 +112,11 @@ AddEventHandler('esx:setAccountMoney', function(account)
end
end)

RegisterNetEvent('esx:addInventoryItem')
AddEventHandler('esx:addInventoryItem', function(item, count, showNotification)
for k,v in ipairs(ESX.PlayerData.inventory) do
if v.name == item then
ESX.UI.ShowInventoryItemNotification(true, v.label, count - v.count)
ESX.PlayerData.inventory[k].count = count
break
end
end

if showNotification then
ESX.UI.ShowInventoryItemNotification(true, item, count)
end

if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
ESX.ShowInventory()
end
end)

RegisterNetEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(item, count, showNotification)
for k,v in ipairs(ESX.PlayerData.inventory) do
if v.name == item then
ESX.UI.ShowInventoryItemNotification(false, v.label, v.count - count)
ESX.PlayerData.inventory[k].count = count
break
end
end

if showNotification then
ESX.UI.ShowInventoryItemNotification(false, item, count)
end

if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
ESX.ShowInventory()
end
end)

RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
ESX.PlayerData.job = job
end)

RegisterNetEvent('esx:addWeapon')
AddEventHandler('esx:addWeapon', function(weaponName, ammo)
local playerPed = PlayerPedId()
local weaponHash = GetHashKey(weaponName)

GiveWeaponToPed(playerPed, weaponHash, ammo, false, false)
end)

RegisterNetEvent('esx:addWeaponComponent')
AddEventHandler('esx:addWeaponComponent', function(weaponName, weaponComponent)
local playerPed = PlayerPedId()
local weaponHash = GetHashKey(weaponName)
local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash

GiveWeaponComponentToPed(playerPed, weaponHash, componentHash)
end)

RegisterNetEvent('esx:setWeaponAmmo')
AddEventHandler('esx:setWeaponAmmo', function(weaponName, weaponAmmo)
local playerPed = PlayerPedId()
local weaponHash = GetHashKey(weaponName)

SetPedAmmo(playerPed, weaponHash, weaponAmmo)
end)

RegisterNetEvent('esx:setWeaponTint')
AddEventHandler('esx:setWeaponTint', function(weaponName, weaponTintIndex)
local playerPed = PlayerPedId()
local weaponHash = GetHashKey(weaponName)

SetPedWeaponTintIndex(playerPed, weaponHash, weaponTintIndex)
end)

RegisterNetEvent('esx:removeWeapon')
AddEventHandler('esx:removeWeapon', function(weaponName)
local playerPed = PlayerPedId()
local weaponHash = GetHashKey(weaponName)

RemoveWeaponFromPed(playerPed, weaponHash)
SetPedAmmo(playerPed, weaponHash, 0) -- remove leftover ammo
end)

RegisterNetEvent('esx:removeWeaponComponent')
AddEventHandler('esx:removeWeaponComponent', function(weaponName, weaponComponent)
local playerPed = PlayerPedId()
local weaponHash = GetHashKey(weaponName)
local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash

RemoveWeaponComponentFromPed(playerPed, weaponHash, componentHash)
end)

RegisterNetEvent('esx:teleport')
AddEventHandler('esx:teleport', function(coords)
local playerPed = PlayerPedId()
Expand Down Expand Up @@ -270,46 +155,6 @@ AddEventHandler('esx:spawnVehicle', function(vehicleName)
end
end)

RegisterNetEvent('esx:createPickup')
AddEventHandler('esx:createPickup', function(pickupId, label, coords, type, name, components, tintIndex)
local function setObjectProperties(object)
SetEntityAsMissionEntity(object, true, false)
PlaceObjectOnGroundProperly(object)
FreezeEntityPosition(object, true)
SetEntityCollision(object, false, true)

pickups[pickupId] = {
obj = object,
label = label,
inRange = false,
coords = vector3(coords.x, coords.y, coords.z)
}
end

if type == 'item_weapon' then
local weaponHash = GetHashKey(name)
ESX.Streaming.RequestWeaponAsset(weaponHash)
local pickupObject = CreateWeaponObject(weaponHash, 50, coords.x, coords.y, coords.z, true, 1.0, 0)
SetWeaponObjectTintIndex(pickupObject, tintIndex)

for k,v in ipairs(components) do
local component = ESX.GetWeaponComponent(name, v)
GiveWeaponComponentToWeaponObject(pickupObject, component.hash)
end

setObjectProperties(pickupObject)
else
ESX.Game.SpawnLocalObject('prop_money_bag_01', coords, setObjectProperties)
end
end)

RegisterNetEvent('esx:createMissingPickups')
AddEventHandler('esx:createMissingPickups', function(missingPickups)
for pickupId,pickup in pairs(missingPickups) do
TriggerEvent('esx:createPickup', pickupId, pickup.label, pickup.coords, pickup.type, pickup.name, pickup.components, pickup.tintIndex)
end
end)

RegisterNetEvent('esx:registerSuggestions')
AddEventHandler('esx:registerSuggestions', function(registeredCommands)
for name,command in pairs(registeredCommands) do
Expand All @@ -319,14 +164,6 @@ AddEventHandler('esx:registerSuggestions', function(registeredCommands)
end
end)

RegisterNetEvent('esx:removePickup')
AddEventHandler('esx:removePickup', function(pickupId)
if pickups[pickupId] and pickups[pickupId].obj then
ESX.Game.DeleteObject(pickups[pickupId].obj)
pickups[pickupId] = nil
end
end)

RegisterNetEvent('esx:deleteVehicle')
AddEventHandler('esx:deleteVehicle', function(radius)
local playerPed = PlayerPedId()
Expand Down Expand Up @@ -389,29 +226,6 @@ if Config.EnableHud then
end

function StartServerSyncLoops()
-- keep track of ammo
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)

if isDead then
Citizen.Wait(500)
else
local playerPed = PlayerPedId()

if IsPedShooting(playerPed) then
local _,weaponHash = GetCurrentPedWeapon(playerPed, true)
local weapon = ESX.GetWeaponFromHash(weaponHash)

if weapon then
local ammoCount = GetAmmoInPedWeapon(playerPed, weaponHash)
TriggerServerEvent('esx:updateWeaponAmmo', weapon.name, ammoCount)
end
end
end
end
end)

-- sync current player coords with server
Citizen.CreateThread(function()
local previousCoords = vector3(ESX.PlayerData.coords.x, ESX.PlayerData.coords.y, ESX.PlayerData.coords.z)
Expand All @@ -427,71 +241,15 @@ function StartServerSyncLoops()
if distance > 1 then
previousCoords = playerCoords
local playerHeading = ESX.Math.Round(GetEntityHeading(playerPed), 1)
local formattedCoords = {x = ESX.Math.Round(playerCoords.x, 1), y = ESX.Math.Round(playerCoords.y, 1), z = ESX.Math.Round(playerCoords.z, 1), heading = playerHeading}
local formattedCoords = {
x = ESX.Math.Round(playerCoords.x, 1),
y = ESX.Math.Round(playerCoords.y, 1),
z = ESX.Math.Round(playerCoords.z, 1),
heading = playerHeading
}
TriggerServerEvent('esx:updateCoords', formattedCoords)
end
end
end
end)
end
--[[
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustReleased(0, 289) then
if IsInputDisabled(0) and not isDead and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
ESX.ShowInventory()
end
end
end
end)
]]
-- Pickups
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerPed = PlayerPedId()
local playerCoords, letSleep = GetEntityCoords(playerPed), true
local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer(playerCoords)

for pickupId,pickup in pairs(pickups) do
local distance = #(playerCoords - pickup.coords)

if distance < 5 then
local label = pickup.label
letSleep = false

if distance < 1 then
if IsControlJustReleased(0, 38) then
if IsPedOnFoot(playerPed) and (closestDistance == -1 or closestDistance > 3) and not pickup.inRange then
pickup.inRange = true

local dict, anim = 'weapons@first_person@aim_rng@generic@projectile@sticky_bomb@', 'plant_floor'
ESX.Streaming.RequestAnimDict(dict)
TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, 1000, 16, 0.0, false, false, false)
Citizen.Wait(1000)

TriggerServerEvent('esx:onPickup', pickupId)
PlaySoundFrontend(-1, 'PICK_UP', 'HUD_FRONTEND_DEFAULT_SOUNDSET', false)
end
end

label = ('%s~n~%s'):format(label, _U('threw_pickup_prompt'))
end

ESX.Game.Utils.DrawText3D({
x = pickup.coords.x,
y = pickup.coords.y,
z = pickup.coords.z + 0.25
}, label, 1.2, 1)
elseif pickup.inRange then
pickup.inRange = false
end
end

if letSleep then
Citizen.Wait(500)
end
end
end)

0 comments on commit 1f4a22b

Please sign in to comment.