Raised This Month: $51 Target: $400
 12% 

[ANY/HL2:DM] Flashlight brighter and color


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
painkiller
Senior Member
Join Date: Jun 2011
Old 04-19-2022 , 12:17   [ANY/HL2:DM] Flashlight brighter and color
Reply With Quote #1

Could someone write a plugin for the radius of the flashlight and the color of the flashlight beam?
+ Random color option

I found a SP script maybe it helps to write it in sm.
It is about the game HL2: DM

Greets Painkiller

Code:
# ../flashlight/flashlight.py

# Python
from colorsys import hsv_to_rgb

# Source.Python
from colors import Color
from commands import CommandReturn
from commands.client import ClientCommand
from entities.entity import Entity
from entities.helpers import index_from_pointer
from entities.hooks import EntityCondition, EntityPreHook
from listeners import OnNetworkedEntityDeleted
from mathlib import NULL_VECTOR, NULL_QANGLE
from players.entity import Player


# Color of the flashlight.
FLASHLIGHT_COLOR = Color(255, 255, 255)
# Radius of the flashlight.
FLASHLIGHT_RADIUS = 53
# Brightness of the flashlight.
FLASHLIGHT_BRIGHTNESS = 10

# Block the weapon inspect animation?
BLOCK_ANIMATION = True
# Should the color of the flashlight be based on the player's steamid?
COLOR_FROM_STEAMID = True


# List of vibrant colors.
pretty_colors = []

# Edict flag used for making sure an entity gets transmitted to all clients
# no matter what.
FL_EDICT_ALWAYS = 1<<3

is_projected_texture = EntityCondition.equals_entity_classname(
    'env_projectedtexture')


def load():
    """Called when the plugin gets loaded."""
    # Generate 10 vibrant colors, one for each digit from 0 to 9.
    pretty_colors.extend(get_pretty_colors(amount=10))


def unload():
    """Called when the plugin gets unloaded."""
    for player in PlayerF.cache.values():
        try:
            # Try to remove the player's flashlight.
            player.torch.remove()
        except AttributeError:
            continue


@ClientCommand('+lookatweapon')
def inspect_weapon(command, index):
    """Called when a player inspects their weapon."""
    PlayerF(index).toggle_torch()

    if BLOCK_ANIMATION:
        return CommandReturn.BLOCK


@EntityPreHook(is_projected_texture, 'set_transmit')
def set_transmit_pre(stack_data):
    index = index_from_pointer(stack_data[0])

    try:
        # Does this index belong to a Torch instance?
        torch = Torch.cache[index]
    except KeyError:
        return None

    torch.state_flags |= FL_EDICT_ALWAYS


@OnNetworkedEntityDeleted
def on_networked_entity_deleted(entity):
    """Called when a networked entity gets deleted."""
    if 'env_projectedtexture' in entity.classname:
        try:
            player = PlayerF.from_inthandle(entity.owner_handle)
        except (ValueError, OverflowError):
            # ValueError: Not a player.
            # OverflowError: Invalid 'owner_handle' (-1).
            return

        player.torch = None
        player.torch_enabled = False


class PlayerF(Player):
    """Extended Player class.

    Args:
        index (int): A valid player index.
        caching (bool): Check for a cached instance?

    Attributes:
        torch (Entity): Entity instance of the 'env_projectedtexture'.
        torch_enabled (bool): Is the torch/flashlight turned on?
    """

    def __init__(self, index, caching=True):
        """Initializes the object."""
        super().__init__(index, caching)

        self.torch = None
        self.torch_enabled = False

    def toggle_torch(self):
        """Toggles the player's flashlight."""
        # Flip the flashlight status.
        self.torch_enabled = not self.torch_enabled
        torch = self.torch

        # Is the player missing a flashlight?
        if torch is None:
            # Should the player's steamid determine the flashlight color?
            if COLOR_FROM_STEAMID:
                color = pretty_colors[int(self.steamid[-1])]

            # Or not?
            else:
                color = FLASHLIGHT_COLOR

            torch = Torch.create(
                color=color,
                owner_handle=self.inthandle
            )
            # Usually, when parenting an entity to the player's viewmodel, the
            # entity would only be transmitted to that player. However, if the
            # entity that we're parenting has the 'FL_EDICT_ALWAYS' flag, it
            # should be transmitted to all connected players.
            torch.set_parent(Entity.from_inthandle(
                self.get_datamap_property_int('m_hViewModel')), -1)

            torch.teleport(NULL_VECTOR, NULL_QANGLE)
            # Store the instance.
            self.torch = torch

        torch.call_input('TurnOn' if self.torch_enabled else 'TurnOff')
        self.emit_sound(
            sample='items/flashlight1.wav',
            attenuation=0.8,
            volume=0.3
        )


