How to target specific objects

101
June 09, 2019, at 02:00 AM

Currently, I have a game setup where if one player clicks on another in range, it is supposed to kill said player. However, I'm not sure how to target specific players on collision. The game is written in p5 as well as node.js to network it.

I have tried to assign a specific id to each client however, when a ton of clients send data at once, the receiving client does not know which id to target.

SERVER CODE...

function newConnection(socket){
  storeid = socket.id;
  idarr.push(storeid);
  io.to(storeid).emit('clientid',storeid);
  usernumber+=1;
  console.log('new connection: ' + storeid);
  console.log(idarr);
  socket.on('mouse', mouseMsg);

  socket.on('killdata', killMsg);

  function mouseMsg(data) {
    socket.broadcast.emit('mouse', data);
  }
  function killMsg(otherid) {
    io.to(otherid).emit('iskilled', killed);
  }

CLIENT CODE TO KILL OBJECT

    if(collided){
        death = true;
        socket.emit('killdata', otherid);
        collided = false;
      }
//otherid is the id of other clients taken from the server when the server sends data from other clients

Right now, the code written kills a player, but it kills a random player because the client can only receive an id one at a time and does not know which id to target.

Rent Charter Buses Company
READ ALSO
Discard chunk in NodeJS Transform stream and read the next one

Discard chunk in NodeJS Transform stream and read the next one

How do I discard a chunk in a NodeJS transform stream and read the next one from the previous stream?

165
Facebook Messenger Bot Message is not coming to server

Facebook Messenger Bot Message is not coming to server

I have setup the Facebook Messenger by following correct stepsI could verify the webhook successfully as well as subscribed to the page

132
FacebookTokenError: This authorization code has been used passport-js

FacebookTokenError: This authorization code has been used passport-js

I have implemented log in with facebook using passportjs

111
Is there a way to refresh static files without server restart?

Is there a way to refresh static files without server restart?

My simple Nodejs app serves static files, e

88