Could be way better in terms of optimization… For example, use RegisterKeyMapping instead of IsControlJustPressed, or rewrite things that runs on every tick like :
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
for k, v in pairs(Config.Farm.Type) do
local playerPed = PlayerPedId()
local playercoords = GetEntityCoords(playerPed)
local x, y, z = table.unpack(v.coords)
local distance = Vdist(playercoords, x, y, z)
if distance < 12 then
ShowHelp("DrĂĽcke ~INPUT_CONTEXT~ um ~y~" ..v.Label.. "~w~ zu farmen", true)
if IsControlJustPressed(0, 38) then
Notify("Du sammelts jetzt ~y~" ..v.Count.. "~w~ " ..v.Label)
local ped = PlayerPedId()
TaskStartScenarioInPlace(ped, v.Anim, 0, true)
Citizen.Wait(v.Time)
ClearPedTasksImmediately(ped)
PlaySound(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)
PlaySoundFrontend(-1, "MEDAL_GOLD", "HUD_AWARDS", 0);
Notify("Du hast " ..v.Count.. " ~g~" ..v.Label.. "~w~ Gesammelt")
local item = v.Value
local count = v.Count
TriggerServerEvent("gmw_farm:giveItem", item, count)
end
end
end
end
end)
To :
CreateThread(function()
local playerPed = PlayerPedId()
local playercoords = GetEntityCoords(playerPed)
local x, y, z = table.unpack(v.coords)
local distance = Vdist(playercoords, x, y, z)
while true do
local sleep = 5000
for k, v in pairs(Config.Farm.Type) do
if distance < 12 then
sleep = 0
ShowHelp("DrĂĽcke ~INPUT_CONTEXT~ um ~y~" ..v.Label.. "~w~ zu farmen", true)
if IsControlJustPressed(0, 38) then
Notify("Du sammelts jetzt ~y~" ..v.Count.. "~w~ " ..v.Label)
local ped = PlayerPedId()
TaskStartScenarioInPlace(ped, v.Anim, 0, true)
Citizen.Wait(v.Time)
ClearPedTasksImmediately(ped)
PlaySound(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)
PlaySoundFrontend(-1, "MEDAL_GOLD", "HUD_AWARDS", 0);
Notify("Du hast " ..v.Count.. " ~g~" ..v.Label.. "~w~ Gesammelt")
local item = v.Value
local count = v.Count
TriggerServerEvent("gmw_farm:giveItem", item, count)
end
end
end
Wait(sleep)
end
end)