-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFishing_trigger_farm.lua
More file actions
298 lines (245 loc) · 12.3 KB
/
Fishing_trigger_farm.lua
File metadata and controls
298 lines (245 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
-- ─────────────────────────────────────────
-- Fishing Trigger Widget
-- Server: STARDAWG CITY
-- Instructions: YOU MUST select resource qb-afkfishing to hook
-- DELETE key → open / close
-- X button → close
-- Drag via header, left-click to toggle
-- ─────────────────────────────────────────
local isVisible = true
local isActive = false
local triggerCount = 0
local loopSpeed = 0 -- ms delay (1000 = slowest, 0 = fastest)
local loopLimit = 0 -- 0 = infinite, >0 = stop after N loops
-- DELETE key debounce
local lastKeyPress = 0
-- Widget top-left position (normalised 0.0 – 1.0)
local wx = 0.05
local wy = 0.05
-- Dimensions
local WW = 0.135
local HDR_H = 0.042
local BOD_H = 0.196 -- taller to fit sell button
-- Drag state (header)
local isDragging = false
local dragOffX, dragOffY = 0.0, 0.0
-- Drag state (slider)
local isSliderDragging = false
-- ── Helpers ───────────────────────────────────────────────────────────────
local function getCursor()
return GetDisabledControlNormal(0, 239),
GetDisabledControlNormal(0, 240)
end
local function inBounds(lx, ly, w, h)
local mx, my = getCursor()
return mx >= lx and mx <= lx + w and my >= ly and my <= ly + h
end
local function dRect(lx, ly, w, h, r, g, b, a)
DrawRect(lx + w * 0.5, ly + h * 0.5, w, h, r, g, b, a)
end
local function dText(str, x, y, scale, r, g, b, a, align)
SetTextFont(4)
SetTextScale(0.0, scale)
SetTextColour(r, g, b, a)
SetTextJustification(align or 1)
SetTextEntry("STRING")
AddTextComponentString(tostring(str))
DrawText(x, y)
end
local function clamp(v, lo, hi)
return math.max(lo, math.min(v, hi))
end
-- ── Trigger loop ──────────────────────────────────────────────────────────
local function startLoop()
Citizen.CreateThread(function()
while isActive do
if loopLimit > 0 and triggerCount >= loopLimit then
isActive = false
break
end
TriggerServerEvent('qb-afkfishing:server:giveCatch')
triggerCount = triggerCount + 1
Citizen.Wait(loopSpeed)
end
end)
end
-- ── Open keyboard to set loop limit ──────────────────────────────────────
local function promptLoopLimit()
Citizen.CreateThread(function()
DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP1", "", tostring(loopLimit == 0 and "" or loopLimit), "", "", "", 6)
while UpdateOnscreenKeyboard() == 0 do
Citizen.Wait(0)
end
local result = GetOnscreenKeyboardResult()
if result and result ~= "" then
local n = tonumber(result)
if n and n >= 0 then
loopLimit = math.floor(n)
end
end
end)
end
-- ── Main draw / input thread ──────────────────────────────────────────────
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustPressed(0, 178) and GetGameTimer() - lastKeyPress > 500 then
lastKeyPress = GetGameTimer()
isVisible = not isVisible
if not isVisible and isActive then
isActive = false
end
end
if not isVisible then goto continue end
SetMouseCursorActiveThisFrame()
EnableControlAction(0, 239, true)
EnableControlAction(0, 240, true)
EnableControlAction(0, 237, true)
EnableControlAction(0, 178, true)
local mx, my = getCursor()
local clicked = IsDisabledControlJustPressed(0, 237)
local held = IsDisabledControlPressed(0, 237)
-- ── Header ───────────────────────────────────────────────────────
dRect(wx, wy, WW, HDR_H, 22, 42, 58, 235) -- dark blue tint for fishing
dText("Fishing Trigger", wx + 0.010, wy + 0.011, 0.25, 180, 210, 235, 255, 1)
-- X close button
local xBtnW = 0.012
local xBtnH = 0.016
local xBtnX = wx + WW - xBtnW - 0.006
local xBtnY = wy + (HDR_H - xBtnH) * 0.5
local xHovered = inBounds(xBtnX, xBtnY, xBtnW, xBtnH)
local xColR = xHovered and 200 or 110
local xColG = xHovered and 55 or 35
local xColB = xHovered and 55 or 35
dRect(xBtnX, xBtnY, xBtnW, xBtnH, xColR, xColG, xColB, 220)
dText("X", xBtnX + xBtnW * 0.5, xBtnY + 0.001, 0.19, 255, 255, 255, 230, 0)
if clicked and xHovered then
isVisible = false
lastKeyPress = GetGameTimer()
if isActive then isActive = false end
goto continue
end
-- ── Body ─────────────────────────────────────────────────────────
dRect(wx, wy + HDR_H, WW, BOD_H, 17, 17, 17, 235)
local pad = 0.010
-- ── Row 1 – Toggle button (+0.012) ────────────────────────────────
local btnX = wx + pad
local btnY = wy + HDR_H + 0.012
local btnW = WW - pad * 2
local btnH = 0.036
if isActive then
dRect(btnX, btnY, btnW, btnH, 26, 74, 26, 255)
dText("STOP LOOP", wx + WW * 0.5, btnY + 0.009, 0.24, 76, 222, 76, 255, 0)
else
dRect(btnX, btnY, btnW, btnH, 38, 38, 38, 255)
dText("START LOOP", wx + WW * 0.5, btnY + 0.009, 0.24, 140, 140, 140, 255, 0)
end
-- ── Row 2 – Status indicator (+0.058) ────────────────────────────
local dotX = wx + 0.012
local dotY = wy + HDR_H + 0.058
if isActive then
dRect(dotX, dotY, 0.006, 0.012, 76, 222, 76, 255)
dText("Running", dotX + 0.011, dotY - 0.001, 0.21, 76, 222, 76, 255, 1)
else
dRect(dotX, dotY, 0.006, 0.012, 68, 68, 68, 255)
dText("Inactive", dotX + 0.011, dotY - 0.001, 0.21, 85, 85, 85, 255, 1)
end
-- ── Row 3 – Max loops (+0.078) ────────────────────────────────────
local limY = wy + HDR_H + 0.078
local limitDisplay = loopLimit == 0 and "inf" or tostring(loopLimit)
dText("Max Loops:", wx + pad, limY, 0.20, 100, 100, 100, 255, 1)
dText(limitDisplay, wx + WW * 0.5, limY, 0.20, 160, 160, 160, 255, 0)
local setBtnW = 0.028
local setBtnH = 0.020
local setBtnX = wx + WW - pad - setBtnW
local setBtnY = limY - 0.003
local setHov = inBounds(setBtnX, setBtnY, setBtnW, setBtnH)
dRect(setBtnX, setBtnY, setBtnW, setBtnH, setHov and 55 or 38, setHov and 55 or 38, setHov and 55 or 38, 255)
dText("SET", setBtnX + 0.004, setBtnY + 0.003, 0.19, 160, 160, 160, 255, 1)
if clicked and not isDragging and setHov then
promptLoopLimit()
end
-- ── Row 4 – Slider label (+0.106) ────────────────────────────────
local sldPad = 0.012
local lblY = wy + HDR_H + 0.106
dText("Loop Speed", wx + sldPad, lblY, 0.20, 100, 100, 100, 255, 1)
dText(loopSpeed .. "ms", wx + WW - sldPad, lblY, 0.20, 130, 130, 130, 255, 2)
-- ── Row 5 – Slider track (+0.131) ────────────────────────────────
local sldX = wx + sldPad
local sldW = WW - sldPad * 2
local sldTrkH = 0.006
local sldHW = 0.009
local sldHH = 0.020
local sldY = wy + HDR_H + 0.131
local t = 1.0 - (loopSpeed / 1000.0)
local handleX = sldX + t * sldW - sldHW * 0.5
dRect(sldX, sldY, sldW, sldTrkH, 45, 45, 45, 255)
if t > 0 then
dRect(sldX, sldY, t * sldW, sldTrkH, 76, 160, 76, 255)
end
local hR, hG, hB = 180, 180, 180
if isSliderDragging then hR, hG, hB = 220, 220, 220 end
dRect(handleX, sldY - (sldHH - sldTrkH) * 0.5, sldHW, sldHH, hR, hG, hB, 255)
-- ── Row 6 – Loop count centred (+0.150) ───────────────────────────
dText("Loops: " .. triggerCount,
wx + WW * 0.5,
wy + HDR_H + 0.150,
0.20, 68, 68, 68, 255, 0)
-- ── Divider line (+0.164) ─────────────────────────────────────────
dRect(wx + pad, wy + HDR_H + 0.163, WW - pad * 2, 0.001, 45, 45, 45, 180)
-- ── Row 7 – Sell Fish button (+0.170) ────────────────────────────
local sellBtnX = wx + pad
local sellBtnY = wy + HDR_H + 0.170
local sellBtnW = WW - pad * 2
local sellBtnH = 0.018
local sellHov = inBounds(sellBtnX, sellBtnY, sellBtnW, sellBtnH)
if sellHov then
dRect(sellBtnX, sellBtnY, sellBtnW, sellBtnH, 30, 80, 110, 255)
dText("SELL FISH", wx + WW * 0.5, sellBtnY + 0.003, 0.21, 120, 200, 240, 255, 0)
else
dRect(sellBtnX, sellBtnY, sellBtnW, sellBtnH, 25, 50, 70, 255)
dText("SELL FISH", wx + WW * 0.5, sellBtnY + 0.003, 0.21, 80, 150, 190, 255, 0)
end
if clicked and not isDragging and sellHov then
TriggerServerEvent('qb-afkfishing:server:sellAllFish')
end
-- ═══════════════════════════════════════════════════════════════════
-- INPUT HANDLING
-- ═══════════════════════════════════════════════════════════════════
-- ── Header drag ───────────────────────────────────────────────────
if clicked and inBounds(wx, wy, WW, HDR_H) and not xHovered then
isDragging = true
dragOffX = mx - wx
dragOffY = my - wy
end
if isDragging then
if held then
wx = clamp(mx - dragOffX, 0.0, 1.0 - WW)
wy = clamp(my - dragOffY, 0.0, 1.0 - HDR_H - BOD_H)
else
isDragging = false
end
end
-- ── Slider drag ───────────────────────────────────────────────────
local sldHitY = sldY - 0.014
local sldHitH = sldTrkH + 0.028
if clicked and not isDragging and inBounds(sldX, sldHitY, sldW, sldHitH) then
isSliderDragging = true
end
if isSliderDragging then
if held then
local newT = clamp((mx - sldX) / sldW, 0.0, 1.0)
loopSpeed = math.floor(((1.0 - newT) * 1000.0) / 50 + 0.5) * 50
else
isSliderDragging = false
end
end
-- ── Toggle button ─────────────────────────────────────────────────
if clicked and not isDragging and not isSliderDragging and not setHov and not sellHov and inBounds(btnX, btnY, btnW, btnH) then
isActive = not isActive
triggerCount = 0
if isActive then startLoop() end
end
::continue::
end
end)