Skip to content

Commit fd183c2

Browse files
committed
fix: some minor fixes
1 parent f3ea41d commit fd183c2

14 files changed

Lines changed: 88 additions & 100 deletions

File tree

SSV2/includes/classes/gta/atArray.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
---@field private m_data array<pointer<T>>
1818
---@field private m_size uint16_t
1919
---@field private m_capacity uint16_t
20-
---@field private m_data_type any
20+
---@field private m_data_type T|ClassMeta<T>|any
2121
---@field [integer] pointer<T>
2222
---@operator len: integer
2323
---@overload fun(address: pointer, data_type?: optional<T>): atArray

SSV2/includes/features/online/yim_resupplier/YimResupplierV3.lua

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local ScriptDisplayNames <const> = {
2323
["gb_contraband_sell"] = "CEO",
2424
["gb_gunrunning"] = "Bunker",
2525
["gb_biker_contraband_sell"] = "Biker Business",
26-
["fm_content_acid_lab_sell"] = "Acid Lab",
26+
["fm_content_acid_lab_sell"] = "Acid Lab (Temporarily disabled)",
2727
}
2828

2929
local NightclubNames <const> = {
@@ -330,14 +330,6 @@ function YRV3:PopulateOffice()
330330
coords = ref.coords,
331331
custom_name = _F("%s%s", name1, name2)
332332
})
333-
334-
if (not self.m_businesses.office) then
335-
return
336-
end
337-
338-
for i = 0, 4 do
339-
self.m_businesses.office:AddSubBusiness(i)
340-
end
341333
end
342334

343335
function YRV3:PopulateClubhouse()
@@ -348,9 +340,7 @@ function YRV3:PopulateClubhouse()
348340

349341
local idx = club_prop - 90
350342
local club_ref = self.m_raw_data.Clubhouses[idx]
351-
if (not club_ref) then
352-
return
353-
end
343+
if (not club_ref) then return end
354344

355345
local safe_data = self.m_raw_data.CashSafes.fronts.clubhouse
356346
safe_data.name = "Clubhouse Duffle Bag"
@@ -360,14 +350,6 @@ function YRV3:PopulateClubhouse()
360350
coords = club_ref.coords,
361351
safe_data = safe_data
362352
})
363-
364-
if (not self.m_businesses.clubhouse) then
365-
return
366-
end
367-
368-
for i = 0, 4 do
369-
self.m_businesses.clubhouse:AddSubBusiness(i)
370-
end
371353
end
372354

373355
function YRV3:PopulateBikerBusinesses()
@@ -433,45 +415,53 @@ function YRV3:PopulateNightclub()
433415
safedata.name = clubname
434416

435417

