npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rbxts/player-hooks

v1.0.1-beta.0

Published

A port of RobloxianDemo's Player class.

Downloads

21

Readme

Player Hooks

Player (hooks) is a more complexed class designated to wrap around the general Player interface found on Roblox's API, feel free to add more features through PRs!

Installation

📦 — NPM:

npm i @rbxts/player-hooks

🧶 — Yarn:

yarn add @rbxts/player-hooks

📀 — pnPM:

pnpm add @rbxts/player-hooks

Player Hooks API

Types

interface Destroyable {
	Destroy(): void;
}

type Object =
	| never
	| undefined
	| ((this: defined) => void)
	| ((_: defined) => void)
	| ExtractKeys<defined, () => void>
	| thread
	| RBXScriptConnection
	| globalThis.Player
	| Player
	| PlayerHook.Destroyable;

Constructor

const player: PlayerHook = new Player(localPlayer);

player.RetrieveCharacter

public RetrieveCharacter(): Model;

Return the player's character.

player.RetrieveHumanoid

public RetrieveHumanoid(): Humanoid;

Return the player's character's humanoid.

player.WaitForCharacter

public WaitForCharacter(Callback?: Callback): Model | boolean;

Wait for and return the player's character (cancels by default if five attempts fail).

player.WaitForHumanoid

public WaitForHumanoid(Callback?: Callback): Humanoid | boolean;

Wait for and return the player's characters' humanoid (cancels by default if five attempts fail).

player.RetrieveName

RetrieveName(): string;

Return the player's name.

player.RetrievePlayer

public RetrievePlayer(): Player;

Return the player's Player object.

player.RetrieveUserId

public RetrieveUserId(): number ;

Return the player's unique UserId.

player.CharacterAdded

public CharacterAdded(Callback?: Callback): defined;

Run the specified callback function on the addition of the player's character.

player.HumanoidAdded

public HumanoidAdded(Callback?: Callback): defined;

Run the specified callback function on the addition of the player's humanoid.

player.SetJumpPower

public SetJumpPower(power: number): defined;

Set the player's jump-power.

player.UseJumpPower

public UseJumpPower(value: boolean): defined;

Set whether or not to use the player's jump-power for jump-related adjustments.

player.SetJumpHeight

public SetJumpHeight(height: number): defined;

Set the player's jump-height.

player.SetMaxSlopeAngle

public SetMaxSlopeAngle(angle: number): defined;

Set the player's maximum slope angle.

player.SetWalkSpeed

public SetWalkSpeed(speed: number): defined;

Kick the player.

player.Kick

public Kick(reason: string): boolean;

Set the player's walking speed.

player.Destroy

public Destroy(): void;

Destroy and cleanup a player-hook (making it and not the player unusable).

Example

// Services
import { Players } from "@rbxts/services";

// Modules
import { PlayerHook } from "./";

// Variables
const PLAYER_CACHE: Array<Player> = [];

// Functions
function onPlayerAdded(localPlayer: Player) {
	if (PLAYER_CACHE.indexOf(localPlayer) !== undefined) {
		return;
	}

	function characterCallback() {
		print(`The character has been added!`);
	}

	function humanoidCallback() {
		print(`The humanoid has been added!`);
	}

	const player: PlayerHook = new PlayerHook<typeof localPlayer>(localPlayer);

	player.CharacterAdded(characterCallback);
	player.HumanoidAdded(humanoidCallback);

	player.WaitForCharacter(function (...args: Array<Model | boolean>) {
		print(...args); // --> Model | Model.Name

		print(player.RetrieveCharacter().Name); // --> Model.Name
	});

	player.WaitForHumanoid(function (...args: Array<Humanoid | boolean>) {
		print(...args); // --> Humanoid | Humanoid.Name

		player.SetWalkSpeed(1e1); // --> 10
		print(player.RetrieveHumanoid().WalkSpeed); // --> 10

		player.SetWalkSpeed(1e2); // --> 100
		print(player.RetrieveHumanoid().WalkSpeed); // --> 100
	});
}

function onPlayerRemoving(localPlayer: Player) {
	if (PLAYER_CACHE.indexOf(localPlayer) === undefined) {
		return;
	} else {
		const player = PLAYER_CACHE.indexOf(localPlayer) as unknown as PlayerHook;

		PLAYER_CACHE.indexOf(localPlayer) === undefined;

		player.Destroy();
	}
}

Players.PlayerAdded.Connect(onPlayerAdded);
Players.PlayerRemoving.Connect(onPlayerRemoving);