Skip to content

Commit a0859c7

Browse files
committed
feat(client): add blips
1 parent 862d8f0 commit a0859c7

11 files changed

Lines changed: 143 additions & 43 deletions

File tree

client/cracking.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local effectsLoop = false
1111

1212
local function createMiningEffects(anim, oreCoords)
1313
lib.playAnim(cache.ped, anim.anim, anim.dict, 8.0, 8.0,
14-
-1, 1, 1.0, false, false, false)
14+
-1, 1, 1.0, false, 0, false)
1515
lib.requestNamedPtfxAsset('core', 10000)
1616
CreateThread(function()
1717
while effectsLoop do
@@ -97,6 +97,16 @@ local function buildCrackPoints(crackPoint)
9797
looted = crackPoint.looted,
9898
})
9999

100+
if crackPoint.blip.enabled then
101+
CreateBlip({
102+
coords = crackPoint.blip.coords,
103+
sprite = crackPoint.blip.sprite,
104+
color = crackPoint.blip.color,
105+
scale = crackPoint.blip.scale,
106+
name = crackPoint.blip.name,
107+
})
108+
end
109+
100110
local targetOptions = {}
101111
if config.crackingTarget then
102112
targetOptions = {

client/jewelry.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ local function createJewelryPoint(point)
8585
options = shopOptions,
8686
})
8787

