Skip to content

Commit

Permalink
mt_lib support + server errors fixed with distance
Browse files Browse the repository at this point in the history
  • Loading branch information
trclassic92 committed Sep 29, 2024
1 parent ba4ca5c commit 22cd3df
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 129 deletions.
135 changes: 53 additions & 82 deletions client/cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ local QBCore = exports['qb-core']:GetCoreObject()
local PlayerWorkVans = {}
local waypointCoords = vector3(-603.707, 5305.513, 70.331)
local waypointCoords2 = vector(-555.627, 5314.729, 74.302)
local cameraCoords = Config.deliverySupervisorCam
local timmyCoords = Config.deliveryTaskerCam
local logPropModel = GetHashKey("prop_logpile_03")
local logPropEntity = nil
local outlineColor = Config.outLine
Expand Down Expand Up @@ -230,91 +228,64 @@ RegisterNetEvent('tr-lumberjack:client:returnworkvan', function()
end
end)


local function startCameraTask(targetPos, targetRot, dialogMessages)
local player = PlayerPedId()
local playerPos = GetEntityCoords(player)
local cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
local transitionDuration = Config.camTransition * 1000
local startTime = GetGameTimer()
local initialCamPos = vector3(playerPos.x, playerPos.y, playerPos.z + 0.5)

SetCamCoord(cam, initialCamPos.x, initialCamPos.y, initialCamPos.z)
SetCamRot(cam, GetGameplayCamRot(0).x, GetGameplayCamRot(0).y, GetGameplayCamRot(0).z, 2)
SetCamActive(cam, true)
RenderScriptCams(true, false, 0, true, true)

CreateThread(function()
while true do
local elapsedTime = GetGameTimer() - startTime
local progress = math.min(elapsedTime / transitionDuration, 1.0)
local newPos = CamVector(initialCamPos, targetPos, progress)
local newRot = CamVector(GetGameplayCamRot(0), targetRot, progress)

SetCamCoord(cam, newPos.x, newPos.y, newPos.z)
SetCamRot(cam, newRot.x, newRot.y, newRot.z, 2)

if progress >= 1.0 then
NotifyPlayer(dialogMessages[1], 'primary')
Wait(2500)
NotifyPlayer(dialogMessages[2], 'primary')
Wait(3500)

local returnStartTime = GetGameTimer()
while true do
local returnElapsedTime = GetGameTimer() - returnStartTime
local returnProgress = math.min(returnElapsedTime / transitionDuration, 1.0)
local returnPos = CamVector(targetPos, initialCamPos, returnProgress)
local returnRot = CamVector(targetRot, GetGameplayCamRot(0), returnProgress)

SetCamCoord(cam, returnPos.x, returnPos.y, returnPos.z)
SetCamRot(cam, returnRot.x, returnRot.y, returnRot.z, 2)

if returnProgress >= 1.0 then
break
end

Wait(0)
end
RenderScriptCams(false, false, 0, true, true)
DestroyCam(cam, false)
Wait(2000)
if TaskInProgress and not timmyTaskStarted then
SetNewWaypoint(-815.161, 5425.259)
NotifyPlayer(dialogMessages[3], 'success')
else
TriggerServerEvent('tr-lumberjack:server:deliverypaper')
SetNewWaypoint(1239.432, -3148.982)
NotifyPlayer(dialogMessages[3], 'success')
end
break
end

Wait(7)
end
end)
end

RegisterNetEvent('tr-lumberjack:client:starttask', function()
if TaskInProgress then
NotifyPlayer(Lang.alreadyTasked1, 'error')
return
if IsDeliveryTruckSelected then
if TaskInProgress then
NotifyPlayer(Lang.alreadyTasked1, 'error')
return
end
exports.mt_lib:showDialogue({
ped = ConstructionWorker1,
label = 'Larry',
speech = Lang.dialLog1,
options = {
{
id = 'lumber_accepttask',
label = Lang.dialLog2,
icon = 'hand',
close = true,
action = function()
SetNewWaypoint(-815.161, 5425.259)
end
},
}
})
TaskInProgress = true
Wait(5000)
NotifyPlayer(Lang.dialLog3, 'success')
Wait(5000)
NotifyPlayer(Lang.dialLog4, 'success')
else
NotifyPlayer(Lang.selectDeliveryTruck, 'error')
end
TaskInProgress = true
startCameraTask(vector3(cameraCoords.x, cameraCoords.y, cameraCoords.z), vector3(0.0, 0.0, cameraCoords.w), {Lang.dialLog1, Lang.dialLog2, Lang.dialLog3})
end)