class Torch(Entity):
    """Extended Entity class used for creating a flashlight."""
    caching = True

    @classmethod
    def create(cls, color, owner_handle):
        """Creates a colored flashlight.

        Args:
            color (Color): Color of the flashlight.
            owner_handle (int): Inthandle of the owner.
        """
        texture = super().create('env_projectedtexture')
        texture.owner_handle = owner_handle
        texture.light_color = color
        # Radius of the flashlight.
        texture.light_fov = FLASHLIGHT_RADIUS
        # Should objects/geometry cast shadows when lit by the flashlight?
        texture.enable_shadows = False
        # Should the flashlight affect static world geometry?
        texture.light_world = True
        # Speed at which the color changes.
        texture.color_transition_time = 100
        # Brightness of the flashlight.
        texture.brightness_scale = FLASHLIGHT_BRIGHTNESS
        # Set a spawn flag:
        # 2: Always Update (moving light)
        texture.spawn_flags = 2
        texture.spawn()
        return texture

    def remove(self):
        """Turns the flashlight off before removing it."""
        self.call_input('TurnOff')
        self.delay(0, super().remove)


def get_pretty_colors(amount):
    """Returns a list of vibrant colors.

    Args:
        amount (int): How many colors should be generated?

    Returns:
        list of Color: A list containing Color instances.
    """
    colors = []
    step = 1 / amount

    for hue in range(0, amount):
        colors.append(
            Color(*(int(255 * x) for x in hsv_to_rgb(step * hue, 1, 1))))

    return colors

Last edited by painkiller; 04-19-2022 at 12:18.
painkiller is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-19-2022 , 13:21   Re: [ANY/HL2:DM] Flashlight brighter and color
Reply With Quote #2

Quote:
Originally Posted by painkiller View Post
...
It is about the game HL2: DM
...
Your game, is modified HL2:DM
Remember mention that.
Quote:
Originally Posted by painkiller View Post
We need to try to apply the plugin to my metamod and sourcemod version. It is really necessary to make your plugin work because I control everything with these sm and mm versions please try to downgrade your stuff or try this.

https://steamcommunity.com/app/320/d...3785578614100/

My old sky works with all old standert npc if i take newer versions no more fast_zombies or anything else will run by itself.

That's why I'm with you, you've been a fox for years and know what to do.

Edit: my sdk is older so i have to stay on this level so that the npc can run. Unfortunately, Valve no longer does this.

They just deleted npc and no longer run please give yourself a jerk.

this is official and can also help many other people.

You are good at what you do and this is not about the official DM but about everyone trying to keep coop running in hl2dm. With this version everyone can also play Gmod maps or L4D1,2 in hl2dm.

It's about the life of hl2dm servers in coop because that's the only thing that keeps hl2 alive with people.

Sorry for my english and for pointing it out so urgently.
This is no longer about the mod CSS or CSGO. because that has been bought by Valve since 1.5 and those people who play Css and CsGO have more advantages.

Greeting Painkiller
__________________
Do not Private Message @me

Last edited by Bacardi; 04-19-2022 at 13:22.
Bacardi is offline
painkiller
Senior Member
Join Date: Jun 2011
Old 04-20-2022 , 04:50   Re: [ANY/HL2:DM] Flashlight brighter and color
Reply With Quote #3

Yes, as I said, this is nonsense. I was mistaken.
The game is not customized. I have slightly overdone I have only an older sm and mm version. As I mentioned in your post.

And it's bullshit to badmouth me in other posts now.
Just because we both could not communicate properly.

Last edited by painkiller; 04-20-2022 at 04:50.
painkiller is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode