Created
January 9, 2025 00:10
-
-
Save gsmj/5498928f69886ebca801cd14dd6cddbd to your computer and use it in GitHub Desktop.
Prox detector in Python (by ziggi)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pysamp.player import Player as BasePlayer | |
class Player(BasePlayer): | |
registry: dict[int, BasePlayer] = {} | |
def __init__(self, player_id: int): | |
super().__init__(player_id) | |
@classmethod | |
def from_registry_native(cls, player: BasePlayer | int) -> "Player": | |
if isinstance(player, int): | |
player_id = player | |
if isinstance(player, BasePlayer): | |
player_id = player.id | |
player = cls.registry.get(player_id) | |
if not player: | |
cls.registry[player_id] = player = cls(player_id) | |
return player | |
@classmethod | |
def using_registry(cls, func) -> Callable: | |
@functools.wraps(func) | |
def from_registry(*args, **kwargs): | |
args = list(args) | |
args[0] = cls.from_registry_native(args[0]) | |
return func(*args, **kwargs) | |
return from_registry | |
def prox_detector( | |
self, | |
color: int, | |
string: str, | |
max_range: float = 20.0, | |
max_ratio: float = 1.6, | |
) -> None: | |
x, y, z = self.get_pos() | |
color_r = float(color >> 24 & 0xFF) | |
color_g = float(color >> 16 & 0xFF) | |
color_b = float(color >> 8 & 0xFF) | |
range_with_ratio = max_range * max_ratio | |
for player in Player.registry.values(): | |
if not player.is_streamed_in(self): | |
continue | |
range = player.distance_from_point(x, y, z) | |
if range > max_range: | |
continue | |
range_ratio = (range_with_ratio - range) / range_with_ratio | |
clr_r = round(range_ratio * color_r) | |
clr_g = round(range_ratio * color_g) | |
clr_b = round(range_ratio * color_b) | |
player.send_client_message( | |
(color & 0xFF) | (clr_b << 8) | (clr_g << 16) | (clr_r << 24), | |
string | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment