Skip to content

Commit

Permalink
🎉 feat: support player dropped (#6)
Browse files Browse the repository at this point in the history
* 🎉 feat: support player dropped

* 🔨 chore: support playerDropped event
  • Loading branch information
casperiv0 authored Dec 20, 2022
1 parent 8464009 commit 06f4004
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integration/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getIcon } from "~/utils/getIcon";

let firstSpawn = true;

onNet("playerSpawned", () => {
onNet(Events.CFXPlayerDropped, () => {
if (firstSpawn) {
emitPlayerData();
firstSpawn = false;
Expand Down
14 changes: 13 additions & 1 deletion integration/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const io = new Server(server, {

const playerData = new Map<string, any>();

onNet(Events.ResourceStarted, (name: string) => {
onNet(Events.CFXResourceStarted, (name: string) => {
const playerCount = GetNumPlayerIndices();

if (name !== GetCurrentResourceName()) return;
Expand All @@ -24,6 +24,18 @@ onNet(Events.ResourceStarted, (name: string) => {
});
});

onNet(Events.CFXPlayerDropped, () => {
// @ts-expect-error - this is supported according to the docs.
const playerName = GetPlayerName(source);

playerData.delete(playerName);

io.sockets.emit("map-data", {
type: LegacyMapEvents.RemovePlayer,
payload: playerName,
});
});

onNet(Events.PlayerSpawned, (data: any) => {
const identifiers = getPlayerIds(source);
data.identifiers = identifiers;
Expand Down
5 changes: 4 additions & 1 deletion src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export enum Events {
CFXResourceStarted = "onResourceStart",
CFXPlayerDropped = "playerDropped",
CFXPlayerSpawned = "playerSpawned",

PlayerSpawned = "sna-live-map-player-spawned",
ResourceStarted = "onResourceStart",
AddPlayerData = "sna-live-map-add-player-data",
UpdatePlayerData = "sna-live-map-update-player-data",
RemovePlayer = "sna-live-map-remove-player",
Expand Down

0 comments on commit 06f4004

Please sign in to comment.