def _MakePregnant(targetSimHandler: argument_helpers.RequiredTargetParam, fatherSimHandler: argument_helpers.RequiredTargetParam, _connection=None) -> None: try: if game_services.service_manager is None: return targetSimInfo = targetSimHandler.get_target( services.sim_info_manager()) fatherSimInfo = fatherSimHandler.get_target( services.sim_info_manager()) if not isinstance(targetSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the target sim, %s is not a valid sim id." % targetSimHandler.target_id) if not isinstance(fatherSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the source sim, %s is not a valid sim id." % fatherSimHandler.target_id) targetSimInfo.pregnancy_tracker.clear_pregnancy() targetSimInfo.pregnancy_tracker.start_pregnancy( targetSimInfo, fatherSimInfo) except Exception as e: Debug.Log("Failed to make a sim pregnant.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__, exception=e) raise e
def enforce_marriage(x: RequiredTargetParam, y: RequiredTargetParam, _connection=None): mgr = services.sim_info_manager() source = x.get_target(manager=mgr) target = y.get_target(manager=mgr) ForceMarriageInteraction.enforce_marriage(source, target)
def _AddSperm(targetSimHandler: argument_helpers.RequiredTargetParam, sourceSimHandler: argument_helpers.RequiredTargetParam, tryingForBaby: bool = True, _connection=None) -> None: try: if game_services.service_manager is None: return targetSimInfo = targetSimHandler.get_target( services.sim_info_manager()) sourceSimInfo = sourceSimHandler.get_target( services.sim_info_manager()) if not isinstance(targetSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the target sim, %s is not a valid sim id." % targetSimHandler.target_id) if not isinstance(sourceSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the source sim, %s is not a valid sim id." % sourceSimHandler.target_id) Insemination.AutoInseminate(targetSimInfo, sourceSimInfo, tryingForBaby=tryingForBaby, generateGenericSperm=True) except Exception as e: Debug.Log("Failed to add sperm to a sim.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__, exception=e) raise e
def find_career(sim:RequiredTargetParam=None, _connection=None): sim = sim.get_target() if sim.queue.has_duplicate_super_affordance(Career.FIND_JOB_PHONE_INTERACTION, sim, None): return False context = interactions.context.InteractionContext(sim, interactions.context.InteractionContext.SOURCE_SCRIPT_WITH_USER_INTENT, interactions.priority.Priority.High, insert_strategy=QueueInsertStrategy.NEXT) enqueue_result = sim.push_super_affordance(Career.FIND_JOB_PHONE_INTERACTION, sim, context) if not enqueue_result: return False return True
def object_add_stored_sim_info(obj: RequiredTargetParam = None, sim_id: OptionalTargetParam = None, _connection=None): obj = obj.get_target() sim = get_optional_target(sim_id, _connection) if obj is not None and sim is not None: obj.add_dynamic_component( types.STORED_SIM_INFO_COMPONENT.instance_attr, sim_id=sim.id) return True return False
def find_career(sim: RequiredTargetParam = None, _connection=None): sim = sim.get_target() if sim.queue.has_duplicate_super_affordance( Career.FIND_JOB_PHONE_INTERACTION, sim, None): return False context = interactions.context.InteractionContext( sim, interactions.context.InteractionContext.SOURCE_SCRIPT_WITH_USER_INTENT, interactions.priority.Priority.High, insert_strategy=QueueInsertStrategy.NEXT) enqueue_result = sim.push_super_affordance( Career.FIND_JOB_PHONE_INTERACTION, sim, context) if not enqueue_result: return False return True
def loot_apply_to_sim_and_target(loot_type: TunableInstanceParam( sims4.resources.Types.ACTION), actor_sim: RequiredTargetParam = None, target_obj: RequiredTargetParam = None, _connection=None): actor = actor_sim.get_target(manager=services.sim_info_manager()) if actor is None: sims4.commands.output('No actor', _connection) return target = target_obj.get_target(manager=services.object_manager()) if target is None: sims4.commands.output('No target', _connection) return resolver = DoubleObjectResolver(actor, target) loot_type.apply_to_resolver(resolver)
def _TakePill ( targetSimHandler: argument_helpers.RequiredTargetParam, pillsObjectHandler: argument_helpers.RequiredTargetParam, requiresPill: bool = True, removePill: bool = True, showGeneralFeedback: bool = True, _connection: int = None) -> None: try: targetSimInfo = targetSimHandler.get_target(services.sim_info_manager()) if not isinstance(targetSimInfo, sim_info.SimInfo): raise ValueError("Failed to get the target sim, %s is not a valid sim id." % targetSimHandler.target_id) pillsObject = services.inventory_manager().get(pillsObjectHandler.target_id) # type: typing.Optional[script_object.ScriptObject] if pillsObject is None: pillsObject = services.object_manager().get(pillsObjectHandler.target_id) # type: typing.Optional[script_object.ScriptObject] if not isinstance(pillsObject, script_object.ScriptObject): raise ValueError("Failed to get the pills object, %s is not a valid script object id." % targetSimHandler.target_id) SafetyEmergencyContraceptivePill.TakePill(targetSimInfo, pillsObject = pillsObject, requiresPill = requiresPill, removePill = removePill, showGeneralFeedback = showGeneralFeedback) except: output = commands.CheatOutput(_connection) output("Failed to run the take pill command for the target sim.") Debug.Log("Failed to run the take pill command for the target sim.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__)
def spawn_fire_at_object(target:RequiredTargetParam, num_fires:int=1, _connection=None): target_object = target.get_target() if target_object is None: sims4.commands.output(f'Invalid target object id {target_object}') return fire_service = services.get_fire_service() fire_service.spawn_fire_at_object(target_object, num_fires=num_fires)
def _Enable(targetSimHandler: argument_helpers.RequiredTargetParam, _connection: int = None) -> None: try: targetSimInfo = targetSimHandler.get_target( services.sim_info_manager()) if not isinstance(targetSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the target sim, %s is not a valid sim id." % targetSimHandler.target_id) dotInformation = Dot.GetDotInformation( targetSimInfo) # type: typing.Optional[Dot.DotInformation] if dotInformation is None: raise Exception( "Missing dot information object for a sim with the id %s." % targetSimInfo.id) dotInformation.Enabled = True except: output = commands.CheatOutput(_connection) output("Failed to enable the dot app on the target sim's phone.") Debug.Log("Failed to enable the dot app on the target sim's phone.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__)
def show_orgs_events_dialog(sim:RequiredTargetParam, _connection=None): sim_info = sim.get_target(manager=services.sim_info_manager()) if sim_info is None: sims4.commands.output('Sim with id {} is not found to show organizations events dialog.'.format(sim.target_id), _connection) return False op = AskAboutClubsDialog(sim_info.id, show_orgs=True) Distributor.instance().add_op_with_no_owner(op)
def set_as_head(obj_id: RequiredTargetParam = None, scale: float = None, forward_rot: float = None, up_rot: float = None, _connection=None): sim = get_optional_target(None, _connection) if sim is None: return original_obj = obj_id.get_target() if original_obj is None: return if original_obj.is_sim: sims4.commands.output('Cannot set a Sim as your head.', _connection) return obj_definition_id = original_obj.definition.id if original_obj.crafting_component is not None: obj = DebugCreateCraftableInteraction.create_craftable( original_obj.crafting_component._crafting_process.recipe, sim) else: obj = objects.system.create_object(obj_definition_id) if obj is None: return if scale is None: head_width = 0.75 default_object_width = head_width / 4 polygon = obj.footprint_polygon if len(polygon) > 1: polygon2 = list(polygon)[1:] polygon2.append(polygon[-1]) object_width_x = max( [abs(x - y).x for (x, y) in zip(polygon2, polygon)]) object_width_z = max( [abs(x - y).z for (x, y) in zip(polygon2, polygon)]) object_width = min((object_width_x, object_width_z)) else: object_width = default_object_width new_scale = head_width / object_width obj.scale = new_scale else: obj.scale = scale forward_rot = 4 * sims4.math.PI / 3 if forward_rot is None else forward_rot up_rot = 3 * sims4.math.PI / 2 if up_rot is None else up_rot forward_orientation = sims4.math.Quaternion.from_axis_angle( forward_rot, sims4.math.FORWARD_AXIS) up_orientation = sims4.math.Quaternion.from_axis_angle( up_rot, sims4.math.UP_AXIS) orientation = sims4.math.Quaternion.concatenate(forward_orientation, up_orientation) new_transform = sims4.math.Transform.IDENTITY() new_transform.orientation = orientation neck_hash = sims4.hash_util.hash32('b__neck__') if sim.current_object_set_as_head is not None and sim.current_object_set_as_head( ) is not None: sim.current_object_set_as_head().destroy( source=sim, cause='Destroying existing object set as head when setting new one.' ) sim.current_object_set_as_head = weakref.ref(obj) obj.set_parent(sim, transform=new_transform, joint_name_or_hash=neck_hash)
def puddle_evaporate(obj_id: RequiredTargetParam, _connection=None): obj = obj_id.get_target() if obj is None: return False if not isinstance(obj, Puddle): return False obj.evaporate(None) return True
def puddle_grow(obj_id: RequiredTargetParam, _connection=None): obj = obj_id.get_target() if obj is None: return False if not isinstance(obj, Puddle): return False obj.try_grow_puddle() return True
def demote_business_employee(sim: RequiredTargetParam, _connection=None): business_manager = services.business_service( ).get_business_manager_for_zone() if business_manager is None: return False target_sim = sim.get_target(manager=services.sim_info_manager()) if target_sim is None: return False return business_manager.run_demote_employee_interaction(target_sim)
def push_interaction_on_all_sims(affordance, opt_target:RequiredTargetParam=None, _connection=None): target = opt_target.get_target() if opt_target is not None else None client = services.client_manager().get(_connection) for sim_info in client.selectable_sims: sim = sim_info.get_sim_instance() while sim is not None: context = InteractionContext(sim, InteractionContext.SOURCE_PIE_MENU, Priority.High, client=client, pick=None) sim.push_super_affordance(affordance, target, context) return True
def force_spawn_slot_objects(obj_id: RequiredTargetParam, _connection=None): obj = obj_id.get_target() if obj is None or obj.spawner_component is None: return empty_slot_count = sum(1 for runtime_slot in obj.get_runtime_slots_gen() if runtime_slot.empty) obj.force_spawn_object(spawn_type=SpawnerTuning.SLOT_SPAWNER, ignore_firemeter=True, create_slot_obj_count=empty_slot_count)
def demote_retail_employee(sim: RequiredTargetParam, _connection=None): business_manager = services.business_service( ).get_business_manager_for_zone() if business_manager is None: return False target_sim = sim.get_target(manager=services.sim_info_manager()) if target_sim is None: return False return business_manager.run_employee_interaction( business_manager.EMPLOYEE_INTERACTION_DEMOTE, target_sim)
def genalogy_relation(x_sim: RequiredTargetParam, y_sim: RequiredTargetParam, _connection=None): output = sims4.commands.Output(_connection) sim_x = x_sim.get_target() bit = None if sim_x is not None: bit = sim_x.sim_info.genealogy.get_family_relationship_bit( y_sim.target_id, output) return bit is not None
def update_find_career_interaction_availability( sim: RequiredTargetParam = None, _connection=None): client = services.client_manager().get(_connection) sim = sim.get_target() context = client.create_interaction_context(sim) aop = Career.FIND_JOB_PHONE_INTERACTION.generate_aop(sim, context) test_result = aop.test(context) tooltip = None if test_result.tooltip is None else test_result.tooltip(sim) op = distributor.ops.UpdateFindCareerInteractionAvailability( test_result.result, tooltip) distributor.system.Distributor.instance().add_op(sim.sim_info, op)
def open_inventory_ui(inventory_obj:RequiredTargetParam, _connection=None): obj = inventory_obj.get_target() if obj is None: sims4.commands.output('Failed to get inventory_obj: {}.'.format(inventory_obj), _connection) return False comp = obj.inventory_component if comp is None: sims4.commands.output('inventory_obj does not have an inventory component: {}.'.format(inventory_obj), _connection) return False comp.open_ui_panel() return True
def create_and_add_object_to_inventory(to_inventory_object_id:RequiredTargetParam, definition_id:int, _connection=None): to_inventory_owner = to_inventory_object_id.get_target() to_inventory = to_inventory_owner.inventory_component if to_inventory is None: sims4.commands.output('to inventory object does not have an inventory component: {}'.format(to_inventory_owner), _connection) return False obj = create_object(definition_id) if not to_inventory.player_try_add_object(obj): sims4.commands.output('object failed to be placed into inventory: {}'.format(obj), _connection) obj.destroy(source=to_inventory, cause='object failed to be placed into inventory') return False sims4.commands.output('object {} placed into inventory'.format(obj), _connection) return True
def show_ask_about_clubs_dialog_for_sim(sim: RequiredTargetParam, _connection): club_service = _get_club_service(_connection) if club_service is None: return target_sim_info = sim.get_target(manager=services.sim_info_manager()) if target_sim_info is None: sims4.commands.output('Not a valid SimID.', _connection) return participant_clubs = club_service.get_clubs_for_sim_info(target_sim_info) if not participant_clubs: return op = AskAboutClubsDialog(target_sim_info.id, club_ids=[club.id for club in participant_clubs]) Distributor.instance().add_op_with_no_owner(op)
def show_inherited_traits(sim_a:RequiredTargetParam=None, sim_b:OptionalTargetParam=None, _connection=None): sim_a = sim_a.get_target() sim_b = get_optional_target(sim_b, _connection) output = sims4.commands.Output(_connection) if sim_a is None or sim_b is None: output('Must specify two valid Sims.') return False output('Potential inherited traits between {} and {}:'.format(sim_a, sim_b)) for (index, inherited_trait_entries) in enumerate(sim_a.trait_tracker.get_inherited_traits(sim_b)): output('Entry {}:'.format(index)) total_weight = sum(entry[0] for entry in inherited_trait_entries) for inherited_trait_entry in inherited_trait_entries: output(' {:24} {:.2%}'.format(inherited_trait_entry[1].__name__, inherited_trait_entry[0]/total_weight if total_weight else 0)) output('End') return True
def push_interaction(affordance, opt_target:RequiredTargetParam=None, opt_sim:OptionalTargetParam=None, priority=Priority.High, _connection=None): target = opt_target.get_target() if opt_target is not None else None sim = get_optional_target(opt_sim, _connection) client = services.client_manager().get(_connection) priority = Priority(priority) if not sim.queue.can_queue_visible_interaction(): sims4.commands.output('Interaction queue is full, cannot add anymore interactions.', _connection) return False context = InteractionContext(sim, InteractionContext.SOURCE_PIE_MENU, priority, client=client, pick=None) result = sim.push_super_affordance(affordance, target, context) if not result: output = sims4.commands.Output(_connection) output('Failed to push: {}'.format(result)) return False return True
def add_sim_to_club(sim: RequiredTargetParam, club_name, _connection=None): target_sim_info = sim.get_target(manager=services.sim_info_manager()) if target_sim_info is None: sims4.commands.output('Not a valid SimID.', _connection) return club_service = _get_club_service(_connection) if club_service is None: return club_name_lc = club_name.lower() for club in club_service.clubs: if club_name_lc in str(club).lower(): club.add_member(target_sim_info) return sims4.commands.output( 'No existing club with a name including the string {}'.format( club_name_lc), _connection)
def _FixDotCycle(targetSimHandler: argument_helpers.RequiredTargetParam, _connection=None) -> None: try: if game_services.service_manager is None: return targetSimInfo = targetSimHandler.get_target( services.sim_info_manager()) if not isinstance(targetSimInfo, sim_info.SimInfo): raise ValueError( "Failed to get the target sim, %s is not a valid sim id." % targetSimHandler.target_id) targetDotInformation = Dot.GetDotInformation( targetSimInfo) # type: typing.Optional[Dot.DotInformation] if targetDotInformation is None: return targetSystem = Reproduction.GetSimSystem( targetSimInfo ) # type: typing.Optional[ReproductionShared.ReproductiveSystem] if targetSystem is None: return targetCycleTracker = targetSystem.GetTracker( FemalesShared.CycleTrackerIdentifier ) # type: typing.Optional[CycleTracker.CycleTracker] if targetCycleTracker is None: return if targetCycleTracker.CurrentCycle is not None: targetDotInformation.TimeSinceCycleStart = targetCycleTracker.CurrentCycle.Age else: if targetCycleTracker.TimeSinceLastCycle is not None: targetDotInformation.TimeSinceCycleStart = targetCycleTracker.TimeSinceLastCycle except Exception as e: Debug.Log("Failed to fix a sim's dot cycle.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__, exception=e) raise e
def mark_entry_as_seen(sim: RequiredTargetParam, subcategory_id: int, entry_id: int, _connection=None): sim_info = sim.get_target(manager=services.sim_info_manager()) if sim_info is None: sims4.commands.output( 'Sim with id {} is not found to mark notebook entry as seen.'. format(sim.target_id), _connection) return False if sim_info.notebook_tracker is None: sims4.commands.output( 'Notebook tracker is not found on Sim {} to mark notebook entry as seen' .format(sim_info), _connection) return False sim_info.notebook_tracker.mark_entry_as_seen(subcategory_id, entry_id) return True
def purchase_picker_response(inventory_target:RequiredTargetParam, mailman_purchase:bool=False, *def_ids_and_amounts:int, _connection=None): total_price = 0 current_purchased = 0 objects_to_buy = [] definition_manager = services.definition_manager() for (def_id, amount) in zip(def_ids_and_amounts[::2], def_ids_and_amounts[1::2]): definition = definition_manager.get(def_id) if definition is None: sims4.commands.output('inventory.purchase_picker_response: Definition not found with id {}'.format(def_id), _connection) return False purchase_price = definition.price*amount total_price += purchase_price objects_to_buy.append((definition, amount)) client = services.client_manager().get(_connection) if client is None: sims4.commands.output('inventory.purchase_picker_response: No client found to make purchase.', _connection) return False household = client.household if household.funds.money < total_price: sims4.commands.output('inventory.purchase_picker_response: Insufficient funds for household to purchase items.', _connection) return False if mailman_purchase: inventory = services.active_lot().get_hidden_inventory() else: inventory_owner = inventory_target.get_target() inventory = inventory_owner.inventory_component if inventory is None: sims4.commands.output('inventory.purchase_picker_response: Inventory not found for items to be purchased into.', _connection) return False for (definition, amount) in objects_to_buy: obj = create_object(definition) if obj is None: sims4.commands.output('inventory.purchase_picker_response: Failed to create object with definition {}.'.format(definition), _connection) else: obj.set_stack_count(amount) if not inventory.player_try_add_object(obj): sims4.commands.output('inventory.purchase_picker_response: Failed to add object into inventory: {}'.format(obj), _connection) obj.destroy(source=inventory, cause='inventory.purchase_picker_response: Failed to add object into inventory.') else: obj.set_household_owner_id(household.id) obj.try_post_bb_fixup(force_fixup=True, active_household_id=services.active_household_id()) purchase_price = definition.price*amount current_purchased += purchase_price return household.funds.try_remove(current_purchased, Consts_pb2.TELEMETRY_OBJECT_BUY)
def modify_mannequin_in_cas(obj_id:RequiredTargetParam=None, apply_outfit=False, _connection=None): mannequin = obj_id.get_target() if mannequin is None: sims4.commands.output('No valid target with the specified ID found.', _connection) return False mannequin_component = mannequin.mannequin_component if mannequin_component is None: sims4.commands.output('The specified target does not have a Mannequin component.', _connection) return False persistence_service = services.get_persistence_service() if persistence_service is not None: persistence_service.del_mannequin_proto_buff(mannequin.id) sim_info_data_proto = persistence_service.add_mannequin_proto_buff() mannequin_component.populate_sim_info_data_proto(sim_info_data_proto) current_zone_id = services.current_zone_id() sim_info_data_proto.zone_id = current_zone_id sim_info_data_proto.world_id = persistence_service.get_world_id_from_zone(current_zone_id) sims4.commands.client_cheat('sims.exit2caswithmannequinid {} {}'.format(mannequin.id, 'apply_outfit' if apply_outfit else ''), _connection) return True
def _ShowFertilityNotificationsEnabledNotification( targetSimHandler: argument_helpers.RequiredTargetParam, _connection: int = None) -> None: try: targetSimInfo = targetSimHandler.get_target( services.sim_info_manager()) UIDot.ShowFertilityNotificationsEnabledNotification(targetSimInfo) except: output = commands.CheatOutput(_connection) output( "Failed to show the dot app's fertility notifications enabled notification." ) Debug.Log( "Failed to show the dot app's fertility notifications enabled notification.", This.Mod.Namespace, Debug.LogLevels.Exception, group=This.Mod.Namespace, owner=__name__)