コード例 #1
0
ファイル: wanted.py プロジェクト: yinglang/scripthookvpy3k
def main():
    """
    Increase the wanted level when `+` is pressed.
    Decrease the wanted level when `-` is pressed.
    Double increase or decrease when `Shift` is pressed as well.
    """
    logger = utils.get_logger('gta.wanted')

    while True:
        # Wait until '+' or '-' has been pressed
        code, _, modifiers = yield from key(codes={Key.ADD, Key.SUBTRACT})
        number = 2 if modifiers['shift'] else 1

        try:
            # Get player id and wanted level
            player_id = player.get_id()
            wanted_level = gta_native.player.get_player_wanted_level(player_id)
            logger.debug('Wanted level is {}', wanted_level)

            # Increase or decrease wanted level
            if code == Key.ADD and wanted_level < 5:
                wanted_level = min(wanted_level + number, 5)
                logger.debug('Increasing wanted level to {}', wanted_level)
            elif code == Key.SUBTRACT and wanted_level > 0:
                wanted_level = max(wanted_level - number, 0)
                logger.debug('Decreasing wanted level to {}', wanted_level)

            # Apply wanted level
            gta_native.player.set_player_wanted_level(player_id, wanted_level,
                                                      False)
            gta_native.player.set_player_wanted_level_now(player_id, False)
        except gta.RequirementError as exc:
            logger.debug(exc)
コード例 #2
0
ファイル: events.py プロジェクト: yinglang/scripthookvpy3k
def wait(require_func, *args, precision=10, **kwargs):
    """
    Wait for a requirement to be fulfilled.

    Arguments:
        - `require_func`: A function from the :mod:`requires` package.
        - `precision`: The amount of game ticks to wait between checks.
        - `args`: Arguments that will be passed to the function.
        - `kwargs`: Keyword arguments that will be passed to the
          function.

    Return the value `require_func` returns when the requirement is
    fulfilled.
    """
    logger = utils.get_logger('gta.wait')

    # Create partial
    partial = functools.partial(require_func, *args, **kwargs)

    # Poll until fulfilled
    while True:
        try:
            result = partial()
            logger.debug('{} fulfilled, result: {}', partial, result)
            return result
        except gta.RequirementError as exc:
            logger.debug('{} not fulfilled, missing: {}', partial, exc.requirement)
        yield from tick(count=precision)
コード例 #3
0
ファイル: wanted.py プロジェクト: czastack/scripthookvpy3k
def main():
    """
    Increase the wanted level when `+` is pressed.
    Decrease the wanted level when `-` is pressed.
    Double increase or decrease when `Shift` is pressed as well.
    """
    logger = utils.get_logger('gta.wanted')

    while True:
        # Wait until '+' or '-' has been pressed
        code, _, modifiers = yield from key(codes={Key.ADD, Key.SUBTRACT})
        number = 2 if modifiers['shift'] else 1

        try:
            # Get player id and wanted level
            player_id = player.get_id()
            wanted_level = gta_native.player.get_player_wanted_level(player_id)
            logger.debug('Wanted level is {}', wanted_level)

            # Increase or decrease wanted level
            if code == Key.ADD and wanted_level < 5:
                wanted_level = min(wanted_level + number, 5)
                logger.debug('Increasing wanted level to {}', wanted_level)
            elif code == Key.SUBTRACT and wanted_level > 0:
                wanted_level = max(wanted_level - number, 0)
                logger.debug('Decreasing wanted level to {}', wanted_level)

            # Apply wanted level
            gta_native.player.set_player_wanted_level(player_id, wanted_level, False)
            gta_native.player.set_player_wanted_level_now(player_id, False)
        except gta.RequirementError as exc:
            logger.debug(exc)
コード例 #4
0
def main():
    """
    Applies a different vehicle colour every second.
    """
    logger = utils.get_logger('gta.vehicle_color')

    while True:
        # Wait until the player is in a vehicle with a precision of 100 ticks
        vehicle = yield from wait(player.get_vehicle, precision=100)
        # Generate colour
        color = [random.randint(0, 255) for _ in range(3)]
        # Apply colour
        logger.debug('Changing vehicle color to: {}', color)
        gta_native.vehicle.set_vehicle_custom_primary_colour(vehicle, *color)
        # Because the coroutine usually returns immediately, we want to
        # wait a second, so the script isn't spamming colours every tick
        yield from asyncio.sleep(1.0)
コード例 #5
0
def main():
    """
    Creates a few primitive UI elements.
    """
    logger = utils.get_logger('gta.ui')
    counter = 0

    # Create primitive UI elements
    rectangle = primitive.Rectangle(size=Dimension.Quarter)
    ui.add(rectangle)

    while True:
        yield from key(codes=Key.F12)
        ui.draw()

        # Modify the created UI elements
        # TODO

        counter += 1
コード例 #6
0
ファイル: primitive.py プロジェクト: yinglang/scripthookvpy3k
    def draw(self, offset=Point.Zero, **settings):
        # TODO: Remove logging
        from gta import utils
        logger = utils.get_logger('gta.RECTANGLE')

        # Override default settings
        settings.update(self._settings)

        # Calculate position and dimension
        x, y = self.get_coordinates(offset)
        width, height = self.get_dimension()

        text_scale = 0.4

        line_width = 350.0
        line_height = 15.0
        line_top = 18.0
        line_left = 0.0
        text_left = 5.0

        line_width_scaled = line_width / 1280
        line_top_scaled = line_top / 720
        text_left_scaled = text_left / 1280
        line_height_scaled = line_height / 720

        line_left_scaled = line_left / 1280

        # Use native functions to draw
        logger.warning('x: {}, y: {}, width: {}, height: {}, color: {}', x, y,
                       width, height, self.color.rgba)
        logger.warning('gta_native.graphics.get_screen_resolution()')
        gta_native.graphics.get_screen_resolution()
        logger.info('Screen resolution: {}',
                    gta_native.graphics.get_screen_resolution())
        logger.warning('gta_native.ui.set_text_font(Font.chalet_london)')
        gta_native.ui.set_text_font(Font.chalet_london)
        logger.warning('gta_native.ui.set_text_scale(0.0, 0.35)')
        gta_native.ui.set_text_scale(0.0, text_scale)
        logger.warning('gta_native.ui.set_text_colour(*Color.White.rgba)')
        gta_native.ui.set_text_colour(*Color.White.rgba)
        logger.warning('gta_native.ui.set_text_centre(True)')
        gta_native.ui.set_text_centre(False)
        logger.warning('gta_native.ui.set_text_dropshadow(0, 0, 0, 0, 0)')
        gta_native.ui.set_text_dropshadow(0, 0, 0, 0, 0)
        logger.warning('gta_native.ui.set_text_edge(0, 0, 0, 0, 0)')
        gta_native.ui.set_text_edge(0, 0, 0, 0, 0)
        logger.warning('gta_native.ui._SET_TEXT_ENTRY(\'STRING\')')
        gta_native.ui._SET_TEXT_ENTRY('STRING')
        logger.warning('gta_native.ui._ADD_TEXT_COMPONENT_STRING(\'TEST\')')
        gta_native.ui._ADD_TEXT_COMPONENT_STRING('TEST')
        logger.warning('gta_native.ui._DRAW_TEXT(text_left_scaled, no_idea_1)')
        no_idea_1 = line_top_scaled + 0.00278 + line_height_scaled - 0.005
        logger.info('text_left_scaled={}, no_idea_1={}', text_left_scaled,
                    no_idea_1)
        gta_native.ui._DRAW_TEXT(text_left_scaled, no_idea_1)
        no_idea_2 = gta_native.ui._0xDB88A37483346780(text_scale, 0)
        logger.info(
            'line_left_scaled={}, line_top_scaled + 0.00278={}, line_width_scaled={}, no_idea_2 + line_height_scaled*2.0 + 0.005={}, *self.color.rgba={}',
            line_left_scaled, line_top_scaled + 0.00278, line_width_scaled,
            no_idea_2 + line_height_scaled * 2.0 + 0.005, *self.color.rgba)
        gta_native.graphics.draw_rect(
            line_left_scaled, line_top_scaled + 0.00278, line_width_scaled,
            no_idea_2 + line_height_scaled * 2.0 + 0.005, *self.color.rgba)