Giter VIP home page Giter VIP logo

Comments (4)

edqx avatar edqx commented on May 13, 2024

Hi can you provide some code so I can see what you're doing, thanks.

from amongus-protocol.

hfib avatar hfib commented on May 13, 2024
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()
})()

from amongus-protocol.

edqx avatar edqx commented on May 13, 2024
  • Firstly, name is a getter, so p.name is correct.
  • Secondly, this might be happening because the playerJoin event does not necessarily mean the player has spawned, so you must p.awaitSpawn().
  • Thirdly, the player sends their name after they have spawned, and the player's game data containing their colour and name is delayed until after they have spawned too, so even 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.

from amongus-protocol.

edqx avatar edqx commented on May 13, 2024

I'm gonna close this issue now, feel free to open another if you have any more issues.

from amongus-protocol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.