Skip to content

Commit

Permalink
various fixes and improvements (#99)
Browse files Browse the repository at this point in the history
* various fixes and improvements

* Update controllers.lua

* Update adminmenu.lua
  • Loading branch information
iseeyoucopy authored Dec 9, 2024
1 parent 627f419 commit 5db7fbc
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 96 deletions.
16 changes: 6 additions & 10 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ local ranchBlip = nil

RegisterNetEvent('vorp:SelectedCharacter')
AddEventHandler('vorp:SelectedCharacter', function()
TriggerServerEvent('bcc-ranch:AdminCheck')
IsAdmin = BccUtils.RPC:CallAsync("bcc-ranch:AdminCheck")
--TriggerServerEvent('bcc-ranch:AdminCheck')
local player = GetPlayerServerId(tonumber(PlayerId()))
TriggerServerEvent("bcc-ranch:StoreAllPlayers", player)
TriggerServerEvent('bcc-ranch:CheckIfPlayerOwnsARanch')
Expand All @@ -12,7 +13,8 @@ end)

RegisterCommand(Config.commands.devModeCommand, function()
if Config.devMode then
TriggerServerEvent('bcc-ranch:AdminCheck')
IsAdmin = BccUtils.RPC:CallAsync("bcc-ranch:AdminCheck")
--TriggerServerEvent('bcc-ranch:AdminCheck')
local player = GetPlayerServerId(tonumber(PlayerId()))
TriggerServerEvent("bcc-ranch:StoreAllPlayers", player)
TriggerServerEvent('bcc-ranch:CheckIfPlayerOwnsARanch')
Expand All @@ -21,9 +23,7 @@ end
end)

-- Handle ranch ownership notification
BccUtils.RPC:Register("bcc-ranch:PlayerOwnsARanch", function(params)
local ranchData = params.ranchData
local isOwnerOfRanch = params.isOwnerOfRanch
RegisterNetEvent("bcc-ranch:PlayerOwnsARanch", function(ranchData, isOwnerOfRanch)

RanchData = ranchData
if isOwnerOfRanch then
Expand Down Expand Up @@ -86,10 +86,6 @@ BccUtils.RPC:Register("bcc-ranch:PlayerOwnsARanch", function(params)
end
end)

RegisterNetEvent("bcc-ranch:IsAdminClientReceiver", function(admin)
IsAdmin = admin
end)

RegisterNetEvent('bcc-ranch:UpdateRanchData', function (ranchData)
if not IsInMission then
IsInMission = true -- This is to stop the player from being able to manage their ranch while the Ranchdata is updating
Expand Down Expand Up @@ -119,4 +115,4 @@ AddEventHandler('onResourceStop', function(resourceName)
end
BCCRanchMenu:Close()
end
end)
end)
33 changes: 14 additions & 19 deletions client/services/caretaking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ local function setCoords(choreType) --done inside of a function as you cannot as
devPrint("Ranch radius limit: " .. RanchData.ranch_radius_limit)

if RanchData.ranchcoordsVector3 and RanchData.ranch_radius_limit and #(RanchData.ranchcoordsVector3 - pCoords) <= tonumber(RanchData.ranch_radius_limit) then
TriggerServerEvent('bcc-ranch:InsertChoreCoordsIntoDB', pCoords, RanchData.ranchid, selectedOption)
break
BccUtils.RPC:Call('bcc-ranch:InsertChoreCoordsIntoDB', { choreCoords = pCoords, ranchId = RanchData.ranchid, choreType = selectedOption }, function(success)
if success then
devPrint("Chore coordinates successfully inserted.")
else
devPrint("Failed to insert chore coordinates.")
end
end)
else
VORPcore.NotifyRightTip(_U("tooFarFromRanch"), 4000)
end
end
end
if IsControlJustReleased(0, 0x9959A6F0) then
break
Expand Down Expand Up @@ -66,8 +71,7 @@ local function choreMenu(choreType, menuTitle)
label = _U("startChore"),
style = {}
}, function()
-- Use RPC:Call to communicate with the server
BccUtils.RPC:Notify("bcc-ranch:ChoreCheckRanchCond", { ranchId = RanchData.ranchid, choreType = choreType })
BccUtils.RPC:Call("bcc-ranch:ChoreCheckRanchCond", { ranchId = RanchData.ranchid, choreType = choreType })
end)


Expand Down Expand Up @@ -161,7 +165,6 @@ BccUtils.RPC:Register("bcc-ranch:StartChoreClient", function(params)
if not RanchData or not choreType then
devPrint("[ERROR] RanchData or choreType is missing.")
VORPcore.NotifyRightTip(_U("invalidRanchDataOrChoreType"), 4000)
cb(false)
return
end

Expand Down Expand Up @@ -217,7 +220,6 @@ BccUtils.RPC:Register("bcc-ranch:StartChoreClient", function(params)
else
devPrint("[ERROR] Invalid choreType: " .. tostring(choreType))
VORPcore.NotifyRightTip(_U("invalidChoreType"), 4000)
cb(false)
IsInMission = false
return
end
Expand All @@ -227,7 +229,6 @@ BccUtils.RPC:Register("bcc-ranch:StartChoreClient", function(params)
devPrint("[ERROR] Missing or invalid chore coordinates for choreType: " .. choreType)
VORPcore.NotifyRightTip("Invalid Coordinates", 4000)
IsInMission = false
cb(false)
return
end

Expand All @@ -246,7 +247,6 @@ BccUtils.RPC:Register("bcc-ranch:StartChoreClient", function(params)
blip:Remove()
IsInMission = false
VORPcore.NotifyRightTip(_U("failed"), 4000)
cb(false)
break
end

Expand All @@ -264,7 +264,6 @@ BccUtils.RPC:Register("bcc-ranch:StartChoreClient", function(params)
VORPcore.NotifyRightTip(_U("failed"), 4000)
blip:Remove()
IsInMission = false
cb(false)
else
if choreType == 'scooppoop' then
BccUtils.RPC:Call("bcc-ranch:AddItem", { item = ConfigRanch.ranchSetup.choreSetup.shovelPoopRewardItem, amount = ConfigRanch.ranchSetup.choreSetup.shovelPoopRewardAmount }, function(success)
Expand All @@ -275,20 +274,17 @@ BccUtils.RPC:Register("bcc-ranch:StartChoreClient", function(params)
end
end)
end
devPrint("Sending IncreaseRanchCond RPC. RanchId:", RanchData.ranchid, "Amount:", incAmount)
--[[BccUtils.RPC:Call("bcc-ranch:IncreaseRanchCond", { ranchId = RanchData.ranchid, amount = incAmount }, function(success)
devPrint("IncreaseRanchCond RPC Response: success =", success)
devPrint("[DEBUG] Sending IncreaseRanchCond RPC. RanchId:", RanchData.ranchid, "Amount:", incAmount)
BccUtils.RPC:Call('bcc-ranch:IncreaseRanchCond', { ranchId = RanchData.ranchid, amount = incAmount }, function(success, message)
if success then
VORPcore.NotifyRightTip(_U("choreComplete"), 4000)
devPrint("[DEBUG] Successfully increased ranch condition. Message:", message)
else
VORPcore.NotifyRightTip(_U("updateFailed"), 4000)
devPrint("[ERROR] Failed to increase ranch condition. Message:", message)
end
end) ]]--
TriggerServerEvent('bcc-ranch:IncreaseRanchCond', RanchData.ranchid, incAmount)
end)
VORPcore.NotifyRightTip(_U("choreComplete"), 4000)
blip:Remove()
IsInMission = false
cb(true)
end
end

Expand All @@ -315,7 +311,6 @@ BccUtils.RPC:Register("bcc-ranch:StartChoreClient", function(params)
IsInMission = false
VORPcore.NotifyRightTip(_U("failed"), 4000)
SetPedToRagdoll(PlayerPedId(), 1000, 1000, 0, 0, 0, 0)
cb(false)
end
end)
else
Expand Down
79 changes: 54 additions & 25 deletions client/services/ledger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,93 @@ function LedgerMenu()
slot = "header",
style = {}
})
mainLedgerPage:RegisterElement("button", {
label = _U("ledgerAmount") .. " " .. RanchData.ledger,
mainLedgerPage:RegisterElement('subheader', {
value = _U("ledgerAmount") .. " " .. RanchData.ledger,
slot = "header",
style = {}
}, function()
--Leave empty as this is just to dispaly the ledger amount
end)
})
mainLedgerPage:RegisterElement('line', {
slot = "content",
style = {}
})

local depositAmount = ''
mainLedgerPage:RegisterElement("input", {
label = _U("deposit"),
placeholder = _U("amount"),
style = {}
}, function(data)
if string.find(data.value, "-") or string.find(data.value, "'") or string.find(data.value, '"') then -- checking for ' or " to prevent sql injection and - to prevent negative numbers
VORPcore.NotifyRightTip(_U("inputProtectionError"), 4000)
depositAmount = ''
else
depositAmount = data.value
end
depositAmount = data.value -- Save the input for later validation
end)
mainLedgerPage:RegisterElement("button", {
label = _U("confirm"),
style = {}
}, function()
if depositAmount ~= "" and depositAmount then -- make sure its not empty or nil
TriggerServerEvent('bcc-ranch:AffectLedger', RanchData.ranchid, 'deposit', depositAmount)
MainRanchMenu()
-- Validate deposit amount on confirmation
local sanitizedDeposit = tonumber(depositAmount)
if sanitizedDeposit and sanitizedDeposit > 0 then
BccUtils.RPC:Call('bcc-ranch:AffectLedger', { ranchId = RanchData.ranchid, type = 'deposit', amount = sanitizedDeposit }, function(success)
if success then
devPrint("Successfully deposited to ledger.")
MainRanchMenu()
else
devPrint("Failed to deposit to ledger.")
end
end)
else
VORPcore.NotifyRightTip(_U("invalidAmount"), 4000)
end
end)

mainLedgerPage:RegisterElement('line', {
slot = "content",
style = {}
})

local withdrawAmount = ''
mainLedgerPage:RegisterElement("input", {
label = _U("withdraw"),
placeholder = _U("amount"),
style = {}
}, function(data)
if string.find(data.value, "-") or string.find(data.value, "'") or string.find(data.value, '"') then -- checking for ' or " to prevent sql injection and - to prevent negative numbers
VORPcore.NotifyRightTip(_U("inputProtectionError"), 4000)
withdrawAmount = ''
else
withdrawAmount = data.value
end
withdrawAmount = data.value -- Save the input for later validation
end)
mainLedgerPage:RegisterElement("button", {
label = _U("confirm"),
style = {}
}, function()
if withdrawAmount ~= "" and withdrawAmount then -- make sure its not empty or nil
TriggerServerEvent('bcc-ranch:AffectLedger', RanchData.ranchid, "withdraw", withdrawAmount)
MainRanchMenu()
-- Validate withdraw amount on confirmation
local sanitizedWithdraw = tonumber(withdrawAmount)
if sanitizedWithdraw and sanitizedWithdraw > 0 then
BccUtils.RPC:Call('bcc-ranch:AffectLedger', { ranchId = RanchData.ranchid, type = 'withdraw', amount = sanitizedWithdraw }, function(success)
if success then
devPrint("Successfully withdrew from ledger.")
MainRanchMenu()
else
devPrint("Failed to withdraw from ledger.")
end
end)
else
VORPcore.NotifyRightTip(_U("invalidAmount"), 4000)
end
end)

mainLedgerPage:RegisterElement('line', {
slot = "footer",
style = {}
})
mainLedgerPage:RegisterElement("button", {
label = _U("back"),
slot = "footer",
style = {}
}, function()
MainRanchMenu()
end)

mainLedgerPage:RegisterElement('bottomline', {
slot = "footer",
style = {}
})
BCCRanchMenu:Open({
startupPage = mainLedgerPage
})
end
end
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ dependency {
'bcc-minigames',
}

version '2.3.3'
version '2.3.4'
3 changes: 2 additions & 1 deletion languages/de_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@ Locales["de_lang"] = {
taxAmountInvalid = "Taxes must be a non-negative number. Please enter a valid tax amount.",
ranchNotFound = "Previous ranch not found. The ranch ID has been reset.",
ranchAlreadyExists = "You already own a ranch. Only one ranch per character is allowed.",
ranchCreationFailed = "Ranch creation failed. Please try again later."
ranchCreationFailed = "Ranch creation failed. Please try again later.",
invalidAmount = "Invalid amount"
}
3 changes: 2 additions & 1 deletion languages/en_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ Locales["en_lang"] = {
taxAmountInvalid = "Taxes must be a non-negative number. Please enter a valid tax amount.",
ranchNotFound = "Previous ranch not found. The ranch ID has been reset.",
ranchAlreadyExists = "You already own a ranch. Only one ranch per character is allowed.",
ranchCreationFailed = "Ranch creation failed. Please try again later."
ranchCreationFailed = "Ranch creation failed. Please try again later.",
invalidAmount = "Invalid amount"
}
3 changes: 2 additions & 1 deletion languages/fr_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ Locales["fr_lang"] = {
taxAmountInvalid = "Taxes must be a non-negative number. Please enter a valid tax amount.",
ranchNotFound = "Previous ranch not found. The ranch ID has been reset.",
ranchAlreadyExists = "You already own a ranch. Only one ranch per character is allowed.",
ranchCreationFailed = "Ranch creation failed. Please try again later."
ranchCreationFailed = "Ranch creation failed. Please try again later.",
invalidAmount = "Invalid amount"
}
3 changes: 2 additions & 1 deletion languages/pt_br_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ Locales["pt_br_lang"] = {
taxAmountInvalid = "Taxes must be a non-negative number. Please enter a valid tax amount.",
ranchNotFound = "Previous ranch not found. The ranch ID has been reset.",
ranchAlreadyExists = "You already own a ranch. Only one ranch per character is allowed.",
ranchCreationFailed = "Ranch creation failed. Please try again later."
ranchCreationFailed = "Ranch creation failed. Please try again later.",
invalidAmount = "Invalid amount"
}
3 changes: 2 additions & 1 deletion languages/pt_pt_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ Locales["pt_pt_lang"] = {
taxAmountInvalid = "Taxes must be a non-negative number. Please enter a valid tax amount.",
ranchNotFound = "Previous ranch not found. The ranch ID has been reset.",
ranchAlreadyExists = "You already own a ranch. Only one ranch per character is allowed.",
ranchCreationFailed = "Ranch creation failed. Please try again later."
ranchCreationFailed = "Ranch creation failed. Please try again later.",
invalidAmount = "Invalid amount"
}
3 changes: 2 additions & 1 deletion languages/ro_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ Locales["ro_lang"] = {
taxAmountInvalid = "Taxes must be a non-negative number. Please enter a valid tax amount.",
ranchNotFound = "Previous ranch not found. The ranch ID has been reset.",
ranchAlreadyExists = "You already own a ranch. Only one ranch per character is allowed.",
ranchCreationFailed = "Ranch creation failed. Please try again later."
ranchCreationFailed = "Ranch creation failed. Please try again later.",
invalidAmount = "Invalid amount"
}
Loading

0 comments on commit 5db7fbc

Please sign in to comment.