88+
if point.blip.enabled then
89+
CreateBlip({
90+
coords = point.blip.coords,
91+
sprite = point.blip.sprite,
92+
color = point.blip.color,
93+
scale = point.blip.scale,
94+
name = point.blip.name,
95+
})
96+
end
97+
8898
function pedPoint:onEnter()
8999
if config.jewelryTarget and not self.prop then
90100
self.targetId = config.addSphereTarget({

client/main.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
local blips = {}
2+
13
---@param params { text: string, coords: vector3, scale?: number|vector2, font?: number, color?: vector4, enableDropShadow?: boolean, enableOutline?: boolean }
24
function DrawText3d(params) -- luacheck: ignore
35
local isScaleparamANumber = type(params.scale) == "number"
46
local text = params.text
57
local coords = params.coords
8+
---@diagnostic disable-next-line: param-type-mismatch
69
local scale = (isScaleparamANumber and vec2(params.scale, params.scale))
710
or params.scale
811
or vec2(0.35, 0.35)
@@ -29,11 +32,29 @@ function DrawText3d(params) -- luacheck: ignore
2932
ClearDrawOrigin()
3033
end
3134

35+
function CreateBlip(data)
36+
local blip = AddBlipForCoord(data.coords.x, data.coords.y, data.coords.z)
37+
SetBlipSprite(blip, data.sprite)
38+
SetBlipDisplay(blip, 4)
39+
SetBlipScale(blip, data.scale or 0.8)
40+
SetBlipColour(blip, data.color or 2)
41+
SetBlipAsShortRange(blip, true)
42+
if data.name then
43+
BeginTextCommandSetBlipName('STRING')
44+
AddTextComponentSubstringPlayerName(data.name)
45+
EndTextCommandSetBlipName(blip)
46+
end
47+
blips[#blips + 1] = blip
48+
end
49+
3250
AddEventHandler('onResourceStop', function(resourceName)
3351
if resourceName ~= cache.resource then return end
3452
local points = lib.points.getAllPoints()
3553
for i = 1, #points do
3654
local point = points[i]
3755
point:onExit()
3856
end
57+
for i = 1, #blips do
58+
RemoveBlip(blips[i])
59+
end
3960
end)

client/mining.lua

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ end
6969

7070
local function createMiningEffects(type, toolEntity, oreEntity)
7171
lib.playAnim(cache.ped, playerState.red40_mining.anim.anim, playerState.red40_mining.anim.dict, 8.0, 8.0,
72-
-1, 1, 1.0, false, false, false)
72+
-1, 1, 1.0, false, 0, false)
7373
if type == 'pickaxe' then
7474
lib.print.debug('You could add a particle effect here')
7575
elseif type == 'drill' then
@@ -108,8 +108,10 @@ local function createMiningEffects(type, toolEntity, oreEntity)
108108
end
109109

110110
lib.callback.register('red40_mining:client:mineSpot', function(waitTime, toolType)
111-
--TODO add animation, skillcheck (optional), and sounds here (tool config based)
112111
local closestOre = lib.points.getClosestPoint()
112+
113+
if not closestOre then return end
114+
113115
local oreCoords = GetEntityCoords(closestOre.propNumber)
114116
TaskGoStraightToCoord(cache.ped, oreCoords.x, oreCoords.y, oreCoords.z, 0.5, 400, 0.0, 0)
115117
while #(oreCoords - GetEntityCoords(cache.ped)) > 2 do
@@ -254,17 +256,26 @@ end
254256

255257

256258
CreateThread(function()
257-
local points = lib.callback.await('red40_mining:server:getMiningPoints')
259+
local points, lightPoints, blips = lib.callback.await('red40_mining:server:getMiningPoints')
258260

259261
for i = 1, #points do
260262
local point = points[i]
261263
buildOrePoints(point)
262264
end
263265

264-
local lightPoints = lib.callback.await('red40_mining:server:getMiningLightPoints')
265-
266266
for i = 1, #lightPoints do
267267
local point = lightPoints[i]
268268
buildLightPoints(point)
269269
end
270+
271+
for i = 1, #blips do
272+
local blip = blips[i]
273+
CreateBlip({
274+
coords = blip.coords,
275+
sprite = blip.sprite,
276+
color = blip.color,
277+
scale = blip.scale,
278+
name = blip.name,
279+
})
280+
end
270281
end)

client/panning.lua

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local effectsLoop = false
1111

1212
local function createPanningEffects(type, toolEntity)
1313
lib.playAnim(cache.ped, playerState.red40_mining.anim.anim, playerState.red40_mining.anim.dict, 8.0, 8.0,
14-
-1, 1, 1.0, false, false, false)
14+
-1, 1, 1.0, false, 0, false)
1515
if type == 'pan' then
1616
lib.requestNamedPtfxAsset('core', 10000)
1717
CreateThread(function()
@@ -66,11 +66,22 @@ lib.callback.register('red40_mining:client:panSpot', function(waitTime)
6666
end)
6767

6868
local function buildPanningZone(zone)
69-
lib.zones.poly({
70-
points = zone.points,
71-
thickness = zone.thickness,
72-
debug = true,
73-
})
69+
if zone.debug then
70+
lib.zones.poly({
71+
points = zone.points,
72+
thickness = zone.thickness,
73+
debug = true,
74+
})
75+
end
76+
if zone.blip.enabled then
77+
CreateBlip({
78+
coords = zone.blip.coords,
79+
sprite = zone.blip.sprite,
80+
color = zone.blip.color,
81+
scale = zone.blip.scale,
82+
name = zone.blip.name,
83+
})
84+
end
7485
end
7586

7687
CreateThread(function()

client/peds.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ local function inputBox(action, shopName, item, maxAmount)
2121
end
2222

2323
local function openSellMenu(shopName)
24-
--TODO: query server for list of sellable items and build ox_lib context menu
2524
local itemsForSale = lib.callback.await('red40_mining:server:getSellableItems', false, shopName)
2625
local sellOptions = {}
2726
for i = 1, #itemsForSale do
@@ -44,7 +43,6 @@ local function openSellMenu(shopName)
4443
end
4544

4645
local function openBuyMenu(shopName)
47-
--TODO: query server for list of items in shop and build ox_lib context menu
4846
local itemsForSale = lib.callback.await('red40_mining:server:getShopItems', false, shopName)
4947
local buyOptions = {}
5048
for i = 1, #itemsForSale do
@@ -112,6 +110,17 @@ local function createPedPoint(point)
112110
}
113111
end
114112
end
113+
114+
if point.blip.enabled then
115+
CreateBlip({
116+
coords = point.blip.coords,
117+
sprite = point.blip.sprite,
118+
color = point.blip.color,
119+
scale = point.blip.scale,
120+
name = point.blip.name,
121+
})
122+
end
123+
115124
local pedPoint = lib.points.new({
116125
coords = vec3(point.coords.x, point.coords.y, point.coords.z),
117126
distance = 200.0,

client/smelting.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ local function createSmeltPoint(point)
8585
options = shopOptions,
8686
})
8787

88+
if point.blip.enabled then
89+
CreateBlip({
90+
coords = point.blip.coords,
91+
sprite = point.blip.sprite,
92+
color = point.blip.color,
93+
scale = point.blip.scale,
94+
name = point.blip.name,
95+
})
96+
end
97+
8898
function smeltPoint:onEnter()
8999
if config.smeltingTarget and not self.prop then
90100
self.targetId = config.addSphereTarget({

client/washing.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ if not enabled then
44
return
55
end
66

7-
-- local config = require 'config.client'
8-
97
local playerState = LocalPlayer.state
108

119
local function createWashingEffects(type, toolEntity)
@@ -40,11 +38,23 @@ lib.callback.register('red40_mining:client:washSpot', function(waitTime)
4038
end)
4139

4240
local function buildWashingZone(zone)
43-
lib.zones.poly({
44-
points = zone.points,
45-
thickness = zone.thickness,
46-
debug = true,
47-
})
41+
if zone.debug then
42+
43+
lib.zones.poly({
44+
points = zone.points,
45+
thickness = zone.thickness,
46+
debug = true,
47+
})
48+
end
49+
if zone.blip.enabled then
50+
CreateBlip({
51+
coords = zone.blip.coords,
52+
sprite = zone.blip.sprite,
53+
color = zone.blip.color,
54+
scale = zone.blip.scale,
55+
name = zone.blip.name,
56+
})
57+
end
4858
end
4959

5060
CreateThread(function()

server/mining.lua

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local config = require 'config.server'.mining
88

99
local orePoints = {}
1010
local lightPoints = {}
11+
local miningBlips = {}
1112

1213
RegisterNetEvent('red40_mining:server:startMining', function(oreId)
1314
local src = source
@@ -25,7 +26,6 @@ RegisterNetEvent('red40_mining:server:startMining', function(oreId)
2526
return
2627
end
2728

28-
-- Distance Check
2929
local coords = GetEntityCoords(GetPlayerPed(src))
3030
if #(coords - orePoint.coords) > 5.0 then
3131
Notify(src, locale('error.too_far'), 'error')
@@ -44,7 +44,7 @@ RegisterNetEvent('red40_mining:server:startMining', function(oreId)
4444

4545
local waitTime = math.random(config.tools[tool].minUseTime, config.tools[tool].maxUseTime)
4646

47-
local success = lib.callback.await('red40_mining:client:mineSpot', src, waitTime, config.tools[tool].type)
47+
local success = lib.callback.await('red40_mining:client:mineSpot', src, waitTime, config.tools[tool].type)
4848

4949
if success and not orePoint.looted then
5050
orePoints[orePoint.id].looted = true
@@ -76,10 +76,10 @@ RegisterNetEvent('red40_mining:server:startMining', function(oreId)
7676
for itemName, v in pairs(items) do
7777
if not CanCarryItem(src, itemName, v.amount, v.metadata) then
7878
lib.print.debug('Player ' .. src .. ' cannot carry item ' .. itemName .. ' x' .. v.amount)
79-
itemList[#itemList + 1] = {itemName, v.amount, v.metadata}
79+
itemList[#itemList + 1] = { itemName, v.amount, v.metadata }
8080
else
81-
AddItem(src, itemName, v.amount, v.metadata)
82-
lib.print.debug('Added items to player ' .. src .. ': ', items)
81+
AddItem(src, itemName, v.amount, v.metadata)
82+
lib.print.debug('Added items to player ' .. src .. ': ', items)
8383
end
8484
end
8585
if itemList and next(itemList) then
@@ -101,21 +101,18 @@ RegisterNetEvent('red40_mining:server:startMining', function(oreId)
101101
local durabilityRemoved = config.durability()
102102
local durabilityLeft = RemoveItemDurability(src, tool, durabilityRemoved)
103103
lib.print.debug('Removed ' ..
104-
durabilityRemoved .. ' durability from player ' .. src .. ' for mining with tool ' .. tool)
104+
durabilityRemoved .. ' durability from player ' .. src .. ' for mining with tool ' .. tool)
105105
if durabilityLeft and durabilityLeft <= 0 then
106106
Notify(src, locale('error.tool_broke'), 'error')
107-
Logger(src, 'red40_mining', 'Player ' .. src .. '\'s tool ' .. tool .. ' broke due to durability reaching 0.')
107+
Logger(src, 'red40_mining',
108+
'Player ' .. src .. '\'s tool ' .. tool .. ' broke due to durability reaching 0.')
108109
end
109110
end
110111
end
111112
end)
112113

113114
lib.callback.register('red40_mining:server:getMiningPoints', function(_)
114-
return orePoints
115-
end)
116-
117-
lib.callback.register('red40_mining:server:getMiningLightPoints', function(_)
118-
return lightPoints
115+
return orePoints, lightPoints, miningBlips
119116
end)
120117

121118
-- Build ore points
@@ -153,6 +150,15 @@ local function buildPoints()
153150
rot = lightPoint.rotation,
154151
}
155152
end
153+
if location.blip and location.blip.enabled then
154+
miningBlips[#miningBlips + 1] = {
155+
coords = location.blip.coords,
156+
sprite = location.blip.sprite,
157+
color = location.blip.color,
158+
scale = location.blip.scale,
159+
name = location.blip.name,
160+
}
161+
end
156162
end
157163
end
158164

server/panning.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ local function panSpot(src, itemName)
6868
local durabilityRemoved = config.durability()
6969
local durabilityLeft = RemoveItemDurability(src, itemName, durabilityRemoved)
7070
lib.print.debug('Removed ' ..
71-
durabilityRemoved .. ' durability from player ' .. src .. ' for panning with tool ' .. itemName)
71+
durabilityRemoved .. ' durability from player ' .. src .. ' for panning with tool ' .. itemName)
7272
if durabilityLeft and durabilityLeft <= 0 then
7373
Notify(src, locale('error.tool_broke'), 'error')
74-
Logger(src, 'red40_mining', 'Player ' .. src .. '\'s tool ' .. itemName .. ' broke due to durability reaching 0.')
74+
Logger(src, 'red40_mining',
75+
'Player ' .. src .. '\'s tool ' .. itemName .. ' broke due to durability reaching 0.')
7576
end
7677
end
7778
end
@@ -96,14 +97,14 @@ local function buildPanningZone()
9697
min = zone.min,
9798
max = zone.max,
9899
})
99-
if zone.debug then
100-
local clientZone = {
101-
points = zone.points,
102-
thickness = zone.thickness or 400,
103-
blip = zone.blip,
104-
}
105-
panningClientZones[#panningClientZones + 1] = clientZone
106-
end
100+
101+
local clientZone = {
102+
points = zone.points,
103+
thickness = zone.thickness or 400,
104+
debug = zone.debug or false,
105+
blip = zone.blip,
106+
}
107+
panningClientZones[#panningClientZones + 1] = clientZone
107108
panningZones[#panningZones + 1] = createdZone
108109
end
109110
end

0 commit comments

Comments
 (0)