def update(self): if not super().update(): return False self.last_distance = utils.dist( h_utils.get_coords(h_utils.get_player_ped_id()), self.end_pos) pos = h_utils.get_coords(h_utils.get_player_ped_id()) x1, y1, z1 = pos.x, pos.y, pos.z x2, y2, z2 = self.end_pos.x, self.end_pos.y, self.end_pos.z self.last_distance_curve = h.Pathfind.calculate_travel_distance_between_points( x1, y1, z1, x2, y2, z1) return self.should_keep_running
def state(self): """ Dict of current scenario/player state. """ coord = h_utils.get_coords(h_utils.get_player_ped_id()) return dict(position=(coord.x, coord.y, coord.z), reward=0)
def __init__(self, ints=None, floats=None, **kwargs): super().__init__(**kwargs) if floats is None: floats = [0] * 7 floats[0] = h_utils.get_coords(h_utils.get_player_ped_id()).x floats[1] = h_utils.get_coords(h_utils.get_player_ped_id()).y floats[2] = h_utils.get_coords(h_utils.get_player_ped_id()).z floats[3] = 0.0 floats[4] = h_utils.random_point( h_utils.get_coords(h_utils.get_player_ped_id()).x, 1000) floats[5] = h_utils.random_point( h_utils.get_coords(h_utils.get_player_ped_id()).y, 1000) floats[6] = h_utils.random_point( h_utils.get_coords(h_utils.get_player_ped_id()).z, 1000) # Normal self.start_pos = h.Vector3(floats[0], floats[1], floats[2]) self.start_heading = floats[3] self.end_pos = h.Vector3(floats[4], floats[5], floats[6]) pos = h_utils.get_coords(h_utils.get_player_ped_id()) self.last_distance = utils.dist(pos, self.end_pos) self.last_distance_curve = h.Pathfind.calculate_travel_distance_between_points( pos.x, pos.y, pos.z, self.end_pos.x, self.end_pos.y, self.end_pos.z)
def clear(self): """ Keep player in vehicle after toggling autopilot. """ if self.scenario is not None and self.scenario.vehicle is not None: h_utils.set_ped_into_vehicle(h_utils.get_player_ped_id(), self.scenario.vehicle) super().clear()
def _drive(self, **kwargs): if self.scenario is None: return # Hack. if hasattr(self.scenario, 'end_pos'): h.Ai.task_vehicle_drive_to_coord( h_utils.get_player_ped_id(), self.scenario.vehicle, self.scenario.end_pos.x, self.scenario.end_pos.y, self.scenario.end_pos.z, self.scenario.max_speed, 1, self.scenario.vehicle_metadata.hash, self.scenario.driving_style, 1.0, 0.0) else: h.Ai.task_vehicle_drive_wander(h_utils.get_player_ped_id(), self.scenario.vehicle, self.scenario.max_speed, self.scenario.driving_style) self.drive_start = time.time()
def _inject_noise(self, **kwargs): self.status = constants.AgentStatus.NOISE self.angle = -abs(self.scenario.vehicle.control[0] * 5.0) self.throttle = self.scenario.vehicle.control[1] self.brake = self.scenario.vehicle.control[2] self.sign = int(self.angle < 0) h.Ai.clear_ped_tasks(h_utils.get_player_ped_id()) self.noise_start = time.time()
def _respawn(self): player_ped_id = h_utils.get_player_ped_id() if self.random_respawn: pos = h_utils.get_coord_near_road(self.x, self.y) heading = h_utils.get_road_heading(pos.x, pos.y) else: pos = h_utils.get_coords(player_ped_id) heading = player_ped_id.heading h_utils.set_ped_position(player_ped_id, pos) h_utils.set_ped_heading(player_ped_id, heading)
def setup(self, autopilot): coord = h_utils.get_coords(h_utils.get_player_ped_id()) h.Gameplay.clear_area(coord.x, coord.y, coord.z, 30.0, 0, 0, 0, 0) self._remove_all_vehicles() self._respawn() self._ready_vehicle() self.last_control = self.vehicle.control # Give autopilot information about vehicle, etc. autopilot.init(self)
def setup(self, autopilot): """ Teleport to and wander around a random road. """ pos = get_coord_near_road(self.x, self.y) heading = get_road_heading(pos.x, pos.y) player_ped_id = h_utils.get_player_ped_id() h_utils.set_ped_position(player_ped_id, pos) h_utils.set_ped_heading(player_ped_id, heading) h_utils.pause(50)
def _ready_vehicle(self): player_ped_id = h_utils.get_player_ped_id() pos = player_ped_id.get_coords(1) heading = player_ped_id.heading h_utils.set_ped_position(player_ped_id, pos) h_utils.set_ped_heading(player_ped_id, heading) h.wait(500) self.vehicle = h_utils.spawn_entity( self.vehicle_metadata.code, lambda: h_utils.spawn_vehicle(self.vehicle_metadata, pos, heading)) h.wait(500) player_ped_id.set_into_vehicle(self.vehicle, -1) if INVISIBLE: self.vehicle.set_alpha(0, 0) player_ped_id.set_alpha(0, 0)
def tick(self, data): """ Returns last action. """ if not self.has_valid_keys(data): return if self._pause_timer.is_time(): h_utils.pause(0) if self._log_timer.is_time(): logging.debug('Task: %s. Status: %s.' % (self.active_index, self._status)) player_ped_id = h_utils.get_player_ped_id() set_task = self._set_task_funcs[self.active_index] is_task_done = self._is_task_done_funcs[self.active_index] # Reset action vector. h_utils.Controls.reset() if self.only_set_once: if self._status == TaskStatus.SETTING_TASK: set_task(**data) self._status = TaskStatus.WAITING_FOR_TASK_TO_FINISH elif self._status == TaskStatus.WAITING_FOR_TASK_TO_FINISH: if is_task_done(**data): self.active_index = (self.active_index + 1) % len(self) self._status = TaskStatus.SETTING_TASK else: set_task(**data) if is_task_done(**data): self.active_index = (self.active_index + 1) % len(self) return h_utils.Controls.get_last_action()
def __init__(self): super.__init__([ lambda **kwargs: h_utils.make_ped_wander(h_utils.get_player_ped_id( )) ], [utils.always_returns_false], only_set_once=True)
def clear(self): self._status = TaskStatus.SETTING_TASK h.Ai.clear_ped_tasks_immediately(h_utils.get_player_ped_id())
def _respawn(self): player_ped_id = h_utils.get_player_ped_id() h_utils.set_ped_position(player_ped_id, self.start_pos) h_utils.set_ped_heading(player_ped_id, self.start_heading)
def get_info(self): """ Must override for TaskQueue to work properly. """ return dict(player_ped_id=h_utils.get_player_ped_id())