@@ -302,13 +302,23 @@ function YRV3:DoesPlayerOwnAnyBikerBusiness()
302302 return false
303303end
304304
305+ --- @param idx integer
306+ --- @return boolean
307+ function YRV3 :IsPropertyIndexValid (idx )
308+ if (type (idx ) ~= " number" ) then
309+ return false
310+ end
311+
312+ return idx > 0 and idx < math .int32_max ()
313+ end
314+
305315function YRV3 :PopulateClubhouse ()
306316 local club_prop = stats .get_int (" MPX_PROP_CLUBHOUSE" )
307- if (club_prop == 0 ) then
317+ if (not self : IsPropertyIndexValid ( club_prop ) ) then
308318 return
309319 end
310320
311- local idx = club_prop - 90
321+ local idx = club_prop - 90
312322 local club_ref = self .m_raw_data .Clubhouses [idx ]
313323 if (not club_ref ) then
314324 return
@@ -420,18 +430,22 @@ function YRV3:PopulateNightclub()
420430
421431 ThreadManager :Run (function ()
422432 local nc_index = stats .get_int (" MPX_NIGHTCLUB_OWNED" )
423- local ref = self .m_raw_data .Nightclubs [nc_index ]
424- if (nc_index == 0 or not ref ) then
433+ local ref = self .m_raw_data .Nightclubs [nc_index ]
434+ if (not self : IsPropertyIndexValid ( nc_index ) or not ref ) then
425435 self .m_data_initialized = true
426436 return
427437 end
428438
439+ local nameid = stats .get_int (" MPX_PROP_NIGHTCLUB_NAME_ID" )
429440 local safedata = self .m_raw_data .CashSafes .fronts .nightclub
430- safedata .name = " Nightclub Safe"
441+ local clubname = NightclubNames [nameid + 1 ]
442+ safedata .name = clubname
443+
444+
431445 self .m_businesses .nightclub = Nightclub .new ({
432446 id = nc_index ,
433447 name = Game .GetGXTLabel (_F (" MP_NCLU_%d" , nc_index )),
434- custom_name = NightclubNames [ stats . get_int ( " MPX_PROP_NIGHTCLUB_NAME_ID " ) + 1 ] ,
448+ custom_name = clubname ,
435449 coords = ref .coords ,
436450 safe_data = safedata
437451 })
@@ -471,7 +485,6 @@ function YRV3:PopulateNightclub()
471485 end
472486
473487 self .m_data_initialized = true
474- sleep (3000 )
475488
476489 if (GVars .features .yrv3 .nc_always_popular ) then
477490 self .m_businesses .nightclub :LockPopularityDecay ()
@@ -480,7 +493,8 @@ function YRV3:PopulateNightclub()
480493end
481494
482495function YRV3 :PopulateCarWash ()
483- if (stats .get_int (" MPX_SB_CAR_WASH_OWNED" ) == 0 ) then
496+ local idx = stats .get_int (" MPX_SB_CAR_WASH_OWNED" )
497+ if (not self :IsPropertyIndexValid (idx )) then
484498 return
485499 end
486500
493507function YRV3 :PopulateCashSafes ()
494508 for i , data in ipairs (self .m_raw_data .CashSafes .regular ) do
495509 local property_index = stats .get_int (data .property_stat )
496- if (property_index == 0 ) then
510+ if (not self : IsPropertyIndexValid ( property_index ) ) then
497511 goto continue
498512 end
499513
@@ -504,6 +518,9 @@ function YRV3:PopulateCashSafes()
504518 name = name ,
505519 coords = coords ,
506520 cash_value_stat = data .cash_value_stat ,
521+ paytime_stat = data .paytime_stat ,
522+ interior_id = data .interior_id ,
523+ room_hash = data .room_hash ,
507524 get_max_cash = data .get_max_cash ,
508525 })
509526
@@ -513,14 +530,16 @@ end
513530
514531function YRV3 :PopulateSalvageYard ()
515532 local property_index = stats .get_int (" MPX_SALVAGE_YARD_OWNED" )
516- if (property_index == 0 ) then
533+ if (not self : IsPropertyIndexValid ( property_index ) ) then
517534 return
518535 end
519536
520- local ref = self .m_raw_data .SalvageYards [property_index ]
521- local name = ref and Game .GetGXTLabel (ref .gxt ) or _T (" SY_SALVAGE_YARD" )
522- local safe_data = self .m_raw_data .CashSafes .fronts .salvage_yard
523- safe_data .name = name
537+ local ref = self .m_raw_data .SalvageYards [property_index ]
538+ local name = ref and Game .GetGXTLabel (ref .gxt ) or _T (" SY_SALVAGE_YARD" )
539+ local safe_data = self .m_raw_data .CashSafes .fronts .salvage_yard
540+ safe_data .name = name
541+
542+
524543 self .m_businesses .salvage_yard = SalvageYard .new ({
525544 id = property_index ,
526545 name = name ,
@@ -1023,20 +1042,19 @@ function YRV3:UpdateBusinesses()
10231042 end
10241043
10251044 for key , business in pairs (self .m_businesses ) do
1026- if (key == " safes" or key == " salvage_yard" or key == " car_wash" ) then
1027- goto continue
1028- end
1029-
10301045 if (key == " warehouses" ) then
10311046 for _ , wh in ipairs (business ) do
10321047 if (type (wh .Update ) == " function" ) then
10331048 wh :Update ()
10341049 end
10351050 end
1051+ elseif (key == " safes" ) then
1052+ for _ , safe in ipairs (self .m_businesses .safes ) do
1053+ safe :Update ()
1054+ end
10361055 elseif (type (business .Update ) == " function" ) then
10371056 business :Update ()
10381057 end
1039- :: continue::
10401058 end
10411059
10421060 self .m_last_business_update_time = Time .millis ()
0 commit comments