mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
tweak(player): Altered PLAYER_IS_READY event to emit a bool
This will set the client var to true when NPWD loads a player and false when NPWD unloads a player.
This commit is contained in:
1 parent
268bd4f4a4
commit
949ea4ba4b
3 files changed
+21
-11
No files matched your search
@@ -9,7 +9,6 @@ import { NotesEvents } from '../../typings/notes';
|
||||
import { BankEvents } from '../../typings/bank';
|
||||
import { PhotoEvents } from '../../typings/photo';
|
||||
import { CallEvents } from '../../typings/call';
|
||||
import { MatchEvents } from '../../typings/match';
|
||||
import { config } from './client';
|
||||
|
||||
let isPhoneOpen = false;
|
||||
@@ -109,12 +108,9 @@ async function Phone(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// triggerd when the player is ready
|
||||
onNet(PhoneEvents.PLAYER_IS_READY, () => {
|
||||
isPlayerReady = true;
|
||||
if (isUiReady) {
|
||||
fetchOnInitialize();
|
||||
}
|
||||
// Set the global depending on the response from event
|
||||
onNet(PhoneEvents.PLAYER_IS_READY, (ready: boolean) => {
|
||||
isPlayerReady = ready;
|
||||
});
|
||||
|
||||
AddEventHandler('onResourceStop', function (resource: string) {
|
||||
|
||||
@@ -28,7 +28,7 @@ if (!config.general.enableMultiChar) {
|
||||
on('playerDropped', () => {
|
||||
const source = getSource();
|
||||
// Get identifier for player to remove
|
||||
handleUnloadPlayerEvent(source);
|
||||
handleUnloadPlayerEvent(source, true);
|
||||
});
|
||||
|
||||
// Can use this to debug the player table if needed. Disabled by default
|
||||
|
||||
@@ -53,7 +53,7 @@ export async function handleNewPlayerJoined(pSource: number) {
|
||||
playerLogger.debug(newPlayer);
|
||||
|
||||
// Emit to client that player is ready
|
||||
emitNet(PhoneEvents.PLAYER_IS_READY, pSource);
|
||||
emitNet(PhoneEvents.PLAYER_IS_READY, pSource, true);
|
||||
} catch (e) {
|
||||
playerLogger.error(`Failed to create a new player, ${e.message}`, {
|
||||
source: pSource,
|
||||
@@ -93,6 +93,9 @@ export async function handleNewPlayerEvent({
|
||||
|
||||
playerLogger.info(`New NPWD Player added through event (${source}) (${identifier})`);
|
||||
playerLogger.debug(player);
|
||||
|
||||
// Emit to client that player is ready
|
||||
emitNet(PhoneEvents.PLAYER_IS_READY, source, true);
|
||||
} catch (e) {
|
||||
playerLogger.error(`Failed to create a new player through event, ${e.message}`, {
|
||||
source,
|
||||
@@ -100,9 +103,16 @@ export async function handleNewPlayerEvent({
|
||||
}
|
||||
}
|
||||
|
||||
export function handleUnloadPlayerEvent(source: number) {
|
||||
/**
|
||||
* Unloads an NPWD player and emits to the client that the phone is not yet ready
|
||||
* if the player wasn't dropped
|
||||
*
|
||||
* @param source - The source of the player to unload
|
||||
* @param playerDropped - Whether the player was dropped
|
||||
*/
|
||||
export function handleUnloadPlayerEvent(source: number, playerDropped?: boolean) {
|
||||
if (typeof source !== 'number') {
|
||||
return playerLogger.error('Source must be passed as a number to npwd:handleUnloadPlayer');
|
||||
return playerLogger.error('Source must be passed as a number when unloading a player');
|
||||
}
|
||||
const identifier = getPlayer(source).getIdentifier();
|
||||
|
||||
@@ -111,6 +121,10 @@ export function handleUnloadPlayerEvent(source: number) {
|
||||
PlayersByIdentifier.delete(identifier);
|
||||
|
||||
playerLogger.info(`Unloaded NPWD Player, source: (${source})`);
|
||||
|
||||
if (!playerDropped) {
|
||||
emitNet(PhoneEvents.PLAYER_IS_READY, source, false);
|
||||
}
|
||||
}
|
||||
|
||||
const clean = (input: string) => (input ? input.replace(/[^0-9a-z]/gi, '') : input);
|
||||
|
||||
Reference in new issue
Block a user