Skip to main content
added 810 characters in body
Source Link
lvictorino
  • 2.6k
  • 1
  • 15
  • 23

I don't what your code architecture looks like, but you will have to make this check at some point.

The simplest way to do this, imho, is to be sure that the local player only receive his own events, so, be sure to make him register to only his event.

You say that, at click, you know who has clicked. Why don't you just send the event to this specific player. If the, let's say, click_event object contains a player object, you just have to use it to only warn the specific player.

click_event.player.OnClickEvent(click_event);

EDIT

After your edit, it's now clearer.

You will have to check the sender in your callback method. Note that you often want to actually "display" other players actions. In RTS you sometimes want to show who is selecting what or who is clicking on what, even if you don't want to call the action code, only the UI code.

So if OnRightClickEvent has subscribed to RightClickEvent you would have something like :

void OnRightClickEvent(GameObject hit_obj, Player player)
{ 
   // SHOW ACTION UI
   // ... like mouse movement and click on the hit_obj ...
   // ... show hit_obj UI FX ...
   
   // HANDLE CLICK CODE ONLY FOR THE GOOD PLAYER
   if ( player == local_player )
   {
       // ... do what you want to do ...
   }
 }

I don't what your code architecture looks like, but you will have to make this check at some point.

The simplest way to do this, imho, is to be sure that the local player only receive his own events, so, be sure to make him register to only his event.

You say that, at click, you know who has clicked. Why don't you just send the event to this specific player. If the, let's say, click_event object contains a player object, you just have to use it to only warn the specific player.

click_event.player.OnClickEvent(click_event);

I don't what your code architecture looks like, but you will have to make this check at some point.

The simplest way to do this, imho, is to be sure that the local player only receive his own events, so, be sure to make him register to only his event.

You say that, at click, you know who has clicked. Why don't you just send the event to this specific player. If the, let's say, click_event object contains a player object, you just have to use it to only warn the specific player.

click_event.player.OnClickEvent(click_event);

EDIT

After your edit, it's now clearer.

You will have to check the sender in your callback method. Note that you often want to actually "display" other players actions. In RTS you sometimes want to show who is selecting what or who is clicking on what, even if you don't want to call the action code, only the UI code.

So if OnRightClickEvent has subscribed to RightClickEvent you would have something like :

void OnRightClickEvent(GameObject hit_obj, Player player)
{ 
   // SHOW ACTION UI
   // ... like mouse movement and click on the hit_obj ...
   // ... show hit_obj UI FX ...
   
   // HANDLE CLICK CODE ONLY FOR THE GOOD PLAYER
   if ( player == local_player )
   {
       // ... do what you want to do ...
   }
 }
Source Link
lvictorino
  • 2.6k
  • 1
  • 15
  • 23

I don't what your code architecture looks like, but you will have to make this check at some point.

The simplest way to do this, imho, is to be sure that the local player only receive his own events, so, be sure to make him register to only his event.

You say that, at click, you know who has clicked. Why don't you just send the event to this specific player. If the, let's say, click_event object contains a player object, you just have to use it to only warn the specific player.

click_event.player.OnClickEvent(click_event);