[Scripting] Help replacing a game method
Hi,
I just started modding, but I do know how to code from before. I followed
this tutorial succesfully to learn the basics. So, now I'm trying out some of my own ideas. What I'm trying to do is to write a script mod to adjust rent (from the roommate system, Discover University) to more realistic levels. I wanted to start by changing the value of all rent for all sims to a fixed quantity, so I tracked down the method that does it in game and tried to replace it with my own as I did for the tutorial I linked. But it's not working
I'm fairly sure the method is _do_rent from RoommateService (simulation.services.roommate_services). I've tried replacing it with my own method, but it's not working. I have imported everything needed from the original file. I also have a cheat console output in the same file which works in game, and the code compiles and builds. Do you have any idea of why this is, or some advice, something I have missed? Thank you in advance!
Here's the code. All I did was replace the calculation in "rent_per_sim" with a flat value, eventually I want to replace it with another calculation of my own.
Code:
def _do_rent(self, *_):
household = services.get_active_sim().household
zone_id = household.home_zone_id
sim_ids = self._zone_to_roommates[zone_id].sim_ids
total_rent = 0
unpaid_sim_strings = []
roommate_count = len(sim_ids)
rent_per_sim = 500
# int(household.get_home_lot_value() * self.RENT.rent_modifer / (len(household) + roommate_count))
for sim_id in sim_ids:
sim_info = services.sim_info_manager().get(sim_id)
if sim_info.has_trait(self.RENT.non_payment_trait):
if sims4.random.random_chance(self.RENT.non_payment_chance * 100):
rent_owed_stat = sim_info.get_statistic(self.RENT.rent_owed_statistic)
rent_owed_stat.add_value(rent_per_sim)
unpaid_sim_strings.append(self.RENT.non_payment_format(sim_info))
continue
total_rent += rent_per_sim
if not unpaid_sim_strings:
if total_rent == 0:
logger.error('Roommate rent payment: Somehow no rent')
else:
if total_rent != 0:
household.funds.add(total_rent, Consts_pb2.FUNDS_ROOMMATE_RENT)
client = services.client_manager().get_first_client()
active_sim = client.active_sim
if not unpaid_sim_strings:
dialog = self.RENT.all_pay_notification(active_sim, SingleSimResolver(active_sim))
dialog.show_dialog(additional_tokens=(rent_per_sim, total_rent))
else:
dialog = self.RENT.pay_failure_notification(active_sim, SingleSimResolver(active_sim))
dialog.show_dialog(additional_tokens=(rent_per_sim, total_rent, roommate_count - len(unpaid_sim_strings),
(LocalizationHelperTuning.get_bulleted_list)(*(None, ), *unpaid_sim_strings)))
services.roommate_service._do_rent = _do_rent