RegisterNetEvent('tr-lumberjack:client:timmytask', function()
if not TrailerFull then
NotifyPlayer(Lang.timmyTask, 'error')
return
end
if timmyTaskStarted then
NotifyPlayer(Lang.timmyTask, 'error')
return
end
timmyTaskStarted = true
startCameraTask(vector3(Config.deliveryTaskerCam.x, Config.deliveryTaskerCam.y, Config.deliveryTaskerCam.z), vector3(0.0, 0.0, Config.deliveryTaskerCam.w), {Lang.timmyDialLog1, Lang.timmyDialLog2, Lang.timmyDialLog3})
exports.mt_lib:showDialogue({
ped = ConstructionWorker2,
label = 'Timmy',
speech = Lang.timmyTask1,
options = {
{
id = 'lumber_acceptdelivery',
label = Lang.timmyTask2,
icon = 'hand',
close = true,
action = function()
if TrailerFull then
NotifyPlayer(Lang.timmyTask, 'error')
return
end
if timmyTaskStarted then
NotifyPlayer(Lang.timmyTask, 'error')
return
end
TriggerServerEvent('tr-lumberjack:server:deliverypaper')
SetNewWaypoint(1239.432, -3148.982)
end
},
}
})
end)

function CamVector(startVec, endVec, t)
Expand Down
32 changes: 0 additions & 32 deletions client/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ if Config.menu == "qbcore" then
},
})
end)
RegisterNetEvent('tr-lumberjack:client:deliverysuper', function()
if IsDeliveryTruckSelected then
exports['qb-menu']:openMenu({
{
header = Lang.delivery1,
icon = 'fa-solid fa-trailer',
params = {
event = 'tr-lumberjack:client:starttask',
}
}
})
else
NotifyPlayer(Lang.selectDeliveryTruck, 'error')
end
end)
RegisterNetEvent('tr-lumberjack:client:trailerInteract', function()
exports['qb-menu']:openMenu({
{
Expand Down Expand Up @@ -181,23 +166,6 @@ elseif Config.menu == "ox" then
})
lib.showContext('lumberjack_depo')
end)
RegisterNetEvent('tr-lumberjack:client:deliverysuper', function()
if IsDeliveryTruckSelected then
lib.registerContext({
id = 'lumberjack_super',
title = Lang.interact2,
options = {
{
title = Lang.delivery1,
event = 'tr-lumberjack:client:starttask',
},
}
})
lib.showContext('lumberjack_super')
else
NotifyPlayer(Lang.selectDeliveryTruck, 'error')
end
end)
RegisterNetEvent('tr-lumberjack:client:trailerInteract', function()
lib.registerContext({
id = 'lumber_trailer',
Expand Down
4 changes: 2 additions & 2 deletions client/peds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ end
CreateThread(function()
Wait(1000)
local lumberjack1 = CreateLumberPed(TRClassic, false)
local constructionWorker1 = CreateLumberPed(classicSupervisorCoords, true)
local constructionWorker2 = CreateLumberPed(ClassicTR, true)
ConstructionWorker1 = CreateLumberPed(classicSupervisorCoords, true)
ConstructionWorker2 = CreateLumberPed(ClassicTR, true)
local lumberjack2 = CreateLumberPed(bingBong, false)
local lumberjack3 = CreateLumberPed(fuckYourLife, false)

Expand Down
2 changes: 1 addition & 1 deletion client/target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local boxZones = {
name = 'zone2',
label = Lang.interact2,
icon = 'fa-solid fa-cogs',
event = 'tr-lumberjack:client:deliverysuper'
event = 'tr-lumberjack:client:starttask'
},
{
-- Delivery Tasker
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ game 'gta5'

author 'TRClassic'
description 'LumberJack Job For QB-Core / Ox'
version '2.0.2'
version '2.0.3'

shared_scripts {
'lang/en.lua',
Expand Down
12 changes: 7 additions & 5 deletions lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Lang = {
depoInvoice = "Contact",
depoMessage = "", -- Not used
-- NPC
dialLog1 = "Larry: Hello! I have a task for you.",
dialLog2 = "Larry: Please collect some logs at the waypoint we added to your GPS!",
dialLog1 = "Hello! I have a task for you.",
dialLog2 = "Accept Task",
dialLog3 = "Task: Go to the marked location to collect logs.",
dialLog4 = "Task: Drive the truck with the Flatbed to load logs onto it",
timmyDialLog1 = "Timmy: Got the paper work your trailer is put together",
timmyDialLog2 = "Timmy: I will be sending you a ping of a delivery point",
timmyDialLog3 = "Ping has been applied to your GPS",
timmyTask1 = "Grab A Delivery Form",
timmyTask2 = "Request Delivery",
timmyDialLog1 = "Ping has been applied to your GPS",
-- Task Areas
task1 = "Collect Logs",
task2 = "Loaded log onto the trailer!",
Expand Down Expand Up @@ -93,6 +93,7 @@ Lang = {
tooFarFromTasker = "To Far From Timmy",
alreadyHaveDeliveryPaper = "Already Have Delivery Paper",
tooFarFromDepo = "To Far From Depo",
deliveryPaperFailed = "Couldn't Hand Over A Delivery Paper",
-- Progress bar
pickingLog = "Getting log ready for transport",
loadingTrailer = "Loading Log onto trailer",
Expand All @@ -105,5 +106,6 @@ Lang = {
-- Debug
debug1 = "Ground log prop deleted upon re-picking the log.",
debug2 = "Ground log prop deleted after 5 minutes.",
invalidPlayer = "Invalid",

}
13 changes: 7 additions & 6 deletions server/sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ RegisterServerEvent('tr-lumberjack:server:returnworkvan', function()

if Player then
local playerCoords = GetEntityCoords(GetPlayerPed(source))
local depoCoords = Config.lumberDepo
local depoCoords = vector3(Config.lumberDepo.x, Config.lumberDepo.y, Config.lumberDepo.z)

if #(playerCoords - depoCoords) > 10.0 then
notifyPlayer(source, Lang.tooFarFromDepo, 'error')
return
end
if exports.ox_inventory:AddItem(source, 'cash', Config.returnPrice) then
notifyPlayer(source, Lang.workVanReturned, 'success')
notifyPlayer(source, Lang.storedVehicle, 'success')
else
notifyPlayer(source, Lang.returnVanFailed, 'error')
notifyPlayer(source, Lang.incorrectVehicle, 'error')
end
else
notifyPlayer(source, Lang.invalidPlayer, 'error')
Expand Down Expand Up @@ -70,18 +70,20 @@ RegisterServerEvent('tr-lumberjack:server:deliverypaper', function()

if Player then
local playerCoords = GetEntityCoords(GetPlayerPed(source))
local taskerCoords = Config.deliveryTasker
local taskerCoords = vector3(Config.deliveryTasker.x, Config.deliveryTasker.y, Config.deliveryTasker.z)

if #(playerCoords - taskerCoords) > 10.0 then
notifyPlayer(source, Lang.tooFarFromTasker, 'error')
return
end

if exports.ox_inventory:Search(source, 'count', 'tr_deliverypaper') > 0 then
notifyPlayer(source, Lang.alreadyHaveDeliveryPaper, 'error')
return
end

if exports.ox_inventory:AddItem(source, 'tr_deliverypaper', 1) then
notifyPlayer(source, Lang.receivedDeliveryPaper, 'success')
notifyPlayer(source, Lang.timmyDialLog1, 'success')
else
notifyPlayer(source, Lang.deliveryPaperFailed, 'error')
end
Expand Down Expand Up @@ -138,7 +140,6 @@ end)

RegisterServerEvent('tr-lumberjack:server:choptree', function()
local source = source

-- Because you are going to be able to carry till your inventory is full (Don't ask why because Im stupid alright)
if exports.ox_inventory:CanCarryItem(source, 'tr_choppedlog', 1) then
if exports.ox_inventory:AddItem(source, 'tr_choppedlog', 1) then
Expand Down

0 comments on commit 22cd3df

Please sign in to comment.