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:
Taso committed 2021-04-18 15:38:50 -04:00
1 parent 268bd4f4a4
commit 949ea4ba4b
3 files changed
+21 -11

No files matched your search

@@ -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
+17 -3
View File
@@ -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);