Skip to content

Commit

Permalink
refactor: (bpt_farmer) await callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Mar 25, 2024
1 parent dacc97f commit b52932b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
local playerPed

RegisterNetEvent("farmer:freeze")
AddEventHandler("farmer:freeze", function()
RegisterNetEvent("farmer:freeze", function()
playerPed = PlayerPedId()
ClearPedTasks(PlayerPedId())
FreezeEntityPosition(playerPed, true)
end)

RegisterNetEvent("farmer:unfreeze")
AddEventHandler("farmer:freeze", function()
RegisterNetEvent("farmer:unfreeze", function()
playerPed = PlayerPedId()
FreezeEntityPosition(playerPed, false)
ClearPedTasks(PlayerPedId())
end)

RegisterNetEvent("farmer:anim")
AddEventHandler("farmer:anim", function()
RegisterNetEvent("farmer:anim", function()
local lib, anim = "amb@prop_human_bum_bin@idle_b", "idle_d"
ESX.Streaming.RequestAnimDict(lib, function()
TaskPlayAnim(PlayerPedId(), lib, anim, 1.0, -3.0, 5000, 0, 0, false, false, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ local Keys = {
local incollect = false

ESX = exports["es_extended"]:getSharedObject()
RegisterNetEvent("esx:playerLoaded")
AddEventHandler("esx:playerLoaded", function(xPlayer)
RegisterNetEvent("esx:playerLoaded", function(xPlayer)
PlayerData = xPlayer
end)

Expand Down
12 changes: 4 additions & 8 deletions server-data/resources/[bpt_addons]/bpt_farmer/server/main.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
ESX = exports["es_extended"]:getSharedObject()

-- collection potato
RegisterServerEvent("farmer:collectionpotato")
AddEventHandler("farmer:collectionpotato", function()
RegisterServerEvent("farmer:collectionpotato", function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local potato = xPlayer.getInventoryItem("potato").count
Expand All @@ -16,8 +15,7 @@ AddEventHandler("farmer:collectionpotato", function()
end)

-- collection cotton
RegisterServerEvent("farmer:collectioncotton")
AddEventHandler("farmer:collectioncotton", function()
RegisterServerEvent("farmer:collectioncotton", function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local cotton = xPlayer.getInventoryItem("cotton").count
Expand All @@ -31,8 +29,7 @@ AddEventHandler("farmer:collectioncotton", function()
end)

-- collection apple
RegisterServerEvent("farmer:collectionapple")
AddEventHandler("farmer:collectionapple", function()
RegisterServerEvent("farmer:collectionapple", function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local apple = xPlayer.getInventoryItem("apple").count
Expand All @@ -46,8 +43,7 @@ AddEventHandler("farmer:collectionapple", function()
end)

-- collection grain
RegisterServerEvent("farmer:collectiongrain")
AddEventHandler("farmer:collectiongrain", function()
RegisterServerEvent("farmer:collectiongrain", function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local grain = xPlayer.getInventoryItem("grain").count
Expand Down

0 comments on commit b52932b

Please sign in to comment.