436-
self.m_businesses.nightclub = Nightclub.new({
418+
local nightclub = Nightclub.new({
437419
id = nc_index,
438420
name = Game.GetGXTLabel(_F("MP_NCLU_%d", nc_index)),
439421
custom_name = clubname,
440422
coords = ref.coords,
441423
safe_data = safedata
442424
})
443425

426+
if not (nightclub and nightclub:IsValid()) then
427+
self.m_data_initialized = true
428+
return
429+
end
430+
444431
while (not self.m_initial_data_done) do
445432
yield()
446433
end
447434

448435
local owns_cargo = false
449-
if (self.m_businesses.hangar) then
436+
local hangar = self.m_businesses.hangar
437+
local office = self.m_businesses.office
438+
local clubhouse = self.m_businesses.clubhouse
439+
440+
if (hangar and hangar:IsValid()) then
450441
owns_cargo = true
451-
elseif (self.m_businesses.office) then
452-
if (self.m_businesses.office:HasCargoWarehouse()) then
453-
owns_cargo = true
454-
end
442+
elseif (office and office:IsValid()) then
443+
owns_cargo = office:HasCargoWarehouse()
455444
end
456445

457446
if (owns_cargo) then
458-
self.m_businesses.nightclub:AddSubBusiness(0)
447+
nightclub:AddSubBusiness(0)
459448
end
460449

461450
if (self.m_businesses.bunker) then
462-
self.m_businesses.nightclub:AddSubBusiness(1)
451+
nightclub:AddSubBusiness(1)
463452
end
464453

465-
if (self.m_businesses.clubhouse) then
466-
for _, bb in ipairs(self.m_businesses.clubhouse:GetSubBusinesses()) do
454+
if (clubhouse and clubhouse:IsValid()) then
455+
for _, bb in ipairs(clubhouse:GetSubBusinesses()) do
467456
if (bb:IsValid()) then
468457
local index = bb:GetIndex()
469-
self.m_businesses.nightclub:AddSubBusiness(index + 2)
458+
nightclub:AddSubBusiness(index + 2)
470459
end
471460
end
472461
end
473462

474-
self.m_data_initialized = true
463+
self.m_businesses.nightclub = nightclub
464+
self.m_data_initialized = true
475465

476466
if (GVars.features.yrv3.nc_always_popular) then
477467
self.m_businesses.nightclub:LockPopularityDecay()
@@ -650,38 +640,35 @@ end
650640
---@param index integer -- `1 .. 7`
651641
---@return Factory?
652642
function YRV3:GetFactoryByIndex(index)
653-
if (not self:CanAccess()) then
654-
return
655-
end
643+
if (not self:CanAccess()) then return end
656644

657645
if (type(index) ~= "number" or not math.is_inrange(index, 1, 7)) then
658646
Notifier:ShowError("YRV3", "Invalid factory index! Please make sure to use a number between 1 and 7.")
659647
return
660648
end
661649

662-
local factory -- fwd decl
663-
if (index < 6) then
650+
index = index - 1
651+
if (index < 5) then
664652
local clubhouse = self.m_businesses.clubhouse
665-
if (not clubhouse) then
653+
if (not clubhouse) then return end
654+
655+
local factories = self.m_businesses.clubhouse:GetSubBusinesses()
656+
if (type(factories) ~= "table") then
666657
return
667658
end
668659

669-
local factories = self.m_businesses.clubhouse:GetSubBusinesses()
670-
if (type(factories) == "table") then
671-
for _, f in ipairs(factories) do
672-
if (f:GetIndex() == index - 1) then
673-
factory = f
674-
break
675-
end
660+
for _, f in ipairs(factories) do
661+
if (f:GetIndex() == index) then
662+
return f
676663
end
677664
end
665+
elseif (index == 5) then
666+
return self.m_businesses.bunker
678667
elseif (index == 6) then
679-
factory = self.m_businesses.bunker
680-
elseif (index == 7) then
681-
factory = self.m_businesses.acid_lab
668+
return self.m_businesses.acid_lab
682669
end
683670

684-
return factory
671+
return nil
685672
end
686673

687674
---@param index integer -- `1 .. 7`
@@ -731,34 +718,37 @@ function YRV3:CommandToggleProduction(index, isNightclubHub)
731718

732719
if (factory:HasFullProduction()) then
733720
Notifier:ShowError(name, _T("YRV3_FAST_PROD_ERR"))
734-
else
735-
local prefix = "Fast production"
736-
local state = bool and "enabled" or "disabled"
737-
local msg = isNightclubHub and _F("%s for the %s hub", state, factory:GetName()) or state
738-
Notifier:ShowMessage(name, _F("%s %s.", prefix, msg))
721+
return
739722
end
723+
724+
local prefix = "Fast production"
725+
local state = bool and "enabled" or "disabled"
726+
local msg = isNightclubHub and _F("%s for the %s hub", state, factory:GetName()) or state
727+
Notifier:ShowMessage(name, _F("%s %s.", prefix, msg))
740728
end
741729

742730
function YRV3:FillAll()
743731
if (not self:CanAccess()) then
744732
return
745733
end
746734

747-
if (self.m_businesses.office) then
748-
for _, wh in ipairs(self.m_businesses.office:GetCargoWarehouses()) do
735+
local office = self.m_businesses.office
736+
local hangar = self.m_businesses.hangar
737+
if (office and office:IsValid()) then
738+
for _, wh in ipairs(office:GetCargoWarehouses()) do
749739
if (wh:IsValid()) then
750740
wh.auto_fill = true
751741
end
752742
end
753743
end
754744

755-
if (self.m_businesses.hangar and self.m_businesses.hangar:IsValid()) then
756-
self.m_businesses.hangar.auto_fill = true
745+
if (hangar and hangar:IsValid()) then
746+
hangar.auto_fill = true
757747
end
758748

759749
for i = 1, 7 do
760750
local factory = self:GetFactoryByIndex(i)
761-
if (factory) then
751+
if (factory and factory:IsValid() and factory:IsSetup()) then
762752
factory:ReStock()
763753
sleep(math.random(600, 1200))
764754
end

SSV2/includes/features/online/yim_resupplier/businesses/BusinessFront.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@ function BusinessFront.new(opts)
4545
-- assert(IsInstance(opts.coords, vec3), "Missing argument: coords<vec3>") -- not necessary. UI does not render a tp button if this is missing and LuaLS will warn as well
4646

4747
local base = BusinessBase.new(opts)
48-
local instance = setmetatable(base, BusinessFront)
48+
local instance = setmetatable(base, BusinessFront) ---@cast instance BusinessFront
4949
instance.m_subs = {}
5050
instance.m_last_report_check_time = 0
5151

5252
if (opts.safe_data) then
5353
instance.m_safe = CashSafe.new(opts.safe_data)
5454
end
5555

56-
---@diagnostic disable-next-line
5756
return instance
5857
end
5958

SSV2/includes/features/online/yim_resupplier/businesses/BusinessHub.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ function BusinessHub.new(opts)
3737
assert(type(opts.max_units) == "number", "Missing argument: max_units<integer>")
3838

3939
local base = BusinessBase.new(opts)
40-
local instance = setmetatable(base, BusinessHub)
40+
local instance = setmetatable(base, BusinessHub) ---@cast instance BusinessHub
4141
instance.fast_prod_enabled = false
4242
instance.fast_prod_running = false
4343
instance.m_vpu = opts.vpu
4444
instance.m_prod_time_g = SGSL:Get(SGSL.data.bhub_prod_time_global):AsGlobal():At(1, base:GetIndex())
4545
instance.m_prod_bool_g = SGSL:Get(SGSL.data.bhub_prod_bool_global):AsGlobal()
4646
instance.m_tech_global = base:GetBaseGlobal():At(321)
4747

48-
---@diagnostic disable-next-line
4948
return instance
5049
end
5150

SSV2/includes/features/online/yim_resupplier/businesses/CarWash.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ CarWash.__index = CarWash
148148
---@return CarWash
149149
function CarWash.new(opts)
150150
local base = BasicBusiness.new(opts)
151-
local instance = setmetatable(base, CarWash)
151+
local instance = setmetatable(base, CarWash) ---@cast instance CarWash
152152
instance.m_safe = CashSafe.new({
153153
name = opts.name,
154154
cash_value_stat = "MPX_CWASH_SAFE_CASH_VALUE",
@@ -189,7 +189,6 @@ function CarWash.new(opts)
189189
}))
190190
end
191191

192-
---@diagnostic disable-next-line
193192
return instance
194193
end
195194

SSV2/includes/features/online/yim_resupplier/businesses/Clubhouse.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ Clubhouse.__index = Clubhouse
2626
---@return Clubhouse
2727
function Clubhouse.new(opts)
2828
local base = BusinessFront.new(opts)
29-
local instance = setmetatable(base, Clubhouse)
29+
local instance = setmetatable(base, Clubhouse) ---@cast instance Clubhouse
3030
local custom_name1 = stats.get_string("MPX_MC_GANG_NAME")
3131
local custom_name2 = stats.get_string("MPX_MC_GANG_NAME2")
3232
instance.m_custom_name = _F("%s%s", custom_name1, custom_name2)
3333

34-
---@diagnostic disable-next-line
34+
for i = 0, 4 do
35+
instance:AddSubBusiness(i)
36+
end
37+
3538
return instance
3639
end
3740

SSV2/includes/features/online/yim_resupplier/businesses/Factory.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Factory.new(opts)
4646
assert(type(opts.id) == "number" and math.is_inrange(opts.id, 0, 6), "Invalid Biker Business id.")
4747

4848
local base = BusinessBase.new(opts)
49-
local instance = setmetatable(base, Factory)
49+
local instance = setmetatable(base, Factory) ---@cast instance Factory
5050
instance.m_normalized_name = opts.normalized_name
5151
instance.fast_prod_enabled = false
5252
instance.m_fast_prod_running = false
@@ -64,7 +64,6 @@ function Factory.new(opts)
6464
instance.m_prod_time_g = baseGlobal:At(205):At(idx, 13):At(9)
6565
instance.m_restock_g = restockGlobal:At(1, idx)
6666

67-
---@diagnostic disable-next-line
6867
return instance
6968
end
7069

SSV2/includes/features/online/yim_resupplier/businesses/Nightclub.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Nightclub.__index = Nightclub
2929
---@return Nightclub
3030
function Nightclub.new(opts)
3131
local base = BusinessFront.new(opts)
32-
local instance = setmetatable(base, Nightclub)
32+
local instance = setmetatable(base, Nightclub) ---@cast instance Nightclub
3333
instance.m_custom_name = opts.custom_name or "Nightclub"
34-
---@diagnostic disable-next-line
34+
3535
return instance
3636
end
3737

SSV2/includes/features/online/yim_resupplier/businesses/Office.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ Office.__index = Office
4141
---@return Office
4242
function Office.new(opts)
4343
local base = BusinessFront.new(opts)
44-
45-
---@type Office
46-
---@diagnostic disable-next-line
47-
local instance = setmetatable(base, Office)
44+
local instance = setmetatable(base, Office) ---@cast instance Office
4845
instance.m_custom_name = opts.custom_name
4946
instance.m_earnings_report = {
5047
lifetime_buy_undertaken = 0,
@@ -54,7 +51,12 @@ function Office.new(opts)
5451
lifetime_earnings = 0,
5552
lifetime_earnings_fmt = "$0",
5653
}
54+
55+
for i = 0, 4 do
56+
instance:AddSubBusiness(i)
57+
end
5758
instance:CheckVehicleWarehouse()
59+
5860
return instance
5961
end
6062

@@ -71,9 +73,7 @@ function Office:CheckVehicleWarehouse()
7173

7274
local idx = ie_wh_prop - 114
7375
local ref = RawBusinessData.VehicleWarehouses[idx]
74-
if (not ref) then
75-
return
76-
end
76+
if (not ref) then return end
7777

7878
self.m_vehicle_warehouse = VehicleWarehouse.new(
7979
Game.GetGXTLabel(ref.gxt),

SSV2/includes/features/online/yim_resupplier/businesses/SalvageYard.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ SalvageYard.__index = SalvageYard
2424
---@param opts SYOpts
2525
---@return SalvageYard
2626
function SalvageYard.new(opts)
27-
local base = BusinessFront.new(opts)
28-
---@diagnostic disable-next-line
27+
local base = BusinessFront.new(opts) ---@cast base SalvageYard
2928
return setmetatable(base, SalvageYard)
3029
end
3130

@@ -134,9 +133,9 @@ end
134133

135134
---@param slot integer
136135
---@return string
137-
function SalvageYard:GetSalvageCarInSlot(slot)
136+
function SalvageYard:GetRobberyCarInSlot(slot)
138137
local index = stats.get_int(_F("MPX_MPSV_MODEL_SALVAGE_VEH%d", slot))
139-
return data.vehicle_targets[index] or "NULL"
138+
return data.vehicle_targets[index]
140139
end
141140

142141
function SalvageYard:DisableWeeklyCooldown()

0 commit comments

Comments
 (0)