Closed hfib closed 3 years ago
Hi can you provide some code so I can see what you're doing, thanks.
import {
AmongusClient,
MasterServers
} from 'amongus-protocol'
const server = MasterServers.EU[0]
const name = 'AUBot'
const name2 = '2AUBot'
const code = process.argv[2]
const second = async() => {
const client = new AmongusClient
await client.connect(server[0], server[1], name2)
const game = await client.join(code)
await game.awaitSpawns()
game.me.setName(name2)
}
(async() => {
const client = new AmongusClient
await client.connect(server[0], server[1], name)
const game = await client.join(code)
await game.awaitSpawns()
game.me.setName(name)
game.on('playerJoin', async p => {
console.log(p.name())
})
second()
})()
p.name
is correct.playerJoin
event does not necessarily mean the player has spawned, so you must p.awaitSpawn()
.p.awaitSpawn()
won't be enough.Solution: I've pushed some changes so you'll have to update.
If you want to specifically listen for name updates, you'll have to use the event playerData
given off by the GameData
component in the GameData
object.
await game.awaitSpawns();
game.GameData.GameData.on("playerData", player => {
console.log(player.name);
});
I'll leave this open in case you have any more issues.
I'm gonna close this issue now, feel free to open another if you have any more issues.
What I tried to do - make room and get into it, get player name
PlayerClient.name()
on playerJoin. File: struct>PlayerClient Function: PlayerData Arguments: no arguments Log, when tried toPlayerClient.PlayerData()
:(node:1776) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'PlayerControl' of undefined at PlayerClient.get PlayerData [as PlayerData] (file:///path/to/amongus-protocol/js/lib/struct/PlayerClient.js:47:75) at Game.<anonymous> (file:///path/to/index.js:36:19) at Game.emit (events.js:315:20) at Game._playerJoin (file:///path/to/amongus-protocol/js/lib/struct/Game.js:172:14) at Game.<anonymous> (file:///path/to/amongus-protocol/js/lib/struct/Game.js:179:18) at Generator.next (<anonymous>) at file:///path/to/amongus-protocol/js/lib/struct/Game.js:7:71 at new Promise (<anonymous>) at __awaiter (file:///path/to/amongus-protocol/js/lib/struct/Game.js:3:12) at Game.playerJoin (file:///path/to/amongus-protocol/js/lib/struct/Game.js:175:16)