Skip to content

Commit

Permalink
Secured Events
Browse files Browse the repository at this point in the history
  • Loading branch information
trclassic92 committed Sep 27, 2024
1 parent 88ed86a commit 1146b6e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local boxZones = {
},
{
-- Delivery Dropoff
coords = vector3(1239.427, -3149.191, 5.528),
coords = Config.deliverDropOff,
length = 5,
width = 5,
heading = 20.0,
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.1'
version '2.0.2'

shared_scripts {
'lang/en.lua',
Expand Down
8 changes: 8 additions & 0 deletions lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Lang = {
storedVehicle = "You have returned the work van.",
addedLog = "You have picked up a log!",
soldLog = "You sold a log for $%d!",
craftedItems = "Crafted %d %s.",
-- Error Notifications
vehicleToClose = "Vehicle Near By!",
notEnoughCash = "Not enough cash!",
Expand All @@ -85,6 +86,13 @@ Lang = {
alreadyChopped = "This tree has already been chopped",
invalidNumber = "You must enter a valid amount of logs!",
errorNoAxe = "Need to have an axe in hand",
tooFarFromCraftingBench = "To Far From Crafting Location",
tooFarFromSellPoint = "To Far From Selling Location",
tooFarFromDropOff = "To Far From Drop Off Location",
noLogsToSell = "No Logs To Sell",
tooFarFromTasker = "To Far From Timmy",
alreadyHaveDeliveryPaper = "Already Have Delivery Paper",
tooFarFromDepo = "To Far From Depo",
-- Progress bar
pickingLog = "Getting log ready for transport",
loadingTrailer = "Loading Log onto trailer",
Expand Down
111 changes: 96 additions & 15 deletions server/sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ RegisterServerEvent('tr-lumberjack:server:returnworkvan', function()
local Player = QBCore.Functions.GetPlayer(source)

if Player then
exports.ox_inventory:AddItem(source, 'cash', Config.returnPrice)
local playerCoords = GetEntityCoords(GetPlayerPed(source))
local depoCoords = Config.lumberDepo

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')
else
notifyPlayer(source, Lang.returnVanFailed, 'error')
end
else
notifyPlayer(source, Lang.invalidPlayer, 'error')
end
end)

Expand Down Expand Up @@ -56,15 +69,46 @@ RegisterServerEvent('tr-lumberjack:server:deliverypaper', function()
local Player = QBCore.Functions.GetPlayer(source)

if Player then
exports.ox_inventory:AddItem(source, 'tr_deliverypaper', 1)
local playerCoords = GetEntityCoords(GetPlayerPed(source))
local taskerCoords = Config.deliveryTasker
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')
else
notifyPlayer(source, Lang.deliveryPaperFailed, 'error')
end
else
notifyPlayer(source, Lang.invalidPlayer, 'error')
end
end)


RegisterServerEvent('tr-lumberjack:server:sellinglog', function()
local source = source
local Player = QBCore.Functions.GetPlayer(source)

if Player then
local playerCoords = GetEntityCoords(GetPlayerPed(source))
local dropOffCoords = Config.deliverDropOff

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

if exports.ox_inventory:Search(source, 'count', 'tr_log') < 1 then
notifyPlayer(source, Lang.noLogsToSell, 'error')
return
end

local minSell, maxSell = table.unpack(Config.sell.deliveryPerLog)
local cashReward = math.random(minSell, maxSell)

Expand All @@ -73,20 +117,25 @@ RegisterServerEvent('tr-lumberjack:server:sellinglog', function()
end
playerLogSales[source] = playerLogSales[source] + 1

exports.ox_inventory:RemoveItem(source, 'tr_log', 1)
exports.ox_inventory:AddItem(source, 'cash', cashReward)
if exports.ox_inventory:RemoveItem(source, 'tr_log', 1) then
exports.ox_inventory:AddItem(source, 'cash', cashReward)

if playerLogSales[source] >= Config.maxLogs then
if exports.ox_inventory:RemoveItem(source, 'tr_deliverypaper', 1) then
TriggerClientEvent('tr-lumberjack:client:resetTimmyTask', source)
if playerLogSales[source] >= Config.maxLogs then
if exports.ox_inventory:RemoveItem(source, 'tr_deliverypaper', 1) then
TriggerClientEvent('tr-lumberjack:client:resetTimmyTask', source)
end
playerLogSales[source] = 0
end
playerLogSales[source] = 0
notifyPlayer(source, string.format(Lang.soldLog, cashReward), 'success')
else
notifyPlayer(source, Lang.logRemovalFailed, 'error')
end

notifyPlayer(source, string.format(Lang.soldLog, cashReward), 'success')
else
notifyPlayer(source, Lang.invalidPlayer, 'error')
end
end)


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

Expand All @@ -104,11 +153,20 @@ RegisterServerEvent('tr-lumberjack:server:craftinginput', function(argsNumber, l
local source = source
local slot = tonumber(argsNumber)
local itemCount = tonumber(logAmount)
local playerPed = GetPlayerPed(source)
local playerCoords = GetEntityCoords(playerPed)

local craftingBenchCoords = vector3(Config.craftingBench.x, Config.craftingBench.y, Config.craftingBench.z)
local distance = #(playerCoords - craftingBenchCoords)

if distance > 5.0 then
notifyPlayer(source, Lang.tooFarFromCraftingBench, 'error')
return
end

if itemCount < 0 then
if Config.debug then
print(itemCount)
print("Invalid item count.")
print("Invalid item count:", itemCount)
end
return
end
Expand All @@ -129,27 +187,51 @@ RegisterServerEvent('tr-lumberjack:server:craftinginput', function(argsNumber, l
itemToReceive = 'tr_toyset'
totalItems = itemCount * Config.receive.tr_toyset
else
print("Invalid crafting type.")
if Config.debug then
print("Invalid crafting type.")
end
return
end

if exports.ox_inventory:CanCarryItem(source, itemToReceive, totalItems) then
if exports.ox_inventory:RemoveItem(source, 'tr_choppedlog', 1) then
Wait(7)
exports.ox_inventory:AddItem(source, itemToReceive, totalItems)
notifyPlayer(source, string.format(Lang.craftedItems, totalItems, itemToReceive), 'success')
else
notifyPlayer(source, Lang.noItemsToCraft, 'error')
end
else
notifyPlayer(source, Lang.carryingWeight, 'error')
end

if Config.debug then
print(string.format("Player %d crafted %d %s.", source, totalItems, itemToReceive))
end
end)


RegisterServerEvent('tr-lumberjack:server:sellitem', function(args)
local source = source
local itemCount = tonumber(args.number)
local itemType = args.itemType
local playerPed = GetPlayerPed(source)
local playerCoords = GetEntityCoords(playerPed)

local sellingLocation = nil
if itemType == 'tr_firewood' or itemType == 'tr_woodplank' then
sellingLocation = vector3(Config.seller1.x, Config.seller1.y, Config.seller1.z)
elseif itemType == 'tr_toyset' or itemType == 'tr_woodhandles' then
sellingLocation = vector3(Config.seller2.x, Config.seller2.y, Config.seller2.z)
else
notifyPlayer(source, Lang.invalidItem, 'error')
return
end

if #(playerCoords - sellingLocation) > 10 then
notifyPlayer(source, Lang.tooFarFromSellPoint, 'error')
return
end

if itemCount > 0 then
local sellPriceRange = Config.sell[itemType]
Expand All @@ -166,12 +248,11 @@ RegisterServerEvent('tr-lumberjack:server:sellitem', function(args)
end
end)


AddEventHandler('onServerResourceStart', function(resourceName)
if resourceName == 'ox_inventory' or resourceName == GetCurrentResourceName() then
exports.ox_inventory:RegisterShop("contractorshop", {
name = Lang.depoShop,
inventory = Config.depoItems
})
end
end)
end)
1 change: 1 addition & 0 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Config.lumberDepo = vector4(1167.59, -1347.38, 33.915, 267.685)
Config.deliverySuperPed = vector4(-606.472, 5311.273, 69.432, 255.341)
Config.deliveryTasker = vector4(-841.132, 5401.732, 33.615, 305.278)
Config.craftingBench = vector4(-556.287, 5326.222, 72.6, 160.741) --This is also the same as the Target.lua
Config.deliverDropOff = vector3(1239.427, -3149.191, 5.528) -- Drop Off Location for delivery task
Config.seller1 = vector4(906.558, -1514.62, 29.413, 178.657) -- First Sale point (Firewood and Planks)
Config.seller2 = vector4(925.812, -1560.319, 29.74, 95.023) -- Second Sale point (Toys and handles)
-- Camera Coords for NPC Diallog
Expand Down

0 comments on commit 1146b6e

Please sign in to comment.