@@ -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
2929local 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
341333end
342334
343335function 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
371353end
372354
373355function 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 ?
652642function 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
685672end
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 ))
740728end
741729
742730function 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
0 commit comments