Skip to content

Commit

Permalink
refactor(client): moved onCache handler and cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
StuxxyOfficial committed Feb 8, 2023
1 parent a3b0003 commit de2eac7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
41 changes: 19 additions & 22 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ if Config.TextUI then
end
end
CreateThread(uiThread)

lib.onCache('vehicle', function(value)
if value then
uiThreadRunning = false
else
CreateThread(uiThread)
end
end)
end
end

Expand Down Expand Up @@ -141,34 +149,34 @@ local function startPushing(vehicle)
if flipped then return end
local min, max = GetModelDimensions(GetEntityModel(vehicle))
local size = max - min
local coords = GetEntityCoords(cache.ped)
local coords = GetEntityCoords(ped)
local closest = #(coords - GetOffsetFromEntityInWorldCoords(vehicle, 0.0, (size.y / 2), 0.0)) < #(coords - GetOffsetFromEntityInWorldCoords(vehicle, 0.0, (-size.y / 2), 0.0)) and 'bonnet' or 'trunk'
local start = lib.callback.await('OT_pushvehicle:startPushing', false, NetworkGetNetworkIdFromEntity(vehicle), closest)
if start then
vehiclepushing = vehicle
pushing = true
AttachEntityToEntity(cache.ped, vehicle, 0, 0.0, closest == 'trunk' and min.y - 0.6 or -min.y + 0.4, closest == 'trunk' and min.z + 1.1 or max.z / 2, 0.0, 0.0, closest == 'trunk' and 0.0 or 180.0, 0.0, false, false, true, 0, true)
AttachEntityToEntity(ped, vehicle, 0, 0.0, closest == 'trunk' and min.y - 0.6 or -min.y + 0.4, closest == 'trunk' and min.z + 1.1 or max.z / 2, 0.0, 0.0, closest == 'trunk' and 0.0 or 180.0, 0.0, false, false, true, 0, true)
lib.requestAnimDict('missfinale_c2ig_11')
TaskPlayAnim(cache.ped, 'missfinale_c2ig_11', 'pushcar_offcliff_m', 1.5, 1.5, -1, 35, 0, false, false, false)
TaskPlayAnim(ped, 'missfinale_c2ig_11', 'pushcar_offcliff_m', 1.5, 1.5, -1, 35, 0, false, false, false)
end
end

local function stopPushing()
TriggerServerEvent('OT_pushvehicle:stopPushing', NetworkGetNetworkIdFromEntity(vehiclepushing))
vehiclepushing = nil
pushing = false
DetachEntity(cache.ped, true, false)
ClearPedTasks(cache.ped)
DetachEntity(ped, true, false)
ClearPedTasks(ped)
end

keybind = lib.addKeybind({
name = 'pushvehicle',
description = 'Push broken down vehicle',
defaultKey = 'E',
defaultKey = Config.PushKey,
onPressed = function(self)
if Config.target then return end
if pushing then return end
local vehicle = lib.getClosestVehicle(GetEntityCoords(cache.ped), 4, false)
local vehicle = lib.getClosestVehicle(GetEntityCoords(ped), 4, false)
if not vehicle then return end
startPushing(vehicle)
end,
Expand Down Expand Up @@ -211,7 +219,6 @@ if Config.target then
local options = {
{
name = 'startPushing',
icon = Config.Intrunkicon,
label = 'Start Pushing',
onSelect = function(data)
startPushing(data.entity)
Expand All @@ -230,7 +237,6 @@ if Config.target then
},
{
name = 'stopPushing',
icon = Config.Intrunkicon,
label = 'Stop Pushing',
onSelect = function(data)
stopPushing()
Expand All @@ -249,12 +255,12 @@ if Config.target then
if Config.Usebones then
exports[targetSystem]:AddTargetBone({'boot', 'bonnet'}, {
options = options,
distance = Config.MaxDistance
distance = 3
})
else
exports[targetSystem]:Vehicle({
options = options,
distance = Config.MaxDistance
distance = 3
})
end
elseif targetSystem == 'ox_target' then
Expand All @@ -270,12 +276,12 @@ if Config.target then
if Config.Usebones then
exports[targetSystem]:AddTargetBone({'boot', 'bonnet'}, {
options = options,
distance = Config.MaxDistance
distance = 3
})
else
exports[targetSystem]:AddGlobalVehicle({
options = options,
distance = Config.MaxDistance
distance = 3
})
end
end
Expand All @@ -285,15 +291,6 @@ lib.onCache('ped', function(value)
ped = value
end)

lib.onCache('vehicle', function(value)
if Config.target or not Config.TextUI then return end
if value then
uiThreadRunning = false
else
CreateThread(uiThread)
end
end)

lib.onCache('seat', function(value)
seat = value
end)
2 changes: 1 addition & 1 deletion shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Config.TurnLeftKey = 'A' -- Keys to turn the vehicle while pushing it.
Config.TextUI = true -- Use Text UI for vehicle push
Config.useOTSkills = false -- Use OT Skills for XP gain from pushing vehicles. Found here: https://otstudios.tebex.io
Config.maxReward = 20 -- Max amount of xp that can be gained from pushing a vehicle per push, make sure this is the same or less than what is set for strength in your OT_skills config.
Config.healthMin = 200.0 -- Minimum health of vehicle to be able to push it.
Config.healthMin = 2000.0 -- Minimum health of vehicle to be able to push it.

Config.blacklist = { -- blacklist vehicle models from being pushed.
[`phantom`] = true
Expand Down

0 comments on commit de2eac7

Please sign in to